Skip to content

Commit

Permalink
[#1944] metabase: Assume static buckets are created on Init
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
  • Loading branch information
fyrchik committed Oct 26, 2022
1 parent 3a4abc4 commit ec9b58c
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 3 additions & 11 deletions pkg/local_object_storage/metabase/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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)

Expand Down
1 change: 1 addition & 0 deletions pkg/local_object_storage/metabase/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions pkg/local_object_storage/metabase/graveyard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions pkg/local_object_storage/metabase/iterators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions pkg/local_object_storage/metabase/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 1 addition & 13 deletions pkg/local_object_storage/metabase/movable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand All @@ -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)
})

Expand All @@ -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))

Expand Down

0 comments on commit ec9b58c

Please sign in to comment.