Skip to content

Commit f65eeb3

Browse files
node/object: Improve SEARCH and GET (#2722)
2 parents fd9fe83 + 2521e89 commit f65eeb3

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ For example, `attr>=100` or `attr=` are now processed differently. See `-h` for
8585
- Incorrect handling of notary request leading to inability to collect signatures in some cases (#2715)
8686
- Deadlock in autodeploy routine (#2720)
8787
- SN now validates session tokens attached to objects (#1159)
88+
- Object search server no longer wastes system resources sending empty intermediate messages to the stream (#2722)
8889

8990
### Changed
9091
- Created files are not group writable (#2589)

pkg/services/object/get/container.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (exec *execCtx) processEpoch(epoch uint64) bool {
4141
defer cancel()
4242

4343
exec.status = statusUndefined
44+
mProcessedNodes := make(map[string]struct{})
4445

4546
for {
4647
addrs := traverser.Next()
@@ -61,6 +62,13 @@ func (exec *execCtx) processEpoch(epoch uint64) bool {
6162
default:
6263
}
6364

65+
strKey := string(addrs[i].PublicKey())
66+
if _, ok = mProcessedNodes[strKey]; ok {
67+
continue
68+
}
69+
70+
mProcessedNodes[strKey] = struct{}{}
71+
6472
// TODO: #1142 consider parallel execution
6573
// TODO: #1142 consider optimization: if status == SPLIT we can continue until
6674
// we reach the best result - split info with linking object ID.

pkg/services/object/get/get_test.go

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

429+
bPubKey := make([]byte, 33)
430+
rand.Read(bPubKey)
431+
429432
var ni netmap.NodeInfo
430433
ni.SetNetworkEndpoints(a)
434+
ni.SetPublicKey(bPubKey)
431435

432436
var na network.AddressGroup
433437

pkg/services/object/search/container.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ func (exec *execCtx) processEpoch(epoch uint64) bool {
4545
ctx, cancel := context.WithCancel(exec.context())
4646
defer cancel()
4747

48+
mProcessedNodes := make(map[string]struct{})
49+
4850
for {
4951
addrs := traverser.Next()
5052
if len(addrs) == 0 {
@@ -56,6 +58,13 @@ func (exec *execCtx) processEpoch(epoch uint64) bool {
5658
var mtx sync.Mutex
5759

5860
for i := range addrs {
61+
strKey := string(addrs[i].PublicKey())
62+
if _, ok = mProcessedNodes[strKey]; ok {
63+
continue
64+
}
65+
66+
mProcessedNodes[strKey] = struct{}{}
67+
5968
wg.Add(1)
6069
go func(i int) {
6170
defer wg.Done()

pkg/services/object/search/exec.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ func (exec *execCtx) generateTraverser(cnr cid.ID, epoch uint64) (*placement.Tra
8383
}
8484

8585
func (exec *execCtx) writeIDList(ids []oid.ID) {
86-
err := exec.prm.writer.WriteIDs(ids)
86+
var err error
87+
88+
if len(ids) > 0 {
89+
err = exec.prm.writer.WriteIDs(ids)
90+
}
8791

8892
switch {
8993
default:

pkg/services/object/search/search_test.go

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

213+
bPubKey := make([]byte, 33)
214+
rand.Read(bPubKey)
215+
213216
var ni netmap.NodeInfo
214217
ni.SetNetworkEndpoints(a)
218+
ni.SetPublicKey(bPubKey)
215219

216220
var na network.AddressGroup
217221

0 commit comments

Comments
 (0)