From 882d010870ce4e8d4bd6accfa2905fe9d567115b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 30 Dec 2022 14:00:01 +0300 Subject: [PATCH] [#6] services/object: Remove useless helpers We have lots of small _private_ methods on `execCtx` whose sole purpose is to just return a struct field. Signed-off-by: Evgenii Stratonikov --- pkg/services/object/delete/exec.go | 32 ++-------- pkg/services/object/delete/local.go | 2 +- pkg/services/object/delete/util.go | 16 ++--- pkg/services/object/get/assemble.go | 30 ++++----- pkg/services/object/get/container.go | 8 +-- pkg/services/object/get/exec.go | 75 +++++------------------ pkg/services/object/get/get.go | 2 +- pkg/services/object/get/get_test.go | 8 +-- pkg/services/object/get/local.go | 4 +- pkg/services/object/get/remote.go | 4 +- pkg/services/object/get/util.go | 36 +++++------ pkg/services/object/search/container.go | 8 +-- pkg/services/object/search/exec.go | 31 +--------- pkg/services/object/search/search_test.go | 4 +- pkg/services/object/search/util.go | 10 +-- 15 files changed, 88 insertions(+), 182 deletions(-) diff --git a/pkg/services/object/delete/exec.go b/pkg/services/object/delete/exec.go index 4da4c8083..44fc358b2 100644 --- a/pkg/services/object/delete/exec.go +++ b/pkg/services/object/delete/exec.go @@ -5,9 +5,7 @@ import ( "strconv" objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" - cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "go.uber.org/zap" @@ -45,37 +43,17 @@ const ( func (exec *execCtx) setLogger(l *logger.Logger) { exec.log = &logger.Logger{Logger: l.With( zap.String("request", "DELETE"), - zap.Stringer("address", exec.address()), - zap.Bool("local", exec.isLocal()), + zap.Stringer("address", exec.prm.addr), + zap.Bool("local", exec.prm.common.LocalOnly()), zap.Bool("with session", exec.prm.common.SessionToken() != nil), zap.Bool("with bearer", exec.prm.common.BearerToken() != nil), )} } -func (exec execCtx) context() context.Context { - return exec.ctx -} - -func (exec execCtx) isLocal() bool { - return exec.prm.common.LocalOnly() -} - -func (exec *execCtx) address() oid.Address { - return exec.prm.addr -} - -func (exec *execCtx) containerID() cid.ID { - return exec.prm.addr.Container() -} - -func (exec *execCtx) commonParameters() *util.CommonPrm { - return exec.prm.common -} - func (exec *execCtx) newAddress(id oid.ID) oid.Address { var a oid.Address a.SetObject(id) - a.SetContainer(exec.containerID()) + a.SetContainer(exec.prm.addr.Container()) return a } @@ -241,11 +219,11 @@ func (exec *execCtx) initTombstoneObject() bool { } exec.tombstoneObj = object.New() - exec.tombstoneObj.SetContainerID(exec.containerID()) + exec.tombstoneObj.SetContainerID(exec.prm.addr.Container()) exec.tombstoneObj.SetType(object.TypeTombstone) exec.tombstoneObj.SetPayload(payload) - tokenSession := exec.commonParameters().SessionToken() + tokenSession := exec.prm.common.SessionToken() if tokenSession != nil { issuer := tokenSession.Issuer() exec.tombstoneObj.SetOwnerID(&issuer) diff --git a/pkg/services/object/delete/local.go b/pkg/services/object/delete/local.go index 36af96448..97b49e101 100644 --- a/pkg/services/object/delete/local.go +++ b/pkg/services/object/delete/local.go @@ -36,7 +36,7 @@ func (exec *execCtx) formTombstone() (ok bool) { exec.tombstone.SetExpirationEpoch( exec.svc.netInfo.CurrentEpoch() + tsLifetime, ) - exec.addMembers([]oid.ID{exec.address().Object()}) + exec.addMembers([]oid.ID{exec.prm.addr.Object()}) exec.log.Debug("forming split info...") diff --git a/pkg/services/object/delete/util.go b/pkg/services/object/delete/util.go index a8ebb3065..905b182dd 100644 --- a/pkg/services/object/delete/util.go +++ b/pkg/services/object/delete/util.go @@ -24,12 +24,12 @@ func (w *headSvcWrapper) headAddress(exec *execCtx, addr oid.Address) (*object.O wr := getsvc.NewSimpleObjectWriter() p := getsvc.HeadPrm{} - p.SetCommonParameters(exec.commonParameters()) + p.SetCommonParameters(exec.prm.common) p.SetHeaderWriter(wr) p.WithRawFlag(true) p.WithAddress(addr) - err := (*getsvc.Service)(w).Head(exec.context(), p) + err := (*getsvc.Service)(w).Head(exec.ctx, p) if err != nil { return nil, err } @@ -38,7 +38,7 @@ func (w *headSvcWrapper) headAddress(exec *execCtx, addr oid.Address) (*object.O } func (w *headSvcWrapper) splitInfo(exec *execCtx) (*object.SplitInfo, error) { - _, err := w.headAddress(exec, exec.address()) + _, err := w.headAddress(exec, exec.prm.addr) var errSplitInfo *object.SplitInfoError @@ -89,11 +89,11 @@ func (w *searchSvcWrapper) splitMembers(exec *execCtx) ([]oid.ID, error) { p := searchsvc.Prm{} p.SetWriter(wr) - p.SetCommonParameters(exec.commonParameters()) - p.WithContainerID(exec.containerID()) + p.SetCommonParameters(exec.prm.common) + p.WithContainerID(exec.prm.addr.Container()) p.WithSearchFilters(fs) - err := (*searchsvc.Service)(w).Search(exec.context(), p) + err := (*searchsvc.Service)(w).Search(exec.ctx, p) if err != nil { return nil, err } @@ -108,7 +108,7 @@ func (s *simpleIDWriter) WriteIDs(ids []oid.ID) error { } func (w *putSvcWrapper) put(exec *execCtx) (*oid.ID, error) { - streamer, err := (*putsvc.Service)(w).Put(exec.context()) + streamer, err := (*putsvc.Service)(w).Put(exec.ctx) if err != nil { return nil, err } @@ -116,7 +116,7 @@ func (w *putSvcWrapper) put(exec *execCtx) (*oid.ID, error) { payload := exec.tombstoneObj.Payload() initPrm := new(putsvc.PutInitPrm). - WithCommonPrm(exec.commonParameters()). + WithCommonPrm(exec.prm.common). WithObject(exec.tombstoneObj.CutPayload()) err = streamer.Init(initPrm) diff --git a/pkg/services/object/get/assemble.go b/pkg/services/object/get/assemble.go index ebae18eb5..149469e2a 100644 --- a/pkg/services/object/get/assemble.go +++ b/pkg/services/object/get/assemble.go @@ -36,26 +36,26 @@ func (exec *execCtx) assemble() { exec.log.Debug("trying to assemble the object...") - assembler := newAssembler(exec.address(), exec.splitInfo(), exec.ctxRange(), exec) + assembler := newAssembler(exec.prm.addr, exec.splitInfo, exec.prm.rng, exec) exec.log.Debug("assembling splitted object...", - zap.Stringer("address", exec.address()), - zap.Uint64("range_offset", exec.ctxRange().GetOffset()), - zap.Uint64("range_length", exec.ctxRange().GetLength()), + zap.Stringer("address", exec.prm.addr), + zap.Uint64("range_offset", exec.prm.rng.GetOffset()), + zap.Uint64("range_length", exec.prm.rng.GetLength()), ) defer exec.log.Debug("assembling splitted object completed", - zap.Stringer("address", exec.address()), - zap.Uint64("range_offset", exec.ctxRange().GetOffset()), - zap.Uint64("range_length", exec.ctxRange().GetLength()), + zap.Stringer("address", exec.prm.addr), + zap.Uint64("range_offset", exec.prm.rng.GetOffset()), + zap.Uint64("range_length", exec.prm.rng.GetLength()), ) - obj, err := assembler.Assemble(exec.context(), exec.prm.objWriter) + obj, err := assembler.Assemble(exec.ctx, exec.prm.objWriter) if err != nil { exec.log.Warn("failed to assemble splitted object", zap.Error(err), - zap.Stringer("address", exec.address()), - zap.Uint64("range_offset", exec.ctxRange().GetOffset()), - zap.Uint64("range_length", exec.ctxRange().GetLength()), + zap.Stringer("address", exec.prm.addr), + zap.Uint64("range_offset", exec.prm.rng.GetOffset()), + zap.Uint64("range_length", exec.prm.rng.GetLength()), ) } @@ -98,7 +98,7 @@ func equalAddresses(a, b oid.Address) bool { func (exec *execCtx) HeadObject(ctx context.Context, id oid.ID) (*objectSDK.Object, error) { p := exec.prm p.common = p.common.WithLocalOnly(false) - p.addr.SetContainer(exec.containerID()) + p.addr.SetContainer(exec.prm.addr.Container()) p.addr.SetObject(id) prm := HeadPrm{ @@ -108,7 +108,7 @@ func (exec *execCtx) HeadObject(ctx context.Context, id oid.ID) (*objectSDK.Obje w := NewSimpleObjectWriter() prm.SetHeaderWriter(w) //nolint: contextcheck - err := exec.svc.Head(exec.context(), prm) + err := exec.svc.Head(exec.ctx, prm) if err != nil { return nil, err @@ -125,11 +125,11 @@ func (exec *execCtx) GetObject(ctx context.Context, id oid.ID, rng *objectSDK.Ra p.objWriter = w p.SetRange(rng) - p.addr.SetContainer(exec.containerID()) + p.addr.SetContainer(exec.prm.addr.Container()) p.addr.SetObject(id) //nolint: contextcheck - statusError := exec.svc.get(exec.context(), p.commonPrm, withPayloadRange(rng)) + statusError := exec.svc.get(exec.ctx, p.commonPrm, withPayloadRange(rng)) if statusError.err != nil { return nil, statusError.err diff --git a/pkg/services/object/get/container.go b/pkg/services/object/get/container.go index 882861129..85ade334b 100644 --- a/pkg/services/object/get/container.go +++ b/pkg/services/object/get/container.go @@ -8,12 +8,12 @@ import ( ) func (exec *execCtx) executeOnContainer() { - if exec.isLocal() { + if exec.prm.common.LocalOnly() { exec.log.Debug("return result directly") return } - lookupDepth := exec.netmapLookupDepth() + lookupDepth := exec.prm.common.NetmapLookupDepth() exec.log.Debug("trying to execute in container...", zap.Uint64("netmap lookup depth", lookupDepth), @@ -47,12 +47,12 @@ func (exec *execCtx) processCurrentEpoch() bool { zap.Uint64("number", exec.curProcEpoch), ) - traverser, ok := exec.generateTraverser(exec.address()) + traverser, ok := exec.generateTraverser(exec.prm.addr) if !ok { return true } - ctx, cancel := context.WithCancel(exec.context()) + ctx, cancel := context.WithCancel(exec.ctx) defer cancel() exec.status = statusUndefined diff --git a/pkg/services/object/get/exec.go b/pkg/services/object/get/exec.go index 9858b32b2..2f4d98aca 100644 --- a/pkg/services/object/get/exec.go +++ b/pkg/services/object/get/exec.go @@ -8,7 +8,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" - cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "go.uber.org/zap" @@ -29,13 +28,13 @@ type execCtx struct { statusError - infoSplit *objectSDK.SplitInfo + splitInfo *objectSDK.SplitInfo log *logger.Logger collectedObject *objectSDK.Object - head bool + headOnly bool curProcEpoch uint64 } @@ -52,7 +51,7 @@ const ( func headOnly() execOption { return func(c *execCtx) { - c.head = true + c.headOnly = true } } @@ -64,38 +63,22 @@ func withPayloadRange(r *objectSDK.Range) execOption { func (exec *execCtx) setLogger(l *logger.Logger) { req := "GET" - if exec.headOnly() { + if exec.headOnly { req = "HEAD" - } else if exec.ctxRange() != nil { + } else if exec.prm.rng != nil { req = "GET_RANGE" } exec.log = &logger.Logger{Logger: l.With( zap.String("request", req), - zap.Stringer("address", exec.address()), - zap.Bool("raw", exec.isRaw()), - zap.Bool("local", exec.isLocal()), + zap.Stringer("address", exec.prm.addr), + zap.Bool("raw", exec.prm.raw), + zap.Bool("local", exec.prm.common.LocalOnly()), zap.Bool("with session", exec.prm.common.SessionToken() != nil), zap.Bool("with bearer", exec.prm.common.BearerToken() != nil), )} } -func (exec execCtx) context() context.Context { - return exec.ctx -} - -func (exec execCtx) isLocal() bool { - return exec.prm.common.LocalOnly() -} - -func (exec execCtx) isRaw() bool { - return exec.prm.raw -} - -func (exec execCtx) address() oid.Address { - return exec.prm.addr -} - func (exec execCtx) key() (*ecdsa.PrivateKey, error) { if exec.prm.signerKey != nil { // the key has already been requested and @@ -116,35 +99,11 @@ func (exec execCtx) key() (*ecdsa.PrivateKey, error) { } func (exec *execCtx) canAssemble() bool { - return !exec.isRaw() && !exec.headOnly() -} - -func (exec *execCtx) splitInfo() *objectSDK.SplitInfo { - return exec.infoSplit -} - -func (exec *execCtx) containerID() cid.ID { - return exec.address().Container() -} - -func (exec *execCtx) ctxRange() *objectSDK.Range { - return exec.prm.rng -} - -func (exec *execCtx) headOnly() bool { - return exec.head -} - -func (exec *execCtx) netmapEpoch() uint64 { - return exec.prm.common.NetmapEpoch() -} - -func (exec *execCtx) netmapLookupDepth() uint64 { - return exec.prm.common.NetmapLookupDepth() + return !exec.prm.raw && !exec.headOnly } func (exec *execCtx) initEpoch() bool { - exec.curProcEpoch = exec.netmapEpoch() + exec.curProcEpoch = exec.prm.common.NetmapEpoch() if exec.curProcEpoch > 0 { return true } @@ -218,12 +177,12 @@ func mergeSplitInfo(dst, src *objectSDK.SplitInfo) { } func (exec *execCtx) writeCollectedHeader() bool { - if exec.ctxRange() != nil { + if exec.prm.rng != nil { return true } err := exec.prm.objWriter.WriteHeader( - exec.context(), + exec.ctx, exec.collectedObject.CutPayload(), ) @@ -244,11 +203,11 @@ func (exec *execCtx) writeCollectedHeader() bool { } func (exec *execCtx) writeObjectPayload(obj *objectSDK.Object) bool { - if exec.headOnly() { + if exec.headOnly { return true } - err := exec.prm.objWriter.WriteChunk(exec.context(), obj.Payload()) + err := exec.prm.objWriter.WriteChunk(exec.ctx, obj.Payload()) switch { default: @@ -272,12 +231,6 @@ func (exec *execCtx) writeCollectedObject() { } } -// isForwardingEnabled returns true if common execution -// parameters has request forwarding closure set. -func (exec execCtx) isForwardingEnabled() bool { - return exec.prm.forwarder != nil -} - // disableForwarding removes request forwarding closure from common // parameters, so it won't be inherited in new execution contexts. func (exec *execCtx) disableForwarding() { diff --git a/pkg/services/object/get/get.go b/pkg/services/object/get/get.go index cdb2d96fd..2502a93ca 100644 --- a/pkg/services/object/get/get.go +++ b/pkg/services/object/get/get.go @@ -69,7 +69,7 @@ func (s *Service) get(ctx context.Context, prm commonPrm, opts ...execOption) st prm: RangePrm{ commonPrm: prm, }, - infoSplit: object.NewSplitInfo(), + splitInfo: object.NewSplitInfo(), } for i := range opts { diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index 09d0c38fa..b860491d8 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -118,7 +118,7 @@ func newTestClient() *testClient { } func (c *testClient) getObject(exec *execCtx, _ client.NodeInfo) (*objectSDK.Object, error) { - v, ok := c.results[exec.address().EncodeToString()] + v, ok := c.results[exec.prm.addr.EncodeToString()] if !ok { var errNotFound apistatus.ObjectNotFound @@ -129,7 +129,7 @@ func (c *testClient) getObject(exec *execCtx, _ client.NodeInfo) (*objectSDK.Obj return nil, v.err } - return cutToRange(v.obj, exec.ctxRange()), nil + return cutToRange(v.obj, exec.prm.rng), nil } func (c *testClient) addResult(addr oid.Address, obj *objectSDK.Object, err error) { @@ -143,7 +143,7 @@ func (s *testStorage) get(exec *execCtx) (*objectSDK.Object, error) { var ( ok bool obj *objectSDK.Object - sAddr = exec.address().EncodeToString() + sAddr = exec.prm.addr.EncodeToString() ) if _, ok = s.inhumed[sAddr]; ok { @@ -157,7 +157,7 @@ func (s *testStorage) get(exec *execCtx) (*objectSDK.Object, error) { } if obj, ok = s.phy[sAddr]; ok { - return cutToRange(obj, exec.ctxRange()), nil + return cutToRange(obj, exec.prm.rng), nil } var errNotFound apistatus.ObjectNotFound diff --git a/pkg/services/object/get/local.go b/pkg/services/object/get/local.go index f526af4e6..75de59a5c 100644 --- a/pkg/services/object/get/local.go +++ b/pkg/services/object/get/local.go @@ -34,8 +34,8 @@ func (exec *execCtx) executeLocal() { exec.err = errRemoved case errors.As(err, &errSplitInfo): exec.status = statusVIRTUAL - mergeSplitInfo(exec.splitInfo(), errSplitInfo.SplitInfo()) - exec.err = objectSDK.NewSplitInfoError(exec.infoSplit) + mergeSplitInfo(exec.splitInfo, errSplitInfo.SplitInfo()) + exec.err = objectSDK.NewSplitInfoError(exec.splitInfo) case errors.As(err, &errOutOfRange): exec.status = statusOutOfRange exec.err = errOutOfRange diff --git a/pkg/services/object/get/remote.go b/pkg/services/object/get/remote.go index fbfb01bcd..946cc8d84 100644 --- a/pkg/services/object/get/remote.go +++ b/pkg/services/object/get/remote.go @@ -54,8 +54,8 @@ func (exec *execCtx) processNode(ctx context.Context, info client.NodeInfo) bool exec.err = errOutOfRange case errors.As(err, &errSplitInfo): exec.status = statusVIRTUAL - mergeSplitInfo(exec.splitInfo(), errSplitInfo.SplitInfo()) - exec.err = objectSDK.NewSplitInfoError(exec.infoSplit) + mergeSplitInfo(exec.splitInfo, errSplitInfo.SplitInfo()) + exec.err = objectSDK.NewSplitInfoError(exec.splitInfo) } return exec.status != statusUndefined diff --git a/pkg/services/object/get/util.go b/pkg/services/object/get/util.go index d647b07f6..7dfc6e662 100644 --- a/pkg/services/object/get/util.go +++ b/pkg/services/object/get/util.go @@ -89,7 +89,7 @@ func (c *clientCacheWrapper) get(info coreclient.NodeInfo) (getClient, error) { // nolint: funlen func (c *clientWrapper) getObject(exec *execCtx, info coreclient.NodeInfo) (*object.Object, error) { - if exec.isForwardingEnabled() { + if exec.prm.forwarder != nil { return exec.prm.forwarder(info, c.client) } @@ -98,20 +98,20 @@ func (c *clientWrapper) getObject(exec *execCtx, info coreclient.NodeInfo) (*obj return nil, err } - if exec.headOnly() { + if exec.headOnly { var prm internalclient.HeadObjectPrm - prm.SetContext(exec.context()) + prm.SetContext(exec.ctx) prm.SetClient(c.client) prm.SetTTL(exec.prm.common.TTL()) prm.SetNetmapEpoch(exec.curProcEpoch) - prm.SetAddress(exec.address()) + prm.SetAddress(exec.prm.addr) prm.SetPrivateKey(key) prm.SetSessionToken(exec.prm.common.SessionToken()) prm.SetBearerToken(exec.prm.common.BearerToken()) prm.SetXHeaders(exec.prm.common.XHeaders()) - if exec.isRaw() { + if exec.prm.raw { prm.SetRawFlag() } @@ -124,21 +124,21 @@ func (c *clientWrapper) getObject(exec *execCtx, info coreclient.NodeInfo) (*obj } // we don't specify payload writer because we accumulate // the object locally (even huge). - if rng := exec.ctxRange(); rng != nil { + if rng := exec.prm.rng; rng != nil { var prm internalclient.PayloadRangePrm - prm.SetContext(exec.context()) + prm.SetContext(exec.ctx) prm.SetClient(c.client) prm.SetTTL(exec.prm.common.TTL()) prm.SetNetmapEpoch(exec.curProcEpoch) - prm.SetAddress(exec.address()) + prm.SetAddress(exec.prm.addr) prm.SetPrivateKey(key) prm.SetSessionToken(exec.prm.common.SessionToken()) prm.SetBearerToken(exec.prm.common.BearerToken()) prm.SetXHeaders(exec.prm.common.XHeaders()) prm.SetRange(rng) - if exec.isRaw() { + if exec.prm.raw { prm.SetRawFlag() } @@ -175,17 +175,17 @@ func (c *clientWrapper) getObject(exec *execCtx, info coreclient.NodeInfo) (*obj func (c *clientWrapper) get(exec *execCtx, key *ecdsa.PrivateKey) (*object.Object, error) { var prm internalclient.GetObjectPrm - prm.SetContext(exec.context()) + prm.SetContext(exec.ctx) prm.SetClient(c.client) prm.SetTTL(exec.prm.common.TTL()) prm.SetNetmapEpoch(exec.curProcEpoch) - prm.SetAddress(exec.address()) + prm.SetAddress(exec.prm.addr) prm.SetPrivateKey(key) prm.SetSessionToken(exec.prm.common.SessionToken()) prm.SetBearerToken(exec.prm.common.BearerToken()) prm.SetXHeaders(exec.prm.common.XHeaders()) - if exec.isRaw() { + if exec.prm.raw { prm.SetRawFlag() } @@ -198,10 +198,10 @@ func (c *clientWrapper) get(exec *execCtx, key *ecdsa.PrivateKey) (*object.Objec } func (e *storageEngineWrapper) get(exec *execCtx) (*object.Object, error) { - if exec.headOnly() { + if exec.headOnly { var headPrm engine.HeadPrm - headPrm.WithAddress(exec.address()) - headPrm.WithRaw(exec.isRaw()) + headPrm.WithAddress(exec.prm.addr) + headPrm.WithRaw(exec.prm.raw) r, err := e.engine.Head(headPrm) if err != nil { @@ -209,9 +209,9 @@ func (e *storageEngineWrapper) get(exec *execCtx) (*object.Object, error) { } return r.Header(), nil - } else if rng := exec.ctxRange(); rng != nil { + } else if rng := exec.prm.rng; rng != nil { var getRange engine.RngPrm - getRange.WithAddress(exec.address()) + getRange.WithAddress(exec.prm.addr) getRange.WithPayloadRange(rng) r, err := e.engine.GetRange(getRange) @@ -222,7 +222,7 @@ func (e *storageEngineWrapper) get(exec *execCtx) (*object.Object, error) { return r.Object(), nil } else { var getPrm engine.GetPrm - getPrm.WithAddress(exec.address()) + getPrm.WithAddress(exec.prm.addr) r, err := e.engine.Get(getPrm) if err != nil { diff --git a/pkg/services/object/search/container.go b/pkg/services/object/search/container.go index fffcba42a..ee59fffc7 100644 --- a/pkg/services/object/search/container.go +++ b/pkg/services/object/search/container.go @@ -10,12 +10,12 @@ import ( ) func (exec *execCtx) executeOnContainer() { - if exec.isLocal() { + if exec.prm.common.LocalOnly() { exec.log.Debug("return result directly") return } - lookupDepth := exec.netmapLookupDepth() + lookupDepth := exec.prm.common.NetmapLookupDepth() exec.log.Debug("trying to execute in container...", zap.Uint64("netmap lookup depth", lookupDepth), @@ -52,12 +52,12 @@ func (exec *execCtx) processCurrentEpoch() bool { zap.Uint64("number", exec.curProcEpoch), ) - traverser, ok := exec.generateTraverser(exec.containerID()) + traverser, ok := exec.generateTraverser(exec.prm.cnr) if !ok { return true } - ctx, cancel := context.WithCancel(exec.context()) + ctx, cancel := context.WithCancel(exec.ctx) defer cancel() for { diff --git a/pkg/services/object/search/exec.go b/pkg/services/object/search/exec.go index a1737b521..22d049e79 100644 --- a/pkg/services/object/search/exec.go +++ b/pkg/services/object/search/exec.go @@ -6,7 +6,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" - "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "go.uber.org/zap" ) @@ -45,39 +44,15 @@ func (exec *execCtx) prepare() { func (exec *execCtx) setLogger(l *logger.Logger) { exec.log = &logger.Logger{Logger: l.With( zap.String("request", "SEARCH"), - zap.Stringer("container", exec.containerID()), - zap.Bool("local", exec.isLocal()), + zap.Stringer("container", exec.prm.cnr), + zap.Bool("local", exec.prm.common.LocalOnly()), zap.Bool("with session", exec.prm.common.SessionToken() != nil), zap.Bool("with bearer", exec.prm.common.BearerToken() != nil), )} } -func (exec execCtx) context() context.Context { - return exec.ctx -} - -func (exec execCtx) isLocal() bool { - return exec.prm.common.LocalOnly() -} - -func (exec *execCtx) containerID() cid.ID { - return exec.prm.cnr -} - -func (exec *execCtx) searchFilters() object.SearchFilters { - return exec.prm.filters -} - -func (exec *execCtx) netmapEpoch() uint64 { - return exec.prm.common.NetmapEpoch() -} - -func (exec *execCtx) netmapLookupDepth() uint64 { - return exec.prm.common.NetmapLookupDepth() -} - func (exec *execCtx) initEpoch() bool { - exec.curProcEpoch = exec.netmapEpoch() + exec.curProcEpoch = exec.prm.common.NetmapEpoch() if exec.curProcEpoch > 0 { return true } diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index bb3d422b3..a9c6d219d 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -103,7 +103,7 @@ func (c *testClientCache) get(info clientcore.NodeInfo) (searchClient, error) { } func (s *testStorage) search(exec *execCtx) ([]oid.ID, error) { - v, ok := s.items[exec.containerID().EncodeToString()] + v, ok := s.items[exec.prm.cnr.EncodeToString()] if !ok { return nil, nil } @@ -112,7 +112,7 @@ func (s *testStorage) search(exec *execCtx) ([]oid.ID, error) { } func (c *testStorage) searchObjects(exec *execCtx, _ clientcore.NodeInfo) ([]oid.ID, error) { - v, ok := c.items[exec.containerID().EncodeToString()] + v, ok := c.items[exec.prm.cnr.EncodeToString()] if !ok { return nil, nil } diff --git a/pkg/services/object/search/util.go b/pkg/services/object/search/util.go index 741a224af..9477cb428 100644 --- a/pkg/services/object/search/util.go +++ b/pkg/services/object/search/util.go @@ -98,7 +98,7 @@ func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]oi var prm internalclient.SearchObjectsPrm - prm.SetContext(exec.context()) + prm.SetContext(exec.ctx) prm.SetClient(c.client) prm.SetPrivateKey(key) prm.SetSessionToken(exec.prm.common.SessionToken()) @@ -106,8 +106,8 @@ func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]oi prm.SetTTL(exec.prm.common.TTL()) prm.SetXHeaders(exec.prm.common.XHeaders()) prm.SetNetmapEpoch(exec.curProcEpoch) - prm.SetContainerID(exec.containerID()) - prm.SetFilters(exec.searchFilters()) + prm.SetContainerID(exec.prm.cnr) + prm.SetFilters(exec.prm.filters) res, err := internalclient.SearchObjects(prm) if err != nil { @@ -119,8 +119,8 @@ func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]oi func (e *storageEngineWrapper) search(exec *execCtx) ([]oid.ID, error) { var selectPrm engine.SelectPrm - selectPrm.WithFilters(exec.searchFilters()) - selectPrm.WithContainerID(exec.containerID()) + selectPrm.WithFilters(exec.prm.filters) + selectPrm.WithContainerID(exec.prm.cnr) r, err := e.storage.Select(selectPrm) if err != nil {