forked from TrueCloudLab/frostfs-node
[#1944] metabase: Recreate static buckets instead of resetting
From the `Bucket.ForEach` doc: ``` The provided function must not modify the bucket; this will result in undefined behavior. ``` Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
3c6daa2995
commit
e4bc3d0e9d
2 changed files with 9 additions and 18 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue