[#9999] engine: PutPrm refactoring
Use fields instead of methods. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
57c31e9802
commit
327b29348f
2 changed files with 8 additions and 22 deletions
|
@ -82,11 +82,7 @@ func TestListWithCursor(t *testing.T) {
|
|||
for range tt.objectNum {
|
||||
containerID := cidtest.ID()
|
||||
obj := testutil.GenerateObjectWithCIDWithPayload(containerID, []byte{'a'})
|
||||
|
||||
var prm PutPrm
|
||||
prm.WithObject(obj)
|
||||
|
||||
err := e.Put(context.Background(), prm)
|
||||
err := e.Put(context.Background(), PutPrm{Object: obj})
|
||||
require.NoError(t, err)
|
||||
expected = append(expected, object.Info{Type: objectSDK.TypeRegular, Address: object.AddressOf(obj)})
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
|
||||
// PutPrm groups the parameters of Put operation.
|
||||
type PutPrm struct {
|
||||
obj *objectSDK.Object
|
||||
Object *objectSDK.Object
|
||||
}
|
||||
|
||||
var errPutShard = errors.New("could not put object to any shard")
|
||||
|
@ -41,13 +41,6 @@ type putToShardRes struct {
|
|||
err error
|
||||
}
|
||||
|
||||
// WithObject is a Put option to set object to save.
|
||||
//
|
||||
// Option is required.
|
||||
func (p *PutPrm) WithObject(obj *objectSDK.Object) {
|
||||
p.obj = obj
|
||||
}
|
||||
|
||||
// Put saves the object to local storage.
|
||||
//
|
||||
// Returns any error encountered that
|
||||
|
@ -59,7 +52,7 @@ func (p *PutPrm) WithObject(obj *objectSDK.Object) {
|
|||
func (e *StorageEngine) Put(ctx context.Context, prm PutPrm) (err error) {
|
||||
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.Put",
|
||||
trace.WithAttributes(
|
||||
attribute.String("address", object.AddressOf(prm.obj).EncodeToString()),
|
||||
attribute.String("address", object.AddressOf(prm.Object).EncodeToString()),
|
||||
))
|
||||
defer span.End()
|
||||
|
||||
|
@ -76,13 +69,13 @@ func (e *StorageEngine) put(ctx context.Context, prm PutPrm) error {
|
|||
defer elapsed("Put", e.metrics.AddMethodDuration)()
|
||||
}
|
||||
|
||||
addr := object.AddressOf(prm.obj)
|
||||
addr := object.AddressOf(prm.Object)
|
||||
|
||||
// In #1146 this check was parallelized, however, it became
|
||||
// much slower on fast machines for 4 shards.
|
||||
var parent oid.Address
|
||||
if prm.obj.ECHeader() != nil {
|
||||
parent.SetObject(prm.obj.ECHeader().Parent())
|
||||
if prm.Object.ECHeader() != nil {
|
||||
parent.SetObject(prm.Object.ECHeader().Parent())
|
||||
parent.SetContainer(addr.Container())
|
||||
}
|
||||
var shPrm shard.ExistsPrm
|
||||
|
@ -115,7 +108,7 @@ func (e *StorageEngine) put(ctx context.Context, prm PutPrm) error {
|
|||
// Shard was concurrently removed, skip.
|
||||
return false
|
||||
}
|
||||
shRes = e.putToShard(ctx, sh, pool, addr, prm.obj)
|
||||
shRes = e.putToShard(ctx, sh, pool, addr, prm.Object)
|
||||
return shRes.status != putToShardUnknown
|
||||
})
|
||||
switch shRes.status {
|
||||
|
@ -204,8 +197,5 @@ func (e *StorageEngine) putToShard(ctx context.Context, sh hashedShard, pool uti
|
|||
|
||||
// Put writes provided object to local storage.
|
||||
func Put(ctx context.Context, storage *StorageEngine, obj *objectSDK.Object) error {
|
||||
var putPrm PutPrm
|
||||
putPrm.WithObject(obj)
|
||||
|
||||
return storage.Put(ctx, putPrm)
|
||||
return storage.Put(ctx, PutPrm{Object: obj})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue