Skip to content

Commit 6f5d97c

Browse files
committed
services/object: use SearchV2 for search objects
Closes #3143. Signed-off-by: Andrey Butusov <[email protected]>
1 parent a2d4f15 commit 6f5d97c

File tree

2 files changed

+28
-37
lines changed

2 files changed

+28
-37
lines changed

pkg/services/object/internal/client/client.go

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"io"
10+
"slices"
1011

1112
coreclient "github.com/nspcc-dev/neofs-node/pkg/core/client"
1213
"github.com/nspcc-dev/neofs-sdk-go/bearer"
@@ -415,8 +416,8 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) {
415416
type SearchObjectsPrm struct {
416417
readPrmCommon
417418

418-
cid cid.ID
419-
cliPrm client.PrmObjectSearch
419+
cid cid.ID
420+
fs object.SearchFilters
420421
}
421422

422423
// SetContainerID sets identifier of the container to search the objects.
@@ -428,53 +429,43 @@ func (x *SearchObjectsPrm) SetContainerID(id cid.ID) {
428429

429430
// SetFilters sets search filters.
430431
func (x *SearchObjectsPrm) SetFilters(fs object.SearchFilters) {
431-
x.cliPrm.SetFilters(fs)
432-
}
433-
434-
// SearchObjectsRes groups the resulting values of SearchObjects operation.
435-
type SearchObjectsRes struct {
436-
ids []oid.ID
437-
}
438-
439-
// IDList returns identifiers of the matched objects.
440-
func (x SearchObjectsRes) IDList() []oid.ID {
441-
return x.ids
432+
x.fs = fs
442433
}
443434

444435
// SearchObjects selects objects from container which match the filters.
445436
//
446437
// Returns any error which prevented the operation from completing correctly in error return.
447-
func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) {
438+
func SearchObjects(prm SearchObjectsPrm) ([]oid.ID, error) {
439+
var opts client.SearchObjectsOptions
448440
if prm.local {
449-
prm.cliPrm.MarkLocal()
441+
opts.DisableForwarding()
450442
}
451443

452444
if prm.tokenSession != nil {
453-
prm.cliPrm.WithinSession(*prm.tokenSession)
445+
opts.WithSessionToken(*prm.tokenSession)
454446
}
455447

456448
if prm.tokenBearer != nil {
457-
prm.cliPrm.WithBearerToken(*prm.tokenBearer)
458-
}
459-
460-
prm.cliPrm.WithXHeaders(prm.xHeaders...)
461-
462-
rdr, err := prm.cli.ObjectSearchInit(prm.ctx, prm.cid, prm.signer, prm.cliPrm)
463-
if err != nil {
464-
return nil, fmt.Errorf("init object searching in client: %w", err)
449+
opts.WithBearerToken(*prm.tokenBearer)
465450
}
466451

467-
var ids []oid.ID
468-
469-
err = rdr.Iterate(func(id oid.ID) bool {
470-
ids = append(ids, id)
471-
return false
472-
})
473-
if err != nil {
474-
return nil, fmt.Errorf("search objects using NeoFS API: %w", err)
452+
opts.WithXHeaders(prm.xHeaders...)
453+
454+
var cursor string
455+
var next []client.SearchResultItem
456+
var res []oid.ID
457+
var err error
458+
for {
459+
next, cursor, err = prm.cli.SearchObjects(prm.ctx, prm.cid, prm.fs, nil, cursor, prm.signer, opts)
460+
if err != nil {
461+
return nil, fmt.Errorf("search objects RPC: %w", err)
462+
}
463+
res = slices.Grow(res, len(res)+len(next))
464+
for i := range next {
465+
res = append(res, next[i].ID)
466+
}
467+
if cursor == "" {
468+
return res, nil
469+
}
475470
}
476-
477-
return &SearchObjectsRes{
478-
ids: ids,
479-
}, nil
480471
}

pkg/services/object/search/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (c *clientWrapper) searchObjects(ctx context.Context, exec *execCtx, info c
105105
return nil, err
106106
}
107107

108-
return res.IDList(), nil
108+
return res, nil
109109
}
110110

111111
func (e *storageEngineWrapper) search(exec *execCtx) ([]oid.ID, error) {

0 commit comments

Comments
 (0)