leveldb3: add instant dropping bucket

This commit is contained in:
chrislu 2022-07-21 18:48:51 -07:00
parent c93f7ffa44
commit fc8241fb5e
2 changed files with 35 additions and 4 deletions

View File

@ -121,23 +121,31 @@ func (store *LevelDB3Store) findDB(fullpath weed_util.FullPath, isForChildren bo
}
store.dbsLock.RUnlock()
// upgrade to write lock
db, err := store.createDB(bucket)
return db, bucket, shortPath, err
}
func (store *LevelDB3Store) createDB(bucket string) (*leveldb.DB, error) {
store.dbsLock.Lock()
defer store.dbsLock.Unlock()
// double check after getting the write lock
if db, found := store.dbs[bucket]; found {
return db, bucket, shortPath, nil
return db, nil
}
// create db
db, err := store.loadDB(bucket)
if err != nil {
return nil, bucket, shortPath, err
return nil, err
}
store.dbs[bucket] = db
return db, bucket, shortPath, nil
return db, nil
}
func (store *LevelDB3Store) closeDB(bucket string) {

View File

@ -0,0 +1,23 @@
package leveldb
import (
"github.com/chrislusf/seaweedfs/weed/filer"
"os"
)
var _ filer.BucketAware = (*LevelDB3Store)(nil)
func (store *LevelDB3Store) OnBucketCreation(bucket string) {
store.createDB(bucket)
}
func (store *LevelDB3Store) OnBucketDeletion(bucket string) {
store.closeDB(bucket)
if bucket != "" { // just to make sure
os.RemoveAll(store.dir + "/" + bucket)
}
}
func (store *LevelDB3Store) CanDropWholeBucket() bool {
return true
}