Browse Source

leveldb3: add instant dropping bucket

pull/3348/head
chrislu 2 years ago
parent
commit
fc8241fb5e
  1. 16
      weed/filer/leveldb3/leveldb3_store.go
  2. 23
      weed/filer/leveldb3/leveldb3_store_bucket.go

16
weed/filer/leveldb3/leveldb3_store.go

@ -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) {

23
weed/filer/leveldb3/leveldb3_store_bucket.go

@ -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
}
Loading…
Cancel
Save