From c1530dec5e10afe4c89b22babd0f9c0be4d914d3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 7 Feb 2022 18:08:00 +0300 Subject: [PATCH] [#1115] shard/gc: provide parsed addresses in `HandleExpiredTombstones` Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/engine/inhume.go | 4 ++-- pkg/local_object_storage/metabase/iterators.go | 4 ++-- .../metabase/iterators_test.go | 4 ++-- pkg/local_object_storage/shard/gc.go | 18 ++---------------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/pkg/local_object_storage/engine/inhume.go b/pkg/local_object_storage/engine/inhume.go index f86d2ff8a7..143aa1ca6f 100644 --- a/pkg/local_object_storage/engine/inhume.go +++ b/pkg/local_object_storage/engine/inhume.go @@ -135,10 +135,10 @@ func (e *StorageEngine) inhumeAddr(addr *addressSDK.Address, prm *shard.InhumePr } func (e *StorageEngine) processExpiredTombstones(ctx context.Context, addrs []*addressSDK.Address) { - tss := make(map[string]struct{}, len(addrs)) + tss := make(map[string]*addressSDK.Address, len(addrs)) for i := range addrs { - tss[addrs[i].String()] = struct{}{} + tss[addrs[i].String()] = addrs[i] } e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) { diff --git a/pkg/local_object_storage/metabase/iterators.go b/pkg/local_object_storage/metabase/iterators.go index 65fb4493bc..3d463e49c2 100644 --- a/pkg/local_object_storage/metabase/iterators.go +++ b/pkg/local_object_storage/metabase/iterators.go @@ -120,13 +120,13 @@ func objectType(tx *bbolt.Tx, cid *cid.ID, oidBytes []byte) object.Type { // Returns other errors of h directly. // // Does not modify tss. -func (db *DB) IterateCoveredByTombstones(tss map[string]struct{}, h func(*addressSDK.Address) error) error { +func (db *DB) IterateCoveredByTombstones(tss map[string]*addressSDK.Address, h func(*addressSDK.Address) error) error { return db.boltDB.View(func(tx *bbolt.Tx) error { return db.iterateCoveredByTombstones(tx, tss, h) }) } -func (db *DB) iterateCoveredByTombstones(tx *bbolt.Tx, tss map[string]struct{}, h func(*addressSDK.Address) error) error { +func (db *DB) iterateCoveredByTombstones(tx *bbolt.Tx, tss map[string]*addressSDK.Address, h func(*addressSDK.Address) error) error { bktGraveyard := tx.Bucket(graveyardBucketName) if bktGraveyard == nil { return nil diff --git a/pkg/local_object_storage/metabase/iterators_test.go b/pkg/local_object_storage/metabase/iterators_test.go index b3300759a4..deb218ceee 100644 --- a/pkg/local_object_storage/metabase/iterators_test.go +++ b/pkg/local_object_storage/metabase/iterators_test.go @@ -82,8 +82,8 @@ func TestDB_IterateCoveredByTombstones(t *testing.T) { var handled []*addressSDK.Address - tss := map[string]struct{}{ - ts.String(): {}, + tss := map[string]*addressSDK.Address{ + ts.String(): ts, } err = db.IterateCoveredByTombstones(tss, func(addr *addressSDK.Address) error { diff --git a/pkg/local_object_storage/shard/gc.go b/pkg/local_object_storage/shard/gc.go index 90b2d82b62..32586aa643 100644 --- a/pkg/local_object_storage/shard/gc.go +++ b/pkg/local_object_storage/shard/gc.go @@ -276,7 +276,7 @@ func (s *Shard) getExpiredObjects(ctx context.Context, epoch uint64, collectTomb // If successful, marks tombstones themselves as garbage. // // Does not modify tss. -func (s *Shard) HandleExpiredTombstones(tss map[string]struct{}) { +func (s *Shard) HandleExpiredTombstones(tss map[string]*addressSDK.Address) { inhume := make([]*addressSDK.Address, 0, len(tss)) // Collect all objects covered by the tombstones. @@ -317,21 +317,7 @@ func (s *Shard) HandleExpiredTombstones(tss map[string]struct{}) { inhume = inhume[:0] - for strAddr := range tss { - // parse address - // TODO: make type of map values *object.Address since keys are calculated from addresses - addr := addressSDK.NewAddress() - - err = addr.Parse(strAddr) - if err != nil { - s.log.Error("could not parse tombstone address", - zap.String("text", strAddr), - zap.String("error", err.Error()), - ) - - continue // try process other tombstones - } - + for _, addr := range tss { inhume = append(inhume, addr) }