From 7395ab8ef79e17a88916a97b288b2cbb8faab131 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 26 Oct 2022 09:10:18 +0300 Subject: [PATCH] [#1944] metabase: Assume static buckets are created on `Init` Signed-off-by: Evgenii Stratonikov --- CHANGELOG.md | 1 + pkg/local_object_storage/metabase/containers.go | 14 +++----------- pkg/local_object_storage/metabase/control.go | 1 + pkg/local_object_storage/metabase/graveyard.go | 4 ---- pkg/local_object_storage/metabase/iterators.go | 3 --- pkg/local_object_storage/metabase/lock.go | 5 +---- pkg/local_object_storage/metabase/movable.go | 14 +------------- 7 files changed, 7 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 153a85fd56..6a7144c8f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Changelog for NeoFS Node - Inability to provide session to NeoFS CLI in a NeoFS-binary format (#1933) - `neofs-adm` now works correctly with a committee of more than 4 nodes (#1949, #1959) - Closing a shard now waits until GC background workers stop (#1964) +- Make it possible to use `shard.ContainerSize` in read-only mode (#1975) ### Removed ### Updated diff --git a/pkg/local_object_storage/metabase/containers.go b/pkg/local_object_storage/metabase/containers.go index fb1b487900..de3966d663 100644 --- a/pkg/local_object_storage/metabase/containers.go +++ b/pkg/local_object_storage/metabase/containers.go @@ -38,7 +38,7 @@ func (db *DB) containers(tx *bbolt.Tx) ([]cid.ID, error) { } func (db *DB) ContainerSize(id cid.ID) (size uint64, err error) { - err = db.boltDB.Update(func(tx *bbolt.Tx) error { + err = db.boltDB.View(func(tx *bbolt.Tx) error { size, err = db.containerSize(tx, id) return err @@ -48,11 +48,7 @@ func (db *DB) ContainerSize(id cid.ID) (size uint64, err error) { } func (db *DB) containerSize(tx *bbolt.Tx, id cid.ID) (uint64, error) { - containerVolume, err := tx.CreateBucketIfNotExists(containerVolumeBucketName) - if err != nil { - return 0, err - } - + containerVolume := tx.Bucket(containerVolumeBucketName) key := make([]byte, cidSize) id.Encode(key) @@ -78,11 +74,7 @@ func parseContainerSize(v []byte) uint64 { } func changeContainerSize(tx *bbolt.Tx, id cid.ID, delta uint64, increase bool) error { - containerVolume, err := tx.CreateBucketIfNotExists(containerVolumeBucketName) - if err != nil { - return err - } - + containerVolume := tx.Bucket(containerVolumeBucketName) key := make([]byte, cidSize) id.Encode(key) diff --git a/pkg/local_object_storage/metabase/control.go b/pkg/local_object_storage/metabase/control.go index adcd809437..93d62df6bb 100644 --- a/pkg/local_object_storage/metabase/control.go +++ b/pkg/local_object_storage/metabase/control.go @@ -94,6 +94,7 @@ func (db *DB) init(reset bool) error { string(toMoveItBucketName): {}, string(garbageBucketName): {}, string(shardInfoBucket): {}, + string(bucketNameLocked): {}, } return db.boltDB.Update(func(tx *bbolt.Tx) error { diff --git a/pkg/local_object_storage/metabase/graveyard.go b/pkg/local_object_storage/metabase/graveyard.go index dcf7d1e831..cba91d7dcc 100644 --- a/pkg/local_object_storage/metabase/graveyard.go +++ b/pkg/local_object_storage/metabase/graveyard.go @@ -164,10 +164,6 @@ func (db *DB) iterateDeletedObj(tx *bbolt.Tx, h kvHandler, offset *oid.Address) panic(fmt.Sprintf("metabase: unknown iteration object hadler: %T", t)) } - if bkt == nil { - return nil - } - c := bkt.Cursor() var k, v []byte diff --git a/pkg/local_object_storage/metabase/iterators.go b/pkg/local_object_storage/metabase/iterators.go index cc9b032b16..fcbba3fbb9 100644 --- a/pkg/local_object_storage/metabase/iterators.go +++ b/pkg/local_object_storage/metabase/iterators.go @@ -125,9 +125,6 @@ func (db *DB) IterateCoveredByTombstones(tss map[string]oid.Address, h func(oid. func (db *DB) iterateCoveredByTombstones(tx *bbolt.Tx, tss map[string]oid.Address, h func(oid.Address) error) error { bktGraveyard := tx.Bucket(graveyardBucketName) - if bktGraveyard == nil { - return nil - } err := bktGraveyard.ForEach(func(k, v []byte) error { var addr oid.Address diff --git a/pkg/local_object_storage/metabase/lock.go b/pkg/local_object_storage/metabase/lock.go index c9e0ff5db7..580c5d28d3 100644 --- a/pkg/local_object_storage/metabase/lock.go +++ b/pkg/local_object_storage/metabase/lock.go @@ -44,10 +44,7 @@ func (db *DB) Lock(cnr cid.ID, locker oid.ID, locked []oid.ID) error { return apistatus.LockNonRegularObject{} } - bucketLocked, err := tx.CreateBucketIfNotExists(bucketNameLocked) - if err != nil { - return fmt.Errorf("create global bucket for locked objects: %w", err) - } + bucketLocked := tx.Bucket(bucketNameLocked) cnr.Encode(key) bucketLockedContainer, err := bucketLocked.CreateBucketIfNotExists(key) diff --git a/pkg/local_object_storage/metabase/movable.go b/pkg/local_object_storage/metabase/movable.go index 8011490d25..4ae0b052b8 100644 --- a/pkg/local_object_storage/metabase/movable.go +++ b/pkg/local_object_storage/metabase/movable.go @@ -56,11 +56,7 @@ func (db *DB) ToMoveIt(prm ToMoveItPrm) (res ToMoveItRes, err error) { key = addressKey(prm.addr, key) err = db.boltDB.Update(func(tx *bbolt.Tx) error { - toMoveIt, err := tx.CreateBucketIfNotExists(toMoveItBucketName) - if err != nil { - return err - } - + toMoveIt := tx.Bucket(toMoveItBucketName) return toMoveIt.Put(key, zeroValue) }) @@ -77,10 +73,6 @@ func (db *DB) DoNotMove(prm DoNotMovePrm) (res DoNotMoveRes, err error) { err = db.boltDB.Update(func(tx *bbolt.Tx) error { toMoveIt := tx.Bucket(toMoveItBucketName) - if toMoveIt == nil { - return nil - } - return toMoveIt.Delete(key) }) @@ -96,10 +88,6 @@ func (db *DB) Movable(_ MovablePrm) (MovableRes, error) { err := db.boltDB.View(func(tx *bbolt.Tx) error { toMoveIt := tx.Bucket(toMoveItBucketName) - if toMoveIt == nil { - return nil - } - return toMoveIt.ForEach(func(k, v []byte) error { strAddrs = append(strAddrs, string(k))