mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
leveldb3: add instant dropping bucket
This commit is contained in:
parent
c93f7ffa44
commit
fc8241fb5e
|
@ -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
Normal file
23
weed/filer/leveldb3/leveldb3_store_bucket.go
Normal 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
|
||||
}
|
Loading…
Reference in a new issue