From d8ba954affb7ed3eefd7a1d4d409ebae3346e2bb Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 13 Jul 2022 15:43:04 +0300 Subject: [PATCH] [#1559] shard: Use `Set` prefix for parameter setting Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/engine/container.go | 2 +- pkg/local_object_storage/engine/delete.go | 2 +- pkg/local_object_storage/engine/error_test.go | 6 +++--- pkg/local_object_storage/engine/exists.go | 2 +- pkg/local_object_storage/engine/get.go | 4 ++-- pkg/local_object_storage/engine/head.go | 4 ++-- pkg/local_object_storage/engine/head_test.go | 4 ++-- pkg/local_object_storage/engine/inhume.go | 4 ++-- .../engine/inhume_test.go | 4 ++-- pkg/local_object_storage/engine/lock.go | 2 +- pkg/local_object_storage/engine/put.go | 6 +++--- pkg/local_object_storage/engine/range.go | 6 +++--- pkg/local_object_storage/engine/select.go | 4 ++-- pkg/local_object_storage/shard/container.go | 6 ++---- .../shard/control_test.go | 16 +++++++-------- pkg/local_object_storage/shard/delete.go | 8 +++----- pkg/local_object_storage/shard/delete_test.go | 12 +++++------ pkg/local_object_storage/shard/dump_test.go | 8 ++++---- pkg/local_object_storage/shard/exists.go | 10 +++------- pkg/local_object_storage/shard/gc.go | 2 +- pkg/local_object_storage/shard/get.go | 12 +++++------ pkg/local_object_storage/shard/get_test.go | 14 ++++++------- pkg/local_object_storage/shard/head.go | 16 ++++++--------- pkg/local_object_storage/shard/head_test.go | 14 ++++++------- pkg/local_object_storage/shard/inhume.go | 12 +++++------ pkg/local_object_storage/shard/inhume_test.go | 6 +++--- pkg/local_object_storage/shard/list_test.go | 2 +- pkg/local_object_storage/shard/lock_test.go | 10 +++++----- pkg/local_object_storage/shard/move.go | 8 +++----- pkg/local_object_storage/shard/put.go | 8 +++----- pkg/local_object_storage/shard/range.go | 20 ++++++++----------- pkg/local_object_storage/shard/restore.go | 2 +- pkg/local_object_storage/shard/select.go | 16 ++++++--------- .../shard/shutdown_test.go | 4 ++-- 34 files changed, 114 insertions(+), 142 deletions(-) diff --git a/pkg/local_object_storage/engine/container.go b/pkg/local_object_storage/engine/container.go index 65a6d4f9..1a8dbf16 100644 --- a/pkg/local_object_storage/engine/container.go +++ b/pkg/local_object_storage/engine/container.go @@ -72,7 +72,7 @@ func (e *StorageEngine) containerSize(prm ContainerSizePrm) (res ContainerSizeRe e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) { var csPrm shard.ContainerSizePrm - csPrm.WithContainerID(prm.cnr) + csPrm.SetContainerID(prm.cnr) csRes, err := sh.Shard.ContainerSize(csPrm) if err != nil { diff --git a/pkg/local_object_storage/engine/delete.go b/pkg/local_object_storage/engine/delete.go index a8e0c27a..45fec21d 100644 --- a/pkg/local_object_storage/engine/delete.go +++ b/pkg/local_object_storage/engine/delete.go @@ -68,7 +68,7 @@ func (e *StorageEngine) delete(prm DeletePrm) (DeleteRes, error) { for i := range prm.addr { e.iterateOverSortedShards(prm.addr[i], func(_ int, sh hashedShard) (stop bool) { var existsPrm shard.ExistsPrm - existsPrm.WithAddress(prm.addr[i]) + existsPrm.SetAddress(prm.addr[i]) resExists, err := sh.Exists(existsPrm) if err != nil { diff --git a/pkg/local_object_storage/engine/error_test.go b/pkg/local_object_storage/engine/error_test.go index f95b486d..7117223f 100644 --- a/pkg/local_object_storage/engine/error_test.go +++ b/pkg/local_object_storage/engine/error_test.go @@ -70,7 +70,7 @@ func TestErrorReporting(t *testing.T) { obj.SetPayload(make([]byte, errSmallSize)) var prm shard.PutPrm - prm.WithObject(obj) + prm.SetObject(obj) e.mtx.RLock() _, err := e.shards[id[0].String()].Shard.Put(prm) e.mtx.RUnlock() @@ -100,7 +100,7 @@ func TestErrorReporting(t *testing.T) { obj.SetPayload(make([]byte, errSmallSize)) var prm shard.PutPrm - prm.WithObject(obj) + prm.SetObject(obj) e.mtx.RLock() _, err := e.shards[id[0].String()].Put(prm) e.mtx.RUnlock() @@ -150,7 +150,7 @@ func TestBlobstorFailback(t *testing.T) { obj.SetPayload(make([]byte, size)) var prm shard.PutPrm - prm.WithObject(obj) + prm.SetObject(obj) e.mtx.RLock() _, err = e.shards[id[0].String()].Shard.Put(prm) e.mtx.RUnlock() diff --git a/pkg/local_object_storage/engine/exists.go b/pkg/local_object_storage/engine/exists.go index 3127bf68..4822752d 100644 --- a/pkg/local_object_storage/engine/exists.go +++ b/pkg/local_object_storage/engine/exists.go @@ -8,7 +8,7 @@ import ( func (e *StorageEngine) exists(addr oid.Address) (bool, error) { var shPrm shard.ExistsPrm - shPrm.WithAddress(addr) + shPrm.SetAddress(addr) alreadyRemoved := false exists := false diff --git a/pkg/local_object_storage/engine/get.go b/pkg/local_object_storage/engine/get.go index 9bf42a3f..400eb59d 100644 --- a/pkg/local_object_storage/engine/get.go +++ b/pkg/local_object_storage/engine/get.go @@ -72,7 +72,7 @@ func (e *StorageEngine) get(prm GetPrm) (GetRes, error) { ) var shPrm shard.GetPrm - shPrm.WithAddress(prm.addr) + shPrm.SetAddress(prm.addr) e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) { res, err := sh.Get(shPrm) @@ -129,7 +129,7 @@ func (e *StorageEngine) get(prm GetPrm) (GetRes, error) { // If the object is not found but is present in metabase, // try to fetch it from blobstor directly. If it is found in any // blobstor, increase the error counter for the shard which contains the meta. - shPrm.WithIgnoreMeta(true) + shPrm.SetIgnoreMeta(true) e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) { res, err := sh.Get(shPrm) diff --git a/pkg/local_object_storage/engine/head.go b/pkg/local_object_storage/engine/head.go index d17acc1d..381b5c3b 100644 --- a/pkg/local_object_storage/engine/head.go +++ b/pkg/local_object_storage/engine/head.go @@ -80,8 +80,8 @@ func (e *StorageEngine) head(prm HeadPrm) (HeadRes, error) { ) var shPrm shard.HeadPrm - shPrm.WithAddress(prm.addr) - shPrm.WithRaw(prm.raw) + shPrm.SetAddress(prm.addr) + shPrm.SetRaw(prm.raw) e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) { res, err := sh.Head(shPrm) diff --git a/pkg/local_object_storage/engine/head_test.go b/pkg/local_object_storage/engine/head_test.go index e4714bdc..6f046d8f 100644 --- a/pkg/local_object_storage/engine/head_test.go +++ b/pkg/local_object_storage/engine/head_test.go @@ -47,10 +47,10 @@ func TestHeadRaw(t *testing.T) { defer e.Close() var putPrmLeft shard.PutPrm - putPrmLeft.WithObject(child) + putPrmLeft.SetObject(child) var putPrmLink shard.PutPrm - putPrmLink.WithObject(link) + putPrmLink.SetObject(link) // put most left object in one shard _, err := s1.Put(putPrmLeft) diff --git a/pkg/local_object_storage/engine/inhume.go b/pkg/local_object_storage/engine/inhume.go index f50e96ed..c0c3cd44 100644 --- a/pkg/local_object_storage/engine/inhume.go +++ b/pkg/local_object_storage/engine/inhume.go @@ -86,7 +86,7 @@ func (e *StorageEngine) inhume(prm InhumePrm) (InhumeRes, error) { for i := range prm.addrs { if prm.tombstone != nil { - shPrm.WithTarget(*prm.tombstone, prm.addrs[i]) + shPrm.SetTarget(*prm.tombstone, prm.addrs[i]) } else { shPrm.MarkAsGarbage(prm.addrs[i]) } @@ -129,7 +129,7 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, prm shard.InhumePrm, checkE }() if checkExists { - existPrm.WithAddress(addr) + existPrm.SetAddress(addr) exRes, err := sh.Exists(existPrm) if err != nil { if shard.IsErrRemoved(err) { diff --git a/pkg/local_object_storage/engine/inhume_test.go b/pkg/local_object_storage/engine/inhume_test.go index 419319a3..10f92f7a 100644 --- a/pkg/local_object_storage/engine/inhume_test.go +++ b/pkg/local_object_storage/engine/inhume_test.go @@ -62,12 +62,12 @@ func TestStorageEngine_Inhume(t *testing.T) { defer e.Close() var putChild shard.PutPrm - putChild.WithObject(child) + putChild.SetObject(child) _, err := s1.Put(putChild) require.NoError(t, err) var putLink shard.PutPrm - putLink.WithObject(link) + putLink.SetObject(link) _, err = s2.Put(putLink) require.NoError(t, err) diff --git a/pkg/local_object_storage/engine/lock.go b/pkg/local_object_storage/engine/lock.go index 6fd2eadd..52023b99 100644 --- a/pkg/local_object_storage/engine/lock.go +++ b/pkg/local_object_storage/engine/lock.go @@ -66,7 +66,7 @@ func (e *StorageEngine) lockSingle(idCnr cid.ID, locker, locked oid.ID, checkExi if checkExists { var existsPrm shard.ExistsPrm - existsPrm.WithAddress(addrLocked) + existsPrm.SetAddress(addrLocked) exRes, err := sh.Exists(existsPrm) if err != nil { diff --git a/pkg/local_object_storage/engine/put.go b/pkg/local_object_storage/engine/put.go index 16d05ee3..078223aa 100644 --- a/pkg/local_object_storage/engine/put.go +++ b/pkg/local_object_storage/engine/put.go @@ -60,7 +60,7 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) { } var existPrm shard.ExistsPrm - existPrm.WithAddress(addr) + existPrm.SetAddress(addr) finished := false @@ -82,7 +82,7 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) { if exists.Exists() { if ind != 0 { var toMoveItPrm shard.ToMoveItPrm - toMoveItPrm.WithAddress(addr) + toMoveItPrm.SetAddress(addr) _, err = sh.ToMoveIt(toMoveItPrm) if err != nil { @@ -99,7 +99,7 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) { } var putPrm shard.PutPrm - putPrm.WithObject(prm.obj) + putPrm.SetObject(prm.obj) _, err = sh.Put(putPrm) if err != nil { diff --git a/pkg/local_object_storage/engine/range.go b/pkg/local_object_storage/engine/range.go index 2b5415fc..7b3c9d09 100644 --- a/pkg/local_object_storage/engine/range.go +++ b/pkg/local_object_storage/engine/range.go @@ -87,8 +87,8 @@ func (e *StorageEngine) getRange(prm RngPrm) (RngRes, error) { ) var shPrm shard.RngPrm - shPrm.WithAddress(prm.addr) - shPrm.WithRange(prm.off, prm.ln) + shPrm.SetAddress(prm.addr) + shPrm.SetRange(prm.off, prm.ln) e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) { res, err := sh.GetRange(shPrm) @@ -147,7 +147,7 @@ func (e *StorageEngine) getRange(prm RngPrm) (RngRes, error) { // If the object is not found but is present in metabase, // try to fetch it from blobstor directly. If it is found in any // blobstor, increase the error counter for the shard which contains the meta. - shPrm.WithIgnoreMeta(true) + shPrm.SetIgnoreMeta(true) e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) { res, err := sh.GetRange(shPrm) diff --git a/pkg/local_object_storage/engine/select.go b/pkg/local_object_storage/engine/select.go index 8142e300..063a5c4b 100644 --- a/pkg/local_object_storage/engine/select.go +++ b/pkg/local_object_storage/engine/select.go @@ -62,8 +62,8 @@ func (e *StorageEngine) _select(prm SelectPrm) (SelectRes, error) { var outError error var shPrm shard.SelectPrm - shPrm.WithContainerID(prm.cnr) - shPrm.WithFilters(prm.filters) + shPrm.SetContainerID(prm.cnr) + shPrm.SetFilters(prm.filters) e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) { res, err := sh.Select(shPrm) diff --git a/pkg/local_object_storage/shard/container.go b/pkg/local_object_storage/shard/container.go index 5204bf50..dad55ddc 100644 --- a/pkg/local_object_storage/shard/container.go +++ b/pkg/local_object_storage/shard/container.go @@ -14,10 +14,8 @@ type ContainerSizeRes struct { size uint64 } -func (p *ContainerSizePrm) WithContainerID(cnr cid.ID) { - if p != nil { - p.cnr = cnr - } +func (p *ContainerSizePrm) SetContainerID(cnr cid.ID) { + p.cnr = cnr } func (r ContainerSizeRes) Size() uint64 { diff --git a/pkg/local_object_storage/shard/control_test.go b/pkg/local_object_storage/shard/control_test.go index 939e1316..22d11bf4 100644 --- a/pkg/local_object_storage/shard/control_test.go +++ b/pkg/local_object_storage/shard/control_test.go @@ -42,7 +42,7 @@ func TestRefillMetabaseCorrupted(t *testing.T) { obj.SetPayload([]byte{0, 1, 2, 3, 4, 5}) var putPrm PutPrm - putPrm.WithObject(obj) + putPrm.SetObject(obj) _, err := sh.Put(putPrm) require.NoError(t, err) require.NoError(t, sh.Close()) @@ -64,7 +64,7 @@ func TestRefillMetabaseCorrupted(t *testing.T) { require.NoError(t, sh.Init()) var getPrm GetPrm - getPrm.WithAddress(addr) + getPrm.SetAddress(addr) _, err = sh.Get(getPrm) require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) require.NoError(t, sh.Close()) @@ -150,13 +150,13 @@ func TestRefillMetabase(t *testing.T) { var putPrm PutPrm for _, v := range mObjs { - putPrm.WithObject(v.obj) + putPrm.SetObject(v.obj) _, err := sh.Put(putPrm) require.NoError(t, err) } - putPrm.WithObject(tombObj) + putPrm.SetObject(tombObj) _, err = sh.Put(putPrm) require.NoError(t, err) @@ -169,7 +169,7 @@ func TestRefillMetabase(t *testing.T) { lockObj.SetContainerID(cnrLocked) objectSDK.WriteLock(lockObj, lock) - putPrm.WithObject(lockObj) + putPrm.SetObject(lockObj) _, err = sh.Put(putPrm) require.NoError(t, err) @@ -177,7 +177,7 @@ func TestRefillMetabase(t *testing.T) { require.NoError(t, sh.Lock(cnrLocked, lockID, locked)) var inhumePrm InhumePrm - inhumePrm.WithTarget(object.AddressOf(tombObj), tombMembers...) + inhumePrm.SetTarget(object.AddressOf(tombObj), tombMembers...) _, err = sh.Inhume(inhumePrm) require.NoError(t, err) @@ -185,7 +185,7 @@ func TestRefillMetabase(t *testing.T) { var headPrm HeadPrm checkObj := func(addr oid.Address, expObj *objectSDK.Object) { - headPrm.WithAddress(addr) + headPrm.SetAddress(addr) res, err := sh.Head(headPrm) @@ -210,7 +210,7 @@ func TestRefillMetabase(t *testing.T) { checkTombMembers := func(exists bool) { for _, member := range tombMembers { - headPrm.WithAddress(member) + headPrm.SetAddress(member) _, err := sh.Head(headPrm) diff --git a/pkg/local_object_storage/shard/delete.go b/pkg/local_object_storage/shard/delete.go index c9458cce..42f4c515 100644 --- a/pkg/local_object_storage/shard/delete.go +++ b/pkg/local_object_storage/shard/delete.go @@ -17,13 +17,11 @@ type DeletePrm struct { // DeleteRes groups the resulting values of Delete operation. type DeleteRes struct{} -// WithAddresses is a Delete option to set the addresses of the objects to delete. +// SetAddresses is a Delete option to set the addresses of the objects to delete. // // Option is required. -func (p *DeletePrm) WithAddresses(addr ...oid.Address) { - if p != nil { - p.addr = append(p.addr, addr...) - } +func (p *DeletePrm) SetAddresses(addr ...oid.Address) { + p.addr = append(p.addr, addr...) } // Delete removes data from the shard's writeCache, metaBase and diff --git a/pkg/local_object_storage/shard/delete_test.go b/pkg/local_object_storage/shard/delete_test.go index 189269a6..1fee9bcc 100644 --- a/pkg/local_object_storage/shard/delete_test.go +++ b/pkg/local_object_storage/shard/delete_test.go @@ -36,11 +36,11 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { t.Run("big object", func(t *testing.T) { addPayload(obj, 1<<20) - putPrm.WithObject(obj) - getPrm.WithAddress(object.AddressOf(obj)) + putPrm.SetObject(obj) + getPrm.SetAddress(object.AddressOf(obj)) var delPrm shard.DeletePrm - delPrm.WithAddresses(object.AddressOf(obj)) + delPrm.SetAddresses(object.AddressOf(obj)) _, err := sh.Put(putPrm) require.NoError(t, err) @@ -59,11 +59,11 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { obj.SetID(oidtest.ID()) addPayload(obj, 1<<5) - putPrm.WithObject(obj) - getPrm.WithAddress(object.AddressOf(obj)) + putPrm.SetObject(obj) + getPrm.SetAddress(object.AddressOf(obj)) var delPrm shard.DeletePrm - delPrm.WithAddresses(object.AddressOf(obj)) + delPrm.SetAddresses(object.AddressOf(obj)) _, err := sh.Put(putPrm) require.NoError(t, err) diff --git a/pkg/local_object_storage/shard/dump_test.go b/pkg/local_object_storage/shard/dump_test.go index b1c13c4b..d9d9bc52 100644 --- a/pkg/local_object_storage/shard/dump_test.go +++ b/pkg/local_object_storage/shard/dump_test.go @@ -95,7 +95,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) { objects[i] = obj var prm shard.PutPrm - prm.WithObject(objects[i]) + prm.SetObject(objects[i]) _, err := sh.Put(prm) require.NoError(t, err) } @@ -225,7 +225,7 @@ func TestStream(t *testing.T) { objects[i] = obj var prm shard.PutPrm - prm.WithObject(objects[i]) + prm.SetObject(objects[i]) _, err := sh1.Put(prm) require.NoError(t, err) } @@ -268,7 +268,7 @@ func checkRestore(t *testing.T, sh *shard.Shard, prm shard.RestorePrm, objects [ var getPrm shard.GetPrm for i := range objects { - getPrm.WithAddress(object.AddressOf(objects[i])) + getPrm.SetAddress(object.AddressOf(objects[i])) res, err := sh.Get(getPrm) require.NoError(t, err) require.Equal(t, objects[i], res.Object()) @@ -311,7 +311,7 @@ func TestDumpIgnoreErrors(t *testing.T) { objects[i] = obj var prm shard.PutPrm - prm.WithObject(objects[i]) + prm.SetObject(objects[i]) _, err := sh.Put(prm) require.NoError(t, err) } diff --git a/pkg/local_object_storage/shard/exists.go b/pkg/local_object_storage/shard/exists.go index 34d93a51..f862c880 100644 --- a/pkg/local_object_storage/shard/exists.go +++ b/pkg/local_object_storage/shard/exists.go @@ -17,13 +17,9 @@ type ExistsRes struct { ex bool } -// WithAddress is an Exists option to set object checked for existence. -func (p *ExistsPrm) WithAddress(addr oid.Address) *ExistsPrm { - if p != nil { - p.addr = addr - } - - return p +// SetAddress is an Exists option to set object checked for existence. +func (p *ExistsPrm) SetAddress(addr oid.Address) { + p.addr = addr } // Exists returns the fact that the object is in the shard. diff --git a/pkg/local_object_storage/shard/gc.go b/pkg/local_object_storage/shard/gc.go index c34e16e4..760fa546 100644 --- a/pkg/local_object_storage/shard/gc.go +++ b/pkg/local_object_storage/shard/gc.go @@ -210,7 +210,7 @@ func (s *Shard) removeGarbage() { } var deletePrm DeletePrm - deletePrm.WithAddresses(buf...) + deletePrm.SetAddresses(buf...) // delete accumulated objects _, err = s.Delete(deletePrm) diff --git a/pkg/local_object_storage/shard/get.go b/pkg/local_object_storage/shard/get.go index 478c4c10..d82d2d4f 100644 --- a/pkg/local_object_storage/shard/get.go +++ b/pkg/local_object_storage/shard/get.go @@ -29,18 +29,16 @@ type GetRes struct { hasMeta bool } -// WithAddress is a Get option to set the address of the requested object. +// SetAddress is a Get option to set the address of the requested object. // // Option is required. -func (p *GetPrm) WithAddress(addr oid.Address) { - if p != nil { - p.addr = addr - } +func (p *GetPrm) SetAddress(addr oid.Address) { + p.addr = addr } -// WithIgnoreMeta is a Get option try to fetch object from blobstor directly, +// SetIgnoreMeta is a Get option try to fetch object from blobstor directly, // without accessing metabase. -func (p *GetPrm) WithIgnoreMeta(ignore bool) { +func (p *GetPrm) SetIgnoreMeta(ignore bool) { p.skipMeta = ignore } diff --git a/pkg/local_object_storage/shard/get_test.go b/pkg/local_object_storage/shard/get_test.go index 038716bc..7756b2ba 100644 --- a/pkg/local_object_storage/shard/get_test.go +++ b/pkg/local_object_storage/shard/get_test.go @@ -36,12 +36,12 @@ func testShardGet(t *testing.T, hasWriteCache bool) { addAttribute(obj, "foo", "bar") addPayload(obj, 1<<5) - putPrm.WithObject(obj) + putPrm.SetObject(obj) _, err := sh.Put(putPrm) require.NoError(t, err) - getPrm.WithAddress(object.AddressOf(obj)) + getPrm.SetAddress(object.AddressOf(obj)) res, err := testGet(t, sh, getPrm, hasWriteCache) require.NoError(t, err) @@ -54,12 +54,12 @@ func testShardGet(t *testing.T, hasWriteCache bool) { obj.SetID(oidtest.ID()) addPayload(obj, 1<<20) // big obj - putPrm.WithObject(obj) + putPrm.SetObject(obj) _, err := sh.Put(putPrm) require.NoError(t, err) - getPrm.WithAddress(object.AddressOf(obj)) + getPrm.SetAddress(object.AddressOf(obj)) res, err := testGet(t, sh, getPrm, hasWriteCache) require.NoError(t, err) @@ -82,18 +82,18 @@ func testShardGet(t *testing.T, hasWriteCache bool) { child.SetSplitID(splitID) addPayload(child, 1<<5) - putPrm.WithObject(child) + putPrm.SetObject(child) _, err := sh.Put(putPrm) require.NoError(t, err) - getPrm.WithAddress(object.AddressOf(child)) + getPrm.SetAddress(object.AddressOf(child)) res, err := testGet(t, sh, getPrm, hasWriteCache) require.NoError(t, err) require.True(t, binaryEqual(child, res.Object())) - getPrm.WithAddress(object.AddressOf(parent)) + getPrm.SetAddress(object.AddressOf(parent)) _, err = testGet(t, sh, getPrm, hasWriteCache) diff --git a/pkg/local_object_storage/shard/head.go b/pkg/local_object_storage/shard/head.go index 62ad7062..4699c55f 100644 --- a/pkg/local_object_storage/shard/head.go +++ b/pkg/local_object_storage/shard/head.go @@ -20,22 +20,18 @@ type HeadRes struct { obj *objectSDK.Object } -// WithAddress is a Head option to set the address of the requested object. +// SetAddress is a Head option to set the address of the requested object. // // Option is required. -func (p *HeadPrm) WithAddress(addr oid.Address) { - if p != nil { - p.addr = addr - } +func (p *HeadPrm) SetAddress(addr oid.Address) { + p.addr = addr } -// WithRaw is a Head option to set raw flag value. If flag is unset, then Head +// SetRaw is a Head option to set raw flag value. If flag is unset, then Head // returns header of virtual object, otherwise it returns SplitInfo of virtual // object. -func (p *HeadPrm) WithRaw(raw bool) { - if p != nil { - p.raw = raw - } +func (p *HeadPrm) SetRaw(raw bool) { + p.raw = raw } // Object returns the requested object header. diff --git a/pkg/local_object_storage/shard/head_test.go b/pkg/local_object_storage/shard/head_test.go index b39ac955..00de09cf 100644 --- a/pkg/local_object_storage/shard/head_test.go +++ b/pkg/local_object_storage/shard/head_test.go @@ -33,12 +33,12 @@ func testShardHead(t *testing.T, hasWriteCache bool) { obj := generateObject(t) addAttribute(obj, "foo", "bar") - putPrm.WithObject(obj) + putPrm.SetObject(obj) _, err := sh.Put(putPrm) require.NoError(t, err) - headPrm.WithAddress(object.AddressOf(obj)) + headPrm.SetAddress(object.AddressOf(obj)) res, err := testHead(t, sh, headPrm, hasWriteCache) require.NoError(t, err) @@ -58,21 +58,21 @@ func testShardHead(t *testing.T, hasWriteCache bool) { child.SetParentID(idParent) child.SetSplitID(splitID) - putPrm.WithObject(child) + putPrm.SetObject(child) _, err := sh.Put(putPrm) require.NoError(t, err) - headPrm.WithAddress(object.AddressOf(parent)) - headPrm.WithRaw(true) + headPrm.SetAddress(object.AddressOf(parent)) + headPrm.SetRaw(true) var siErr *objectSDK.SplitInfoError _, err = testHead(t, sh, headPrm, hasWriteCache) require.True(t, errors.As(err, &siErr)) - headPrm.WithAddress(object.AddressOf(parent)) - headPrm.WithRaw(false) + headPrm.SetAddress(object.AddressOf(parent)) + headPrm.SetRaw(false) head, err := sh.Head(headPrm) require.NoError(t, err) diff --git a/pkg/local_object_storage/shard/inhume.go b/pkg/local_object_storage/shard/inhume.go index 41967438..92306819 100644 --- a/pkg/local_object_storage/shard/inhume.go +++ b/pkg/local_object_storage/shard/inhume.go @@ -20,21 +20,19 @@ type InhumePrm struct { // InhumeRes encapsulates results of inhume operation. type InhumeRes struct{} -// WithTarget sets a list of objects that should be inhumed and tombstone address +// SetTarget sets a list of objects that should be inhumed and tombstone address // as the reason for inhume operation. // // tombstone should not be nil, addr should not be empty. // Should not be called along with MarkAsGarbage. -func (p *InhumePrm) WithTarget(tombstone oid.Address, addrs ...oid.Address) { - if p != nil { - p.target = addrs - p.tombstone = &tombstone - } +func (p *InhumePrm) SetTarget(tombstone oid.Address, addrs ...oid.Address) { + p.target = addrs + p.tombstone = &tombstone } // MarkAsGarbage marks object to be physically removed from shard. // -// Should not be called along with WithTarget. +// Should not be called along with SetTarget. func (p *InhumePrm) MarkAsGarbage(addr ...oid.Address) { if p != nil { p.target = addr diff --git a/pkg/local_object_storage/shard/inhume_test.go b/pkg/local_object_storage/shard/inhume_test.go index cd3b6d33..dc02a037 100644 --- a/pkg/local_object_storage/shard/inhume_test.go +++ b/pkg/local_object_storage/shard/inhume_test.go @@ -32,13 +32,13 @@ func testShardInhume(t *testing.T, hasWriteCache bool) { ts := generateObjectWithCID(t, cnr) var putPrm shard.PutPrm - putPrm.WithObject(obj) + putPrm.SetObject(obj) var inhPrm shard.InhumePrm - inhPrm.WithTarget(object.AddressOf(ts), object.AddressOf(obj)) + inhPrm.SetTarget(object.AddressOf(ts), object.AddressOf(obj)) var getPrm shard.GetPrm - getPrm.WithAddress(object.AddressOf(obj)) + getPrm.SetAddress(object.AddressOf(obj)) _, err := sh.Put(putPrm) require.NoError(t, err) diff --git a/pkg/local_object_storage/shard/list_test.go b/pkg/local_object_storage/shard/list_test.go index 8e4c06ad..07290106 100644 --- a/pkg/local_object_storage/shard/list_test.go +++ b/pkg/local_object_storage/shard/list_test.go @@ -49,7 +49,7 @@ func testShardList(t *testing.T, sh *shard.Shard) { objs[object.AddressOf(obj).EncodeToString()] = 0 - putPrm.WithObject(obj) + putPrm.SetObject(obj) _, err := sh.Put(putPrm) require.NoError(t, err) diff --git a/pkg/local_object_storage/shard/lock_test.go b/pkg/local_object_storage/shard/lock_test.go index 81558dbf..270ecd71 100644 --- a/pkg/local_object_storage/shard/lock_test.go +++ b/pkg/local_object_storage/shard/lock_test.go @@ -57,7 +57,7 @@ func TestShard_Lock(t *testing.T) { // put the object var putPrm shard.PutPrm - putPrm.WithObject(obj) + putPrm.SetObject(obj) _, err := sh.Put(putPrm) require.NoError(t, err) @@ -67,7 +67,7 @@ func TestShard_Lock(t *testing.T) { err = sh.Lock(cnr, lockID, []oid.ID{objID}) require.NoError(t, err) - putPrm.WithObject(lock) + putPrm.SetObject(lock) _, err = sh.Put(putPrm) require.NoError(t, err) @@ -75,7 +75,7 @@ func TestShard_Lock(t *testing.T) { ts := generateObjectWithCID(t, cnr) var inhumePrm shard.InhumePrm - inhumePrm.WithTarget(objectcore.AddressOf(ts), objectcore.AddressOf(obj)) + inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(obj)) _, err = sh.Inhume(inhumePrm) require.ErrorAs(t, err, new(apistatus.ObjectLocked)) @@ -89,7 +89,7 @@ func TestShard_Lock(t *testing.T) { ts := generateObjectWithCID(t, cnr) var inhumePrm shard.InhumePrm - inhumePrm.WithTarget(objectcore.AddressOf(ts), objectcore.AddressOf(lock)) + inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(lock)) _, err = sh.Inhume(inhumePrm) require.Error(t, err) @@ -119,7 +119,7 @@ func TestShard_Lock(t *testing.T) { // check that object has been removed var getPrm shard.GetPrm - getPrm.WithAddress(objectcore.AddressOf(obj)) + getPrm.SetAddress(objectcore.AddressOf(obj)) _, err = sh.Get(getPrm) require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) diff --git a/pkg/local_object_storage/shard/move.go b/pkg/local_object_storage/shard/move.go index 8f117274..ef7bf619 100644 --- a/pkg/local_object_storage/shard/move.go +++ b/pkg/local_object_storage/shard/move.go @@ -14,12 +14,10 @@ type ToMoveItPrm struct { // ToMoveItRes encapsulates results of ToMoveIt operation. type ToMoveItRes struct{} -// WithAddress sets object address that should be marked to move into another +// SetAddress sets object address that should be marked to move into another // shard. -func (p *ToMoveItPrm) WithAddress(addr oid.Address) { - if p != nil { - p.addr = addr - } +func (p *ToMoveItPrm) SetAddress(addr oid.Address) { + p.addr = addr } // ToMoveIt calls metabase.ToMoveIt method to mark object as relocatable to diff --git a/pkg/local_object_storage/shard/put.go b/pkg/local_object_storage/shard/put.go index 7d8696b5..be5c79d8 100644 --- a/pkg/local_object_storage/shard/put.go +++ b/pkg/local_object_storage/shard/put.go @@ -17,11 +17,9 @@ type PutPrm struct { // PutRes groups the resulting values of Put operation. type PutRes struct{} -// WithObject is a Put option to set object to save. -func (p *PutPrm) WithObject(obj *object.Object) { - if p != nil { - p.obj = obj - } +// SetObject is a Put option to set object to save. +func (p *PutPrm) SetObject(obj *object.Object) { + p.obj = obj } // Put saves the object in shard. diff --git a/pkg/local_object_storage/shard/range.go b/pkg/local_object_storage/shard/range.go index 182cc37a..284561af 100644 --- a/pkg/local_object_storage/shard/range.go +++ b/pkg/local_object_storage/shard/range.go @@ -24,25 +24,21 @@ type RngRes struct { hasMeta bool } -// WithAddress is a Rng option to set the address of the requested object. +// SetAddress is a Rng option to set the address of the requested object. // // Option is required. -func (p *RngPrm) WithAddress(addr oid.Address) { - if p != nil { - p.addr = addr - } +func (p *RngPrm) SetAddress(addr oid.Address) { + p.addr = addr } -// WithRange is a GetRange option to set range of requested payload data. -func (p *RngPrm) WithRange(off uint64, ln uint64) { - if p != nil { - p.off, p.ln = off, ln - } +// SetRange is a GetRange option to set range of requested payload data. +func (p *RngPrm) SetRange(off uint64, ln uint64) { + p.off, p.ln = off, ln } -// WithIgnoreMeta is a Get option try to fetch object from blobstor directly, +// SetIgnoreMeta is a Get option try to fetch object from blobstor directly, // without accessing metabase. -func (p *RngPrm) WithIgnoreMeta(ignore bool) { +func (p *RngPrm) SetIgnoreMeta(ignore bool) { p.skipMeta = ignore } diff --git a/pkg/local_object_storage/shard/restore.go b/pkg/local_object_storage/shard/restore.go index 90087f1a..96d7f8b1 100644 --- a/pkg/local_object_storage/shard/restore.go +++ b/pkg/local_object_storage/shard/restore.go @@ -120,7 +120,7 @@ func (s *Shard) Restore(prm RestorePrm) (RestoreRes, error) { return RestoreRes{}, err } - putPrm.WithObject(obj) + putPrm.SetObject(obj) _, err = s.Put(putPrm) if err != nil { return RestoreRes{}, err diff --git a/pkg/local_object_storage/shard/select.go b/pkg/local_object_storage/shard/select.go index aa3d6bdf..58f7f150 100644 --- a/pkg/local_object_storage/shard/select.go +++ b/pkg/local_object_storage/shard/select.go @@ -20,18 +20,14 @@ type SelectRes struct { addrList []oid.Address } -// WithContainerID is a Select option to set the container id to search in. -func (p *SelectPrm) WithContainerID(cnr cid.ID) { - if p != nil { - p.cnr = cnr - } +// SetContainerID is a Select option to set the container id to search in. +func (p *SelectPrm) SetContainerID(cnr cid.ID) { + p.cnr = cnr } -// WithFilters is a Select option to set the object filters. -func (p *SelectPrm) WithFilters(fs object.SearchFilters) { - if p != nil { - p.filters = fs - } +// SetFilters is a Select option to set the object filters. +func (p *SelectPrm) SetFilters(fs object.SearchFilters) { + p.filters = fs } // AddressList returns list of addresses of the selected objects. diff --git a/pkg/local_object_storage/shard/shutdown_test.go b/pkg/local_object_storage/shard/shutdown_test.go index 60bee152..e4671d4e 100644 --- a/pkg/local_object_storage/shard/shutdown_test.go +++ b/pkg/local_object_storage/shard/shutdown_test.go @@ -40,7 +40,7 @@ func TestWriteCacheObjectLoss(t *testing.T) { var putPrm shard.PutPrm for i := range objects { - putPrm.WithObject(objects[i]) + putPrm.SetObject(objects[i]) _, err := sh.Put(putPrm) require.NoError(t, err) } @@ -52,7 +52,7 @@ func TestWriteCacheObjectLoss(t *testing.T) { var getPrm shard.GetPrm for i := range objects { - getPrm.WithAddress(object.AddressOf(objects[i])) + getPrm.SetAddress(object.AddressOf(objects[i])) _, err := sh.Get(getPrm) require.NoError(t, err, i)