From a6d5556dc1de96343c0d7f36da80285fcffce575 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 19 Feb 2021 11:31:25 +0300 Subject: [PATCH] [#378] shard/gc: Reuse addressFromKey func in all appropriate places Signed-off-by: Leonard Lyubich --- pkg/local_object_storage/metabase/iterators.go | 4 +--- pkg/local_object_storage/metabase/movable.go | 4 +--- pkg/local_object_storage/metabase/select.go | 8 +++----- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/pkg/local_object_storage/metabase/iterators.go b/pkg/local_object_storage/metabase/iterators.go index b8085048f..bd8fa5b3f 100644 --- a/pkg/local_object_storage/metabase/iterators.go +++ b/pkg/local_object_storage/metabase/iterators.go @@ -131,9 +131,7 @@ func (db *DB) iterateCoveredByTombstones(tx *bbolt.Tx, tss map[string]struct{}, err := bktGraveyard.ForEach(func(k, v []byte) error { if _, ok := tss[string(v)]; ok { - addr := object.NewAddress() - - err := addr.Parse(string(k)) + addr, err := addressFromKey(k) if err != nil { return errors.Wrap(err, "could not parse address of the object under tombstone") } diff --git a/pkg/local_object_storage/metabase/movable.go b/pkg/local_object_storage/metabase/movable.go index e6064780b..d81f74e3a 100644 --- a/pkg/local_object_storage/metabase/movable.go +++ b/pkg/local_object_storage/metabase/movable.go @@ -131,9 +131,7 @@ func (db *DB) Movable(prm *MovablePrm) (*MovableRes, error) { addrs := make([]*objectSDK.Address, 0, len(strAddrs)) for i := range strAddrs { - addr := objectSDK.NewAddress() - - err = addr.Parse(strAddrs[i]) + addr, err := addressFromKey([]byte(strAddrs[i])) if err != nil { return nil, fmt.Errorf("can't parse object address %v: %w", strAddrs[i], err) diff --git a/pkg/local_object_storage/metabase/select.go b/pkg/local_object_storage/metabase/select.go index 21d13eba2..88636da42 100644 --- a/pkg/local_object_storage/metabase/select.go +++ b/pkg/local_object_storage/metabase/select.go @@ -128,8 +128,8 @@ func (db *DB) selectObjects(tx *bbolt.Tx, cid *container.ID, fs object.SearchFil continue // ignore objects with unmatched fast filters } - addr := object.NewAddress() - if err := addr.Parse(a); err != nil { + addr, err := addressFromKey([]byte(a)) + if err != nil { // TODO: storage was broken, so we need to handle it return nil, err } @@ -435,9 +435,7 @@ func (db *DB) selectObjectID( appendOID := func(oid string) { addrStr := prefix + string(oid) - addr := object.NewAddress() - - err := addr.Parse(addrStr) + addr, err := addressFromKey([]byte(addrStr)) if err != nil { db.log.Debug("can't decode object id address", zap.String("addr", addrStr),