Skip to content

Commit 7b06cee

Browse files
committed
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 <[email protected]>
1 parent 04d99d4 commit 7b06cee

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pkg/services/object/search/container.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ func (exec *execCtx) executeOnContainer() {
2727
return
2828
}
2929

30+
mProcessedNodes := make(map[string]struct{})
31+
3032
for {
31-
if exec.processCurrentEpoch() {
33+
if exec.processCurrentEpoch(mProcessedNodes) {
3234
break
3335
}
3436

@@ -47,7 +49,7 @@ func (exec *execCtx) executeOnContainer() {
4749
exec.err = nil
4850
}
4951

50-
func (exec *execCtx) processCurrentEpoch() bool {
52+
func (exec *execCtx) processCurrentEpoch(mProcessedNodes map[string]struct{}) bool {
5153
exec.log.Debug("process epoch",
5254
zap.Uint64("number", exec.curProcEpoch),
5355
)
@@ -71,6 +73,13 @@ func (exec *execCtx) processCurrentEpoch() bool {
7173
var mtx sync.Mutex
7274

7375
for i := range addrs {
76+
strKey := string(addrs[i].PublicKey())
77+
if _, ok = mProcessedNodes[strKey]; ok {
78+
continue
79+
}
80+
81+
mProcessedNodes[strKey] = struct{}{}
82+
7483
wg.Add(1)
7584
go func(i int) {
7685
defer wg.Done()

pkg/services/object/search/search_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,12 @@ func testNodeMatrix(t testing.TB, dim []int) ([][]netmap.NodeInfo, [][]string) {
208208
strconv.Itoa(60000+j),
209209
)
210210

211+
bPubKey := make([]byte, 33)
212+
rand.Read(bPubKey)
213+
211214
var ni netmap.NodeInfo
212215
ni.SetNetworkEndpoints(a)
216+
ni.SetPublicKey(bPubKey)
213217

214218
var na network.AddressGroup
215219

0 commit comments

Comments
 (0)