diff --git a/weed/filer2/memdb/memdb_store.go b/weed/filer2/memdb/memdb_store.go index 855a13faa..9c10a5472 100644 --- a/weed/filer2/memdb/memdb_store.go +++ b/weed/filer2/memdb/memdb_store.go @@ -7,6 +7,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/util" "github.com/google/btree" "strings" + "sync" ) func init() { @@ -14,7 +15,8 @@ func init() { } type MemDbStore struct { - tree *btree.BTree + tree *btree.BTree + treeLock sync.Mutex } type entryItem struct { @@ -46,7 +48,9 @@ func (store *MemDbStore) RollbackTransaction(ctx context.Context) error { func (store *MemDbStore) InsertEntry(ctx context.Context, entry *filer2.Entry) (err error) { // println("inserting", entry.FullPath) + store.treeLock.Lock() store.tree.ReplaceOrInsert(entryItem{entry}) + store.treeLock.Unlock() return nil } @@ -54,7 +58,9 @@ func (store *MemDbStore) UpdateEntry(ctx context.Context, entry *filer2.Entry) ( if _, err = store.FindEntry(ctx, entry.FullPath); err != nil { return fmt.Errorf("no such file %s : %v", entry.FullPath, err) } + store.treeLock.Lock() store.tree.ReplaceOrInsert(entryItem{entry}) + store.treeLock.Unlock() return nil } @@ -68,7 +74,9 @@ func (store *MemDbStore) FindEntry(ctx context.Context, fullpath filer2.FullPath } func (store *MemDbStore) DeleteEntry(ctx context.Context, fullpath filer2.FullPath) (err error) { + store.treeLock.Lock() store.tree.Delete(entryItem{&filer2.Entry{FullPath: fullpath}}) + store.treeLock.Unlock() return nil }