diff --git a/pkg/local_object_storage/metabase/control.go b/pkg/local_object_storage/metabase/control.go index 750ecfdd51..adcd809437 100644 --- a/pkg/local_object_storage/metabase/control.go +++ b/pkg/local_object_storage/metabase/control.go @@ -106,15 +106,17 @@ func (db *DB) init(reset bool) error { } } for k := range mStaticBuckets { - b, err := tx.CreateBucketIfNotExists([]byte(k)) - if err != nil { - return fmt.Errorf("could not create static bucket %s: %w", k, err) + name := []byte(k) + if reset { + err := tx.DeleteBucket(name) + if err != nil && !errors.Is(err, bbolt.ErrBucketNotFound) { + return fmt.Errorf("could not delete static bucket %s: %w", k, err) + } } - if reset { - if err = resetBucket(b); err != nil { - return fmt.Errorf("could not reset static bucket %s: %w", k, err) - } + _, err := tx.CreateBucketIfNotExists(name) + if err != nil { + return fmt.Errorf("could not create static bucket %s: %w", k, err) } } diff --git a/pkg/local_object_storage/metabase/util.go b/pkg/local_object_storage/metabase/util.go index 132870d10e..7102dd1831 100644 --- a/pkg/local_object_storage/metabase/util.go +++ b/pkg/local_object_storage/metabase/util.go @@ -223,17 +223,6 @@ func objectKey(obj oid.ID, key []byte) []byte { return key[:objectKeySize] } -// removes all bucket elements. -func resetBucket(b *bbolt.Bucket) error { - return b.ForEach(func(k, v []byte) error { - if v != nil { - return b.Delete(k) - } - - return b.DeleteBucket(k) - }) -} - // if meets irregular object container in objs - returns its type, otherwise returns object.TypeRegular. // // firstIrregularObjectType(tx, cnr, obj) usage allows getting object type.