[#1559] shard: Use Set prefix for parameter setting

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-07-13 15:43:04 +03:00 committed by fyrchik
parent 7b882b26d8
commit d8ba954aff
34 changed files with 114 additions and 142 deletions

View file

@ -72,7 +72,7 @@ func (e *StorageEngine) containerSize(prm ContainerSizePrm) (res ContainerSizeRe
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) { e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
var csPrm shard.ContainerSizePrm var csPrm shard.ContainerSizePrm
csPrm.WithContainerID(prm.cnr) csPrm.SetContainerID(prm.cnr)
csRes, err := sh.Shard.ContainerSize(csPrm) csRes, err := sh.Shard.ContainerSize(csPrm)
if err != nil { if err != nil {

View file

@ -68,7 +68,7 @@ func (e *StorageEngine) delete(prm DeletePrm) (DeleteRes, error) {
for i := range prm.addr { for i := range prm.addr {
e.iterateOverSortedShards(prm.addr[i], func(_ int, sh hashedShard) (stop bool) { e.iterateOverSortedShards(prm.addr[i], func(_ int, sh hashedShard) (stop bool) {
var existsPrm shard.ExistsPrm var existsPrm shard.ExistsPrm
existsPrm.WithAddress(prm.addr[i]) existsPrm.SetAddress(prm.addr[i])
resExists, err := sh.Exists(existsPrm) resExists, err := sh.Exists(existsPrm)
if err != nil { if err != nil {

View file

@ -70,7 +70,7 @@ func TestErrorReporting(t *testing.T) {
obj.SetPayload(make([]byte, errSmallSize)) obj.SetPayload(make([]byte, errSmallSize))
var prm shard.PutPrm var prm shard.PutPrm
prm.WithObject(obj) prm.SetObject(obj)
e.mtx.RLock() e.mtx.RLock()
_, err := e.shards[id[0].String()].Shard.Put(prm) _, err := e.shards[id[0].String()].Shard.Put(prm)
e.mtx.RUnlock() e.mtx.RUnlock()
@ -100,7 +100,7 @@ func TestErrorReporting(t *testing.T) {
obj.SetPayload(make([]byte, errSmallSize)) obj.SetPayload(make([]byte, errSmallSize))
var prm shard.PutPrm var prm shard.PutPrm
prm.WithObject(obj) prm.SetObject(obj)
e.mtx.RLock() e.mtx.RLock()
_, err := e.shards[id[0].String()].Put(prm) _, err := e.shards[id[0].String()].Put(prm)
e.mtx.RUnlock() e.mtx.RUnlock()
@ -150,7 +150,7 @@ func TestBlobstorFailback(t *testing.T) {
obj.SetPayload(make([]byte, size)) obj.SetPayload(make([]byte, size))
var prm shard.PutPrm var prm shard.PutPrm
prm.WithObject(obj) prm.SetObject(obj)
e.mtx.RLock() e.mtx.RLock()
_, err = e.shards[id[0].String()].Shard.Put(prm) _, err = e.shards[id[0].String()].Shard.Put(prm)
e.mtx.RUnlock() e.mtx.RUnlock()

View file

@ -8,7 +8,7 @@ import (
func (e *StorageEngine) exists(addr oid.Address) (bool, error) { func (e *StorageEngine) exists(addr oid.Address) (bool, error) {
var shPrm shard.ExistsPrm var shPrm shard.ExistsPrm
shPrm.WithAddress(addr) shPrm.SetAddress(addr)
alreadyRemoved := false alreadyRemoved := false
exists := false exists := false

View file

@ -72,7 +72,7 @@ func (e *StorageEngine) get(prm GetPrm) (GetRes, error) {
) )
var shPrm shard.GetPrm var shPrm shard.GetPrm
shPrm.WithAddress(prm.addr) shPrm.SetAddress(prm.addr)
e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) { e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) {
res, err := sh.Get(shPrm) 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, // If the object is not found but is present in metabase,
// try to fetch it from blobstor directly. If it is found in any // 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. // 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) { e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) {
res, err := sh.Get(shPrm) res, err := sh.Get(shPrm)

View file

@ -80,8 +80,8 @@ func (e *StorageEngine) head(prm HeadPrm) (HeadRes, error) {
) )
var shPrm shard.HeadPrm var shPrm shard.HeadPrm
shPrm.WithAddress(prm.addr) shPrm.SetAddress(prm.addr)
shPrm.WithRaw(prm.raw) shPrm.SetRaw(prm.raw)
e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) { e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) {
res, err := sh.Head(shPrm) res, err := sh.Head(shPrm)

View file

@ -47,10 +47,10 @@ func TestHeadRaw(t *testing.T) {
defer e.Close() defer e.Close()
var putPrmLeft shard.PutPrm var putPrmLeft shard.PutPrm
putPrmLeft.WithObject(child) putPrmLeft.SetObject(child)
var putPrmLink shard.PutPrm var putPrmLink shard.PutPrm
putPrmLink.WithObject(link) putPrmLink.SetObject(link)
// put most left object in one shard // put most left object in one shard
_, err := s1.Put(putPrmLeft) _, err := s1.Put(putPrmLeft)

View file

@ -86,7 +86,7 @@ func (e *StorageEngine) inhume(prm InhumePrm) (InhumeRes, error) {
for i := range prm.addrs { for i := range prm.addrs {
if prm.tombstone != nil { if prm.tombstone != nil {
shPrm.WithTarget(*prm.tombstone, prm.addrs[i]) shPrm.SetTarget(*prm.tombstone, prm.addrs[i])
} else { } else {
shPrm.MarkAsGarbage(prm.addrs[i]) shPrm.MarkAsGarbage(prm.addrs[i])
} }
@ -129,7 +129,7 @@ func (e *StorageEngine) inhumeAddr(addr oid.Address, prm shard.InhumePrm, checkE
}() }()
if checkExists { if checkExists {
existPrm.WithAddress(addr) existPrm.SetAddress(addr)
exRes, err := sh.Exists(existPrm) exRes, err := sh.Exists(existPrm)
if err != nil { if err != nil {
if shard.IsErrRemoved(err) { if shard.IsErrRemoved(err) {

View file

@ -62,12 +62,12 @@ func TestStorageEngine_Inhume(t *testing.T) {
defer e.Close() defer e.Close()
var putChild shard.PutPrm var putChild shard.PutPrm
putChild.WithObject(child) putChild.SetObject(child)
_, err := s1.Put(putChild) _, err := s1.Put(putChild)
require.NoError(t, err) require.NoError(t, err)
var putLink shard.PutPrm var putLink shard.PutPrm
putLink.WithObject(link) putLink.SetObject(link)
_, err = s2.Put(putLink) _, err = s2.Put(putLink)
require.NoError(t, err) require.NoError(t, err)

View file

@ -66,7 +66,7 @@ func (e *StorageEngine) lockSingle(idCnr cid.ID, locker, locked oid.ID, checkExi
if checkExists { if checkExists {
var existsPrm shard.ExistsPrm var existsPrm shard.ExistsPrm
existsPrm.WithAddress(addrLocked) existsPrm.SetAddress(addrLocked)
exRes, err := sh.Exists(existsPrm) exRes, err := sh.Exists(existsPrm)
if err != nil { if err != nil {

View file

@ -60,7 +60,7 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
} }
var existPrm shard.ExistsPrm var existPrm shard.ExistsPrm
existPrm.WithAddress(addr) existPrm.SetAddress(addr)
finished := false finished := false
@ -82,7 +82,7 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
if exists.Exists() { if exists.Exists() {
if ind != 0 { if ind != 0 {
var toMoveItPrm shard.ToMoveItPrm var toMoveItPrm shard.ToMoveItPrm
toMoveItPrm.WithAddress(addr) toMoveItPrm.SetAddress(addr)
_, err = sh.ToMoveIt(toMoveItPrm) _, err = sh.ToMoveIt(toMoveItPrm)
if err != nil { if err != nil {
@ -99,7 +99,7 @@ func (e *StorageEngine) put(prm PutPrm) (PutRes, error) {
} }
var putPrm shard.PutPrm var putPrm shard.PutPrm
putPrm.WithObject(prm.obj) putPrm.SetObject(prm.obj)
_, err = sh.Put(putPrm) _, err = sh.Put(putPrm)
if err != nil { if err != nil {

View file

@ -87,8 +87,8 @@ func (e *StorageEngine) getRange(prm RngPrm) (RngRes, error) {
) )
var shPrm shard.RngPrm var shPrm shard.RngPrm
shPrm.WithAddress(prm.addr) shPrm.SetAddress(prm.addr)
shPrm.WithRange(prm.off, prm.ln) shPrm.SetRange(prm.off, prm.ln)
e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) { e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) {
res, err := sh.GetRange(shPrm) 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, // If the object is not found but is present in metabase,
// try to fetch it from blobstor directly. If it is found in any // 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. // 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) { e.iterateOverSortedShards(prm.addr, func(_ int, sh hashedShard) (stop bool) {
res, err := sh.GetRange(shPrm) res, err := sh.GetRange(shPrm)

View file

@ -62,8 +62,8 @@ func (e *StorageEngine) _select(prm SelectPrm) (SelectRes, error) {
var outError error var outError error
var shPrm shard.SelectPrm var shPrm shard.SelectPrm
shPrm.WithContainerID(prm.cnr) shPrm.SetContainerID(prm.cnr)
shPrm.WithFilters(prm.filters) shPrm.SetFilters(prm.filters)
e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) { e.iterateOverUnsortedShards(func(sh hashedShard) (stop bool) {
res, err := sh.Select(shPrm) res, err := sh.Select(shPrm)

View file

@ -14,11 +14,9 @@ type ContainerSizeRes struct {
size uint64 size uint64
} }
func (p *ContainerSizePrm) WithContainerID(cnr cid.ID) { func (p *ContainerSizePrm) SetContainerID(cnr cid.ID) {
if p != nil {
p.cnr = cnr p.cnr = cnr
} }
}
func (r ContainerSizeRes) Size() uint64 { func (r ContainerSizeRes) Size() uint64 {
return r.size return r.size

View file

@ -42,7 +42,7 @@ func TestRefillMetabaseCorrupted(t *testing.T) {
obj.SetPayload([]byte{0, 1, 2, 3, 4, 5}) obj.SetPayload([]byte{0, 1, 2, 3, 4, 5})
var putPrm PutPrm var putPrm PutPrm
putPrm.WithObject(obj) putPrm.SetObject(obj)
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, sh.Close()) require.NoError(t, sh.Close())
@ -64,7 +64,7 @@ func TestRefillMetabaseCorrupted(t *testing.T) {
require.NoError(t, sh.Init()) require.NoError(t, sh.Init())
var getPrm GetPrm var getPrm GetPrm
getPrm.WithAddress(addr) getPrm.SetAddress(addr)
_, err = sh.Get(getPrm) _, err = sh.Get(getPrm)
require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
require.NoError(t, sh.Close()) require.NoError(t, sh.Close())
@ -150,13 +150,13 @@ func TestRefillMetabase(t *testing.T) {
var putPrm PutPrm var putPrm PutPrm
for _, v := range mObjs { for _, v := range mObjs {
putPrm.WithObject(v.obj) putPrm.SetObject(v.obj)
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
} }
putPrm.WithObject(tombObj) putPrm.SetObject(tombObj)
_, err = sh.Put(putPrm) _, err = sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
@ -169,7 +169,7 @@ func TestRefillMetabase(t *testing.T) {
lockObj.SetContainerID(cnrLocked) lockObj.SetContainerID(cnrLocked)
objectSDK.WriteLock(lockObj, lock) objectSDK.WriteLock(lockObj, lock)
putPrm.WithObject(lockObj) putPrm.SetObject(lockObj)
_, err = sh.Put(putPrm) _, err = sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
@ -177,7 +177,7 @@ func TestRefillMetabase(t *testing.T) {
require.NoError(t, sh.Lock(cnrLocked, lockID, locked)) require.NoError(t, sh.Lock(cnrLocked, lockID, locked))
var inhumePrm InhumePrm var inhumePrm InhumePrm
inhumePrm.WithTarget(object.AddressOf(tombObj), tombMembers...) inhumePrm.SetTarget(object.AddressOf(tombObj), tombMembers...)
_, err = sh.Inhume(inhumePrm) _, err = sh.Inhume(inhumePrm)
require.NoError(t, err) require.NoError(t, err)
@ -185,7 +185,7 @@ func TestRefillMetabase(t *testing.T) {
var headPrm HeadPrm var headPrm HeadPrm
checkObj := func(addr oid.Address, expObj *objectSDK.Object) { checkObj := func(addr oid.Address, expObj *objectSDK.Object) {
headPrm.WithAddress(addr) headPrm.SetAddress(addr)
res, err := sh.Head(headPrm) res, err := sh.Head(headPrm)
@ -210,7 +210,7 @@ func TestRefillMetabase(t *testing.T) {
checkTombMembers := func(exists bool) { checkTombMembers := func(exists bool) {
for _, member := range tombMembers { for _, member := range tombMembers {
headPrm.WithAddress(member) headPrm.SetAddress(member)
_, err := sh.Head(headPrm) _, err := sh.Head(headPrm)

View file

@ -17,14 +17,12 @@ type DeletePrm struct {
// DeleteRes groups the resulting values of Delete operation. // DeleteRes groups the resulting values of Delete operation.
type DeleteRes struct{} 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. // Option is required.
func (p *DeletePrm) WithAddresses(addr ...oid.Address) { func (p *DeletePrm) SetAddresses(addr ...oid.Address) {
if p != nil {
p.addr = append(p.addr, addr...) p.addr = append(p.addr, addr...)
} }
}
// Delete removes data from the shard's writeCache, metaBase and // Delete removes data from the shard's writeCache, metaBase and
// blobStor. // blobStor.

View file

@ -36,11 +36,11 @@ func testShardDelete(t *testing.T, hasWriteCache bool) {
t.Run("big object", func(t *testing.T) { t.Run("big object", func(t *testing.T) {
addPayload(obj, 1<<20) addPayload(obj, 1<<20)
putPrm.WithObject(obj) putPrm.SetObject(obj)
getPrm.WithAddress(object.AddressOf(obj)) getPrm.SetAddress(object.AddressOf(obj))
var delPrm shard.DeletePrm var delPrm shard.DeletePrm
delPrm.WithAddresses(object.AddressOf(obj)) delPrm.SetAddresses(object.AddressOf(obj))
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
@ -59,11 +59,11 @@ func testShardDelete(t *testing.T, hasWriteCache bool) {
obj.SetID(oidtest.ID()) obj.SetID(oidtest.ID())
addPayload(obj, 1<<5) addPayload(obj, 1<<5)
putPrm.WithObject(obj) putPrm.SetObject(obj)
getPrm.WithAddress(object.AddressOf(obj)) getPrm.SetAddress(object.AddressOf(obj))
var delPrm shard.DeletePrm var delPrm shard.DeletePrm
delPrm.WithAddresses(object.AddressOf(obj)) delPrm.SetAddresses(object.AddressOf(obj))
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)

View file

@ -95,7 +95,7 @@ func testDump(t *testing.T, objCount int, hasWriteCache bool) {
objects[i] = obj objects[i] = obj
var prm shard.PutPrm var prm shard.PutPrm
prm.WithObject(objects[i]) prm.SetObject(objects[i])
_, err := sh.Put(prm) _, err := sh.Put(prm)
require.NoError(t, err) require.NoError(t, err)
} }
@ -225,7 +225,7 @@ func TestStream(t *testing.T) {
objects[i] = obj objects[i] = obj
var prm shard.PutPrm var prm shard.PutPrm
prm.WithObject(objects[i]) prm.SetObject(objects[i])
_, err := sh1.Put(prm) _, err := sh1.Put(prm)
require.NoError(t, err) require.NoError(t, err)
} }
@ -268,7 +268,7 @@ func checkRestore(t *testing.T, sh *shard.Shard, prm shard.RestorePrm, objects [
var getPrm shard.GetPrm var getPrm shard.GetPrm
for i := range objects { for i := range objects {
getPrm.WithAddress(object.AddressOf(objects[i])) getPrm.SetAddress(object.AddressOf(objects[i]))
res, err := sh.Get(getPrm) res, err := sh.Get(getPrm)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, objects[i], res.Object()) require.Equal(t, objects[i], res.Object())
@ -311,7 +311,7 @@ func TestDumpIgnoreErrors(t *testing.T) {
objects[i] = obj objects[i] = obj
var prm shard.PutPrm var prm shard.PutPrm
prm.WithObject(objects[i]) prm.SetObject(objects[i])
_, err := sh.Put(prm) _, err := sh.Put(prm)
require.NoError(t, err) require.NoError(t, err)
} }

View file

@ -17,15 +17,11 @@ type ExistsRes struct {
ex bool ex bool
} }
// WithAddress is an Exists option to set object checked for existence. // SetAddress is an Exists option to set object checked for existence.
func (p *ExistsPrm) WithAddress(addr oid.Address) *ExistsPrm { func (p *ExistsPrm) SetAddress(addr oid.Address) {
if p != nil {
p.addr = addr p.addr = addr
} }
return p
}
// Exists returns the fact that the object is in the shard. // Exists returns the fact that the object is in the shard.
func (p ExistsRes) Exists() bool { func (p ExistsRes) Exists() bool {
return p.ex return p.ex

View file

@ -210,7 +210,7 @@ func (s *Shard) removeGarbage() {
} }
var deletePrm DeletePrm var deletePrm DeletePrm
deletePrm.WithAddresses(buf...) deletePrm.SetAddresses(buf...)
// delete accumulated objects // delete accumulated objects
_, err = s.Delete(deletePrm) _, err = s.Delete(deletePrm)

View file

@ -29,18 +29,16 @@ type GetRes struct {
hasMeta bool 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. // Option is required.
func (p *GetPrm) WithAddress(addr oid.Address) { func (p *GetPrm) SetAddress(addr oid.Address) {
if p != nil {
p.addr = addr 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. // without accessing metabase.
func (p *GetPrm) WithIgnoreMeta(ignore bool) { func (p *GetPrm) SetIgnoreMeta(ignore bool) {
p.skipMeta = ignore p.skipMeta = ignore
} }

View file

@ -36,12 +36,12 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
addAttribute(obj, "foo", "bar") addAttribute(obj, "foo", "bar")
addPayload(obj, 1<<5) addPayload(obj, 1<<5)
putPrm.WithObject(obj) putPrm.SetObject(obj)
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
getPrm.WithAddress(object.AddressOf(obj)) getPrm.SetAddress(object.AddressOf(obj))
res, err := testGet(t, sh, getPrm, hasWriteCache) res, err := testGet(t, sh, getPrm, hasWriteCache)
require.NoError(t, err) require.NoError(t, err)
@ -54,12 +54,12 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
obj.SetID(oidtest.ID()) obj.SetID(oidtest.ID())
addPayload(obj, 1<<20) // big obj addPayload(obj, 1<<20) // big obj
putPrm.WithObject(obj) putPrm.SetObject(obj)
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
getPrm.WithAddress(object.AddressOf(obj)) getPrm.SetAddress(object.AddressOf(obj))
res, err := testGet(t, sh, getPrm, hasWriteCache) res, err := testGet(t, sh, getPrm, hasWriteCache)
require.NoError(t, err) require.NoError(t, err)
@ -82,18 +82,18 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
child.SetSplitID(splitID) child.SetSplitID(splitID)
addPayload(child, 1<<5) addPayload(child, 1<<5)
putPrm.WithObject(child) putPrm.SetObject(child)
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
getPrm.WithAddress(object.AddressOf(child)) getPrm.SetAddress(object.AddressOf(child))
res, err := testGet(t, sh, getPrm, hasWriteCache) res, err := testGet(t, sh, getPrm, hasWriteCache)
require.NoError(t, err) require.NoError(t, err)
require.True(t, binaryEqual(child, res.Object())) require.True(t, binaryEqual(child, res.Object()))
getPrm.WithAddress(object.AddressOf(parent)) getPrm.SetAddress(object.AddressOf(parent))
_, err = testGet(t, sh, getPrm, hasWriteCache) _, err = testGet(t, sh, getPrm, hasWriteCache)

View file

@ -20,23 +20,19 @@ type HeadRes struct {
obj *objectSDK.Object 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. // Option is required.
func (p *HeadPrm) WithAddress(addr oid.Address) { func (p *HeadPrm) SetAddress(addr oid.Address) {
if p != nil {
p.addr = addr 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 // returns header of virtual object, otherwise it returns SplitInfo of virtual
// object. // object.
func (p *HeadPrm) WithRaw(raw bool) { func (p *HeadPrm) SetRaw(raw bool) {
if p != nil {
p.raw = raw p.raw = raw
} }
}
// Object returns the requested object header. // Object returns the requested object header.
func (r HeadRes) Object() *objectSDK.Object { func (r HeadRes) Object() *objectSDK.Object {

View file

@ -33,12 +33,12 @@ func testShardHead(t *testing.T, hasWriteCache bool) {
obj := generateObject(t) obj := generateObject(t)
addAttribute(obj, "foo", "bar") addAttribute(obj, "foo", "bar")
putPrm.WithObject(obj) putPrm.SetObject(obj)
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
headPrm.WithAddress(object.AddressOf(obj)) headPrm.SetAddress(object.AddressOf(obj))
res, err := testHead(t, sh, headPrm, hasWriteCache) res, err := testHead(t, sh, headPrm, hasWriteCache)
require.NoError(t, err) require.NoError(t, err)
@ -58,21 +58,21 @@ func testShardHead(t *testing.T, hasWriteCache bool) {
child.SetParentID(idParent) child.SetParentID(idParent)
child.SetSplitID(splitID) child.SetSplitID(splitID)
putPrm.WithObject(child) putPrm.SetObject(child)
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
headPrm.WithAddress(object.AddressOf(parent)) headPrm.SetAddress(object.AddressOf(parent))
headPrm.WithRaw(true) headPrm.SetRaw(true)
var siErr *objectSDK.SplitInfoError var siErr *objectSDK.SplitInfoError
_, err = testHead(t, sh, headPrm, hasWriteCache) _, err = testHead(t, sh, headPrm, hasWriteCache)
require.True(t, errors.As(err, &siErr)) require.True(t, errors.As(err, &siErr))
headPrm.WithAddress(object.AddressOf(parent)) headPrm.SetAddress(object.AddressOf(parent))
headPrm.WithRaw(false) headPrm.SetRaw(false)
head, err := sh.Head(headPrm) head, err := sh.Head(headPrm)
require.NoError(t, err) require.NoError(t, err)

View file

@ -20,21 +20,19 @@ type InhumePrm struct {
// InhumeRes encapsulates results of inhume operation. // InhumeRes encapsulates results of inhume operation.
type InhumeRes struct{} 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. // as the reason for inhume operation.
// //
// tombstone should not be nil, addr should not be empty. // tombstone should not be nil, addr should not be empty.
// Should not be called along with MarkAsGarbage. // Should not be called along with MarkAsGarbage.
func (p *InhumePrm) WithTarget(tombstone oid.Address, addrs ...oid.Address) { func (p *InhumePrm) SetTarget(tombstone oid.Address, addrs ...oid.Address) {
if p != nil {
p.target = addrs p.target = addrs
p.tombstone = &tombstone p.tombstone = &tombstone
} }
}
// MarkAsGarbage marks object to be physically removed from shard. // 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) { func (p *InhumePrm) MarkAsGarbage(addr ...oid.Address) {
if p != nil { if p != nil {
p.target = addr p.target = addr

View file

@ -32,13 +32,13 @@ func testShardInhume(t *testing.T, hasWriteCache bool) {
ts := generateObjectWithCID(t, cnr) ts := generateObjectWithCID(t, cnr)
var putPrm shard.PutPrm var putPrm shard.PutPrm
putPrm.WithObject(obj) putPrm.SetObject(obj)
var inhPrm shard.InhumePrm var inhPrm shard.InhumePrm
inhPrm.WithTarget(object.AddressOf(ts), object.AddressOf(obj)) inhPrm.SetTarget(object.AddressOf(ts), object.AddressOf(obj))
var getPrm shard.GetPrm var getPrm shard.GetPrm
getPrm.WithAddress(object.AddressOf(obj)) getPrm.SetAddress(object.AddressOf(obj))
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)

View file

@ -49,7 +49,7 @@ func testShardList(t *testing.T, sh *shard.Shard) {
objs[object.AddressOf(obj).EncodeToString()] = 0 objs[object.AddressOf(obj).EncodeToString()] = 0
putPrm.WithObject(obj) putPrm.SetObject(obj)
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)

View file

@ -57,7 +57,7 @@ func TestShard_Lock(t *testing.T) {
// put the object // put the object
var putPrm shard.PutPrm var putPrm shard.PutPrm
putPrm.WithObject(obj) putPrm.SetObject(obj)
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
@ -67,7 +67,7 @@ func TestShard_Lock(t *testing.T) {
err = sh.Lock(cnr, lockID, []oid.ID{objID}) err = sh.Lock(cnr, lockID, []oid.ID{objID})
require.NoError(t, err) require.NoError(t, err)
putPrm.WithObject(lock) putPrm.SetObject(lock)
_, err = sh.Put(putPrm) _, err = sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
@ -75,7 +75,7 @@ func TestShard_Lock(t *testing.T) {
ts := generateObjectWithCID(t, cnr) ts := generateObjectWithCID(t, cnr)
var inhumePrm shard.InhumePrm var inhumePrm shard.InhumePrm
inhumePrm.WithTarget(objectcore.AddressOf(ts), objectcore.AddressOf(obj)) inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(obj))
_, err = sh.Inhume(inhumePrm) _, err = sh.Inhume(inhumePrm)
require.ErrorAs(t, err, new(apistatus.ObjectLocked)) require.ErrorAs(t, err, new(apistatus.ObjectLocked))
@ -89,7 +89,7 @@ func TestShard_Lock(t *testing.T) {
ts := generateObjectWithCID(t, cnr) ts := generateObjectWithCID(t, cnr)
var inhumePrm shard.InhumePrm var inhumePrm shard.InhumePrm
inhumePrm.WithTarget(objectcore.AddressOf(ts), objectcore.AddressOf(lock)) inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(lock))
_, err = sh.Inhume(inhumePrm) _, err = sh.Inhume(inhumePrm)
require.Error(t, err) require.Error(t, err)
@ -119,7 +119,7 @@ func TestShard_Lock(t *testing.T) {
// check that object has been removed // check that object has been removed
var getPrm shard.GetPrm var getPrm shard.GetPrm
getPrm.WithAddress(objectcore.AddressOf(obj)) getPrm.SetAddress(objectcore.AddressOf(obj))
_, err = sh.Get(getPrm) _, err = sh.Get(getPrm)
require.ErrorAs(t, err, new(apistatus.ObjectNotFound)) require.ErrorAs(t, err, new(apistatus.ObjectNotFound))

View file

@ -14,13 +14,11 @@ type ToMoveItPrm struct {
// ToMoveItRes encapsulates results of ToMoveIt operation. // ToMoveItRes encapsulates results of ToMoveIt operation.
type ToMoveItRes struct{} 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. // shard.
func (p *ToMoveItPrm) WithAddress(addr oid.Address) { func (p *ToMoveItPrm) SetAddress(addr oid.Address) {
if p != nil {
p.addr = addr p.addr = addr
} }
}
// ToMoveIt calls metabase.ToMoveIt method to mark object as relocatable to // ToMoveIt calls metabase.ToMoveIt method to mark object as relocatable to
// another shard. // another shard.

View file

@ -17,12 +17,10 @@ type PutPrm struct {
// PutRes groups the resulting values of Put operation. // PutRes groups the resulting values of Put operation.
type PutRes struct{} type PutRes struct{}
// WithObject is a Put option to set object to save. // SetObject is a Put option to set object to save.
func (p *PutPrm) WithObject(obj *object.Object) { func (p *PutPrm) SetObject(obj *object.Object) {
if p != nil {
p.obj = obj p.obj = obj
} }
}
// Put saves the object in shard. // Put saves the object in shard.
// //

View file

@ -24,25 +24,21 @@ type RngRes struct {
hasMeta bool 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. // Option is required.
func (p *RngPrm) WithAddress(addr oid.Address) { func (p *RngPrm) SetAddress(addr oid.Address) {
if p != nil {
p.addr = addr p.addr = addr
} }
}
// WithRange is a GetRange option to set range of requested payload data. // SetRange is a GetRange option to set range of requested payload data.
func (p *RngPrm) WithRange(off uint64, ln uint64) { func (p *RngPrm) SetRange(off uint64, ln uint64) {
if p != nil {
p.off, p.ln = off, ln 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. // without accessing metabase.
func (p *RngPrm) WithIgnoreMeta(ignore bool) { func (p *RngPrm) SetIgnoreMeta(ignore bool) {
p.skipMeta = ignore p.skipMeta = ignore
} }

View file

@ -120,7 +120,7 @@ func (s *Shard) Restore(prm RestorePrm) (RestoreRes, error) {
return RestoreRes{}, err return RestoreRes{}, err
} }
putPrm.WithObject(obj) putPrm.SetObject(obj)
_, err = s.Put(putPrm) _, err = s.Put(putPrm)
if err != nil { if err != nil {
return RestoreRes{}, err return RestoreRes{}, err

View file

@ -20,19 +20,15 @@ type SelectRes struct {
addrList []oid.Address addrList []oid.Address
} }
// WithContainerID is a Select option to set the container id to search in. // SetContainerID is a Select option to set the container id to search in.
func (p *SelectPrm) WithContainerID(cnr cid.ID) { func (p *SelectPrm) SetContainerID(cnr cid.ID) {
if p != nil {
p.cnr = cnr p.cnr = cnr
} }
}
// WithFilters is a Select option to set the object filters. // SetFilters is a Select option to set the object filters.
func (p *SelectPrm) WithFilters(fs object.SearchFilters) { func (p *SelectPrm) SetFilters(fs object.SearchFilters) {
if p != nil {
p.filters = fs p.filters = fs
} }
}
// AddressList returns list of addresses of the selected objects. // AddressList returns list of addresses of the selected objects.
func (r SelectRes) AddressList() []oid.Address { func (r SelectRes) AddressList() []oid.Address {

View file

@ -40,7 +40,7 @@ func TestWriteCacheObjectLoss(t *testing.T) {
var putPrm shard.PutPrm var putPrm shard.PutPrm
for i := range objects { for i := range objects {
putPrm.WithObject(objects[i]) putPrm.SetObject(objects[i])
_, err := sh.Put(putPrm) _, err := sh.Put(putPrm)
require.NoError(t, err) require.NoError(t, err)
} }
@ -52,7 +52,7 @@ func TestWriteCacheObjectLoss(t *testing.T) {
var getPrm shard.GetPrm var getPrm shard.GetPrm
for i := range objects { for i := range objects {
getPrm.WithAddress(object.AddressOf(objects[i])) getPrm.SetAddress(object.AddressOf(objects[i]))
_, err := sh.Get(getPrm) _, err := sh.Get(getPrm)
require.NoError(t, err, i) require.NoError(t, err, i)