From a862cb403796d1ec7fee52dfb4daa7ee507e6ea6 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 17 Jan 2024 17:59:33 +0400 Subject: [PATCH] object/search: Do not access the node repeatedly within the same request Previously, `ObjectService.Search` RPC server could send a request to a remote container node more than once in the context of processing a single client request. On the one hand, this makes no sense, since the state of the remote node is assumed to be unchanged in the context of a single request. On the other hand, the resource costs for a repeated request are prohibitively high - signatures, network, local storage. In practice, repetitions occurred in two cases: - storage policy specifics, e.g. with several replica (`REP`) rules - when switching processing to previous epochs: some nodes could "remain" in the container This is solved by storing the processed nodes in memory. Incurs much lower costs than repeated requests. Signed-off-by: Leonard Lyubich --- pkg/services/object/search/container.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/services/object/search/container.go b/pkg/services/object/search/container.go index 5c238cde9c8..b27a3497e73 100644 --- a/pkg/services/object/search/container.go +++ b/pkg/services/object/search/container.go @@ -27,8 +27,10 @@ func (exec *execCtx) executeOnContainer() { return } + mProcessedNodes := make(map[string]struct{}) + for { - if exec.processCurrentEpoch() { + if exec.processCurrentEpoch(mProcessedNodes) { break } @@ -47,7 +49,7 @@ func (exec *execCtx) executeOnContainer() { exec.err = nil } -func (exec *execCtx) processCurrentEpoch() bool { +func (exec *execCtx) processCurrentEpoch(mProcessedNodes map[string]struct{}) bool { exec.log.Debug("process epoch", zap.Uint64("number", exec.curProcEpoch), ) @@ -71,6 +73,13 @@ func (exec *execCtx) processCurrentEpoch() bool { var mtx sync.Mutex for i := range addrs { + strKey := string(addrs[i].PublicKey()) + if _, ok = mProcessedNodes[strKey]; ok { + continue + } + + mProcessedNodes[strKey] = struct{}{} + wg.Add(1) go func(i int) { defer wg.Done()