From 92e19feb577242aea36639e554b3cf71fc7085d1 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 30 May 2024 09:26:06 +0300 Subject: [PATCH] [#1147] node: Use public fields for `shard.ExistsPrm` Signed-off-by: Anton Nikiforov --- pkg/local_object_storage/engine/delete.go | 2 +- .../engine/engine_test.go | 5 +++- pkg/local_object_storage/engine/exists.go | 10 ++++---- pkg/local_object_storage/engine/inhume.go | 2 +- pkg/local_object_storage/engine/lock.go | 2 +- pkg/local_object_storage/engine/put.go | 7 ++++-- .../engine/remove_copies.go | 2 +- pkg/local_object_storage/shard/exists.go | 24 +++++++------------ pkg/local_object_storage/shard/reload_test.go | 2 +- 9 files changed, 26 insertions(+), 30 deletions(-) diff --git a/pkg/local_object_storage/engine/delete.go b/pkg/local_object_storage/engine/delete.go index 44a61221..09652896 100644 --- a/pkg/local_object_storage/engine/delete.go +++ b/pkg/local_object_storage/engine/delete.go @@ -83,7 +83,7 @@ func (e *StorageEngine) delete(ctx context.Context, prm DeletePrm) (DeleteRes, e // 2. Otherwise, search for all objects with a particular SplitID and delete them too. e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) { var existsPrm shard.ExistsPrm - existsPrm.SetAddress(prm.addr) + existsPrm.Address = prm.addr resExists, err := sh.Exists(ctx, existsPrm) if err != nil { diff --git a/pkg/local_object_storage/engine/engine_test.go b/pkg/local_object_storage/engine/engine_test.go index 70c54590..49976abb 100644 --- a/pkg/local_object_storage/engine/engine_test.go +++ b/pkg/local_object_storage/engine/engine_test.go @@ -63,7 +63,10 @@ func benchmarkExists(b *testing.B, shardNum int) { b.ReportAllocs() b.ResetTimer() for i := 0; i < b.N; i++ { - ok, _, err := e.exists(context.Background(), addr, oid.Address{}) + var shPrm shard.ExistsPrm + shPrm.Address = addr + shPrm.ParentAddress = oid.Address{} + ok, _, err := e.exists(context.Background(), shPrm) if err != nil || ok { b.Fatalf("%t %v", ok, err) } diff --git a/pkg/local_object_storage/engine/exists.go b/pkg/local_object_storage/engine/exists.go index ce669ec5..c57f7969 100644 --- a/pkg/local_object_storage/engine/exists.go +++ b/pkg/local_object_storage/engine/exists.go @@ -8,18 +8,16 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" - oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" ) -func (e *StorageEngine) exists(ctx context.Context, addr oid.Address, parentAddr oid.Address) (bool, bool, error) { - var shPrm shard.ExistsPrm - shPrm.SetAddress(addr) - shPrm.SetParentAddress(parentAddr) +// exists return in the first value true if object exists. +// Second return value marks is parent object locked. +func (e *StorageEngine) exists(ctx context.Context, shPrm shard.ExistsPrm) (bool, bool, error) { alreadyRemoved := false exists := false locked := false - e.iterateOverSortedShards(addr, func(_ int, sh hashedShard) (stop bool) { + e.iterateOverSortedShards(shPrm.Address, func(_ int, sh hashedShard) (stop bool) { res, err := sh.Exists(ctx, shPrm) if err != nil { if client.IsErrObjectAlreadyRemoved(err) { diff --git a/pkg/local_object_storage/engine/inhume.go b/pkg/local_object_storage/engine/inhume.go index 62e7be93..991305af 100644 --- a/pkg/local_object_storage/engine/inhume.go +++ b/pkg/local_object_storage/engine/inhume.go @@ -142,7 +142,7 @@ func (e *StorageEngine) inhumeAddr(ctx context.Context, addr oid.Address, prm sh }() if checkExists { - existPrm.SetAddress(addr) + existPrm.Address = addr exRes, err := sh.Exists(ctx, existPrm) if err != nil { if client.IsErrObjectAlreadyRemoved(err) || shard.IsErrObjectExpired(err) { diff --git a/pkg/local_object_storage/engine/lock.go b/pkg/local_object_storage/engine/lock.go index af56c3e1..5354c205 100644 --- a/pkg/local_object_storage/engine/lock.go +++ b/pkg/local_object_storage/engine/lock.go @@ -78,7 +78,7 @@ func (e *StorageEngine) lockSingle(ctx context.Context, idCnr cid.ID, locker, lo if checkExists { var existsPrm shard.ExistsPrm - existsPrm.SetAddress(addrLocked) + existsPrm.Address = addrLocked exRes, err := sh.Exists(ctx, existsPrm) if err != nil { diff --git a/pkg/local_object_storage/engine/put.go b/pkg/local_object_storage/engine/put.go index aa94ef22..2a78febe 100644 --- a/pkg/local_object_storage/engine/put.go +++ b/pkg/local_object_storage/engine/put.go @@ -85,7 +85,10 @@ func (e *StorageEngine) put(ctx context.Context, prm PutPrm) error { parent.SetObject(prm.obj.ECHeader().Parent()) parent.SetContainer(addr.Container()) } - existed, locked, err := e.exists(ctx, addr, parent) + var shPrm shard.ExistsPrm + shPrm.Address = addr + shPrm.ParentAddress = parent + existed, locked, err := e.exists(ctx, shPrm) if err != nil { return err } @@ -138,7 +141,7 @@ func (e *StorageEngine) putToShard(ctx context.Context, sh hashedShard, pool uti defer close(exitCh) var existPrm shard.ExistsPrm - existPrm.SetAddress(addr) + existPrm.Address = addr exists, err := sh.Exists(ctx, existPrm) if err != nil { diff --git a/pkg/local_object_storage/engine/remove_copies.go b/pkg/local_object_storage/engine/remove_copies.go index 00562e4c..b99cf4f4 100644 --- a/pkg/local_object_storage/engine/remove_copies.go +++ b/pkg/local_object_storage/engine/remove_copies.go @@ -115,7 +115,7 @@ func (e *StorageEngine) removeObjects(ctx context.Context, ch <-chan oid.Address found := false for i := range shards { var existsPrm shard.ExistsPrm - existsPrm.SetAddress(addr) + existsPrm.Address = addr res, err := shards[i].Exists(ctx, existsPrm) if err != nil { diff --git a/pkg/local_object_storage/shard/exists.go b/pkg/local_object_storage/shard/exists.go index 12c339c0..b5a9604b 100644 --- a/pkg/local_object_storage/shard/exists.go +++ b/pkg/local_object_storage/shard/exists.go @@ -13,8 +13,10 @@ import ( // ExistsPrm groups the parameters of Exists operation. type ExistsPrm struct { - addr oid.Address - paddr oid.Address + // Exists option to set object checked for existence. + Address oid.Address + // Exists option to set parent object checked for existence. + ParentAddress oid.Address } // ExistsRes groups the resulting values of Exists operation. @@ -23,16 +25,6 @@ type ExistsRes struct { lc bool } -// SetAddress is an Exists option to set object checked for existence. -func (p *ExistsPrm) SetAddress(addr oid.Address) { - p.addr = addr -} - -// SetParentAddress is an Exists option to set parent object checked for existence. -func (p *ExistsPrm) SetParentAddress(addr oid.Address) { - p.paddr = addr -} - // Exists returns the fact that the object is in the shard. func (p ExistsRes) Exists() bool { return p.ex @@ -55,7 +47,7 @@ func (s *Shard) Exists(ctx context.Context, prm ExistsPrm) (ExistsRes, error) { ctx, span := tracing.StartSpanFromContext(ctx, "Shard.Exists", trace.WithAttributes( attribute.String("shard_id", s.ID().String()), - attribute.String("address", prm.addr.EncodeToString()), + attribute.String("address", prm.Address.EncodeToString()), )) defer span.End() @@ -70,15 +62,15 @@ func (s *Shard) Exists(ctx context.Context, prm ExistsPrm) (ExistsRes, error) { return ExistsRes{}, ErrShardDisabled } else if s.info.Mode.NoMetabase() { var p common.ExistsPrm - p.Address = prm.addr + p.Address = prm.Address var res common.ExistsRes res, err = s.blobStor.Exists(ctx, p) exists = res.Exists } else { var existsPrm meta.ExistsPrm - existsPrm.SetAddress(prm.addr) - existsPrm.SetParent(prm.paddr) + existsPrm.SetAddress(prm.Address) + existsPrm.SetParent(prm.ParentAddress) var res meta.ExistsRes res, err = s.metaBase.Exists(ctx, existsPrm) diff --git a/pkg/local_object_storage/shard/reload_test.go b/pkg/local_object_storage/shard/reload_test.go index b5ea2fec..7dacbfa6 100644 --- a/pkg/local_object_storage/shard/reload_test.go +++ b/pkg/local_object_storage/shard/reload_test.go @@ -72,7 +72,7 @@ func TestShardReload(t *testing.T) { checkHasObjects := func(t *testing.T, exists bool) { for i := range objects { var prm ExistsPrm - prm.SetAddress(objects[i].addr) + prm.Address = objects[i].addr res, err := sh.Exists(context.Background(), prm) require.NoError(t, err)