diff --git a/weed/filer/leveldb3/leveldb3_store.go b/weed/filer/leveldb3/leveldb3_store.go index d21515bd4..8da4a9e7f 100644 --- a/weed/filer/leveldb3/leveldb3_store.go +++ b/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) { diff --git a/weed/filer/leveldb3/leveldb3_store_bucket.go b/weed/filer/leveldb3/leveldb3_store_bucket.go new file mode 100644 index 000000000..823fe363b --- /dev/null +++ b/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 +}