[#1412] engine: PutPrm refactoring

Use fields instead of methods.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-10-01 13:28:46 +03:00
parent 0c49bca19c
commit 899cd55c27
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
2 changed files with 8 additions and 22 deletions

View file

@ -82,11 +82,7 @@ func TestListWithCursor(t *testing.T) {
for range tt.objectNum { for range tt.objectNum {
containerID := cidtest.ID() containerID := cidtest.ID()
obj := testutil.GenerateObjectWithCIDWithPayload(containerID, []byte{'a'}) obj := testutil.GenerateObjectWithCIDWithPayload(containerID, []byte{'a'})
err := e.Put(context.Background(), PutPrm{Object: obj})
var prm PutPrm
prm.WithObject(obj)
err := e.Put(context.Background(), prm)
require.NoError(t, err) require.NoError(t, err)
expected = append(expected, object.Info{Type: objectSDK.TypeRegular, Address: object.AddressOf(obj)}) expected = append(expected, object.Info{Type: objectSDK.TypeRegular, Address: object.AddressOf(obj)})
} }

View file

@ -22,7 +22,7 @@ import (
// PutPrm groups the parameters of Put operation. // PutPrm groups the parameters of Put operation.
type PutPrm struct { type PutPrm struct {
obj *objectSDK.Object Object *objectSDK.Object
} }
var errPutShard = errors.New("could not put object to any shard") var errPutShard = errors.New("could not put object to any shard")
@ -41,13 +41,6 @@ type putToShardRes struct {
err error 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. // Put saves the object to local storage.
// //
// Returns any error encountered that // 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) { func (e *StorageEngine) Put(ctx context.Context, prm PutPrm) (err error) {
ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.Put", ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.Put",
trace.WithAttributes( trace.WithAttributes(
attribute.String("address", object.AddressOf(prm.obj).EncodeToString()), attribute.String("address", object.AddressOf(prm.Object).EncodeToString()),
)) ))
defer span.End() defer span.End()
@ -74,13 +67,13 @@ func (e *StorageEngine) Put(ctx context.Context, prm PutPrm) (err error) {
func (e *StorageEngine) put(ctx context.Context, prm PutPrm) error { func (e *StorageEngine) put(ctx context.Context, prm PutPrm) error {
defer elapsed("Put", e.metrics.AddMethodDuration)() 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 // In #1146 this check was parallelized, however, it became
// much slower on fast machines for 4 shards. // much slower on fast machines for 4 shards.
var parent oid.Address var parent oid.Address
if prm.obj.ECHeader() != nil { if prm.Object.ECHeader() != nil {
parent.SetObject(prm.obj.ECHeader().Parent()) parent.SetObject(prm.Object.ECHeader().Parent())
parent.SetContainer(addr.Container()) parent.SetContainer(addr.Container())
} }
var shPrm shard.ExistsPrm var shPrm shard.ExistsPrm
@ -113,7 +106,7 @@ func (e *StorageEngine) put(ctx context.Context, prm PutPrm) error {
// Shard was concurrently removed, skip. // Shard was concurrently removed, skip.
return false return false
} }
shRes = e.putToShard(ctx, sh, pool, addr, prm.obj) shRes = e.putToShard(ctx, sh, pool, addr, prm.Object)
return shRes.status != putToShardUnknown return shRes.status != putToShardUnknown
}) })
switch shRes.status { switch shRes.status {
@ -202,8 +195,5 @@ func (e *StorageEngine) putToShard(ctx context.Context, sh hashedShard, pool uti
// Put writes provided object to local storage. // Put writes provided object to local storage.
func Put(ctx context.Context, storage *StorageEngine, obj *objectSDK.Object) error { func Put(ctx context.Context, storage *StorageEngine, obj *objectSDK.Object) error {
var putPrm PutPrm return storage.Put(ctx, PutPrm{Object: obj})
putPrm.WithObject(obj)
return storage.Put(ctx, putPrm)
} }