Skip to content

Commit 1ac26db

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

File tree

5 files changed

+134
-123
lines changed

5 files changed

+134
-123
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Changelog for NeoFS Node
4848
- Storage Nodes do not accept REPLICATE with a header that exceeds the limit (#3297)
4949
- Search API is served from SearchV2 indexes now (#3316)
5050
- Blobstor can be of exactly one type, with no substorages (#3330)
51+
- SN uses SearchV2 to verify tombstones (#3312)
5152

5253
### Removed
5354
- SN `apiclient.allow_external` config (#3235)

cmd/neofs-node/object.go

+29-22
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ import (
4040
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
4141
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
4242
protoobject "github.com/nspcc-dev/neofs-sdk-go/proto/object"
43+
protosession "github.com/nspcc-dev/neofs-sdk-go/proto/session"
4344
apireputation "github.com/nspcc-dev/neofs-sdk-go/reputation"
4445
"github.com/nspcc-dev/neofs-sdk-go/user"
46+
"github.com/nspcc-dev/neofs-sdk-go/version"
4547
"go.uber.org/zap"
4648
)
4749

@@ -244,6 +246,7 @@ func initObjectService(c *cfg) {
244246
mNumber, err := c.shared.basics.cli.MagicNumber()
245247
fatalOnErr(err)
246248

249+
os := &objectSource{get: sGet}
247250
sPut := putsvc.NewService(&transport{clients: putConstructor}, c,
248251
putsvc.WithNetworkMagic(mNumber),
249252
putsvc.WithKeyStorage(keyStorage),
@@ -257,7 +260,7 @@ func initObjectService(c *cfg) {
257260
putsvc.WithWorkerPools(c.cfgObject.pool.putRemote, c.cfgObject.pool.putLocal),
258261
putsvc.WithLogger(c.log),
259262
putsvc.WithSplitChainVerifier(split.NewVerifier(sGet)),
260-
putsvc.WithTombstoneVerifier(tombstone.NewVerifier(objectSource{sGet, sSearch})),
263+
putsvc.WithTombstoneVerifier(tombstone.NewVerifier(os)),
261264
)
262265

263266
sDelete := deletesvc.New(
@@ -314,6 +317,7 @@ func initObjectService(c *cfg) {
314317
keys: keyStorage,
315318
}
316319
server := objectService.New(objSvc, mNumber, fsChain, storage, c.metaService, c.shared.basics.key.PrivateKey, c.metricsCollector, aclChecker, aclSvc, coreConstructor)
320+
os.server = server
317321

318322
for _, srv := range c.cfgGRPC.servers {
319323
protoobject.RegisterObjectServiceServer(srv, server)
@@ -639,16 +643,9 @@ func (x storageForObjectService) GetSessionPrivateKey(usr user.ID, uid uuid.UUID
639643

640644
type objectSource struct {
641645
get *getsvc.Service
642-
search *searchsvc.Service
643-
}
644-
645-
type searchWriter struct {
646-
ids []oid.ID
647-
}
648-
649-
func (w *searchWriter) WriteIDs(ids []oid.ID) error {
650-
w.ids = append(w.ids, ids...)
651-
return nil
646+
server interface {
647+
ProcessSearch(ctx context.Context, req *protoobject.SearchV2Request) ([]client.SearchResultItem, []byte, error)
648+
}
652649
}
653650

654651
func (o objectSource) Head(ctx context.Context, addr oid.Address) (*objectSDK.Object, error) {
@@ -664,20 +661,30 @@ func (o objectSource) Head(ctx context.Context, addr oid.Address) (*objectSDK.Ob
664661
return hw.h, err
665662
}
666663

667-
func (o objectSource) Search(ctx context.Context, cnr cid.ID, filters objectSDK.SearchFilters) ([]oid.ID, error) {
668-
var sw searchWriter
669-
670-
var sPrm searchsvc.Prm
671-
sPrm.SetWriter(&sw)
672-
sPrm.WithSearchFilters(filters)
673-
sPrm.WithContainerID(cnr)
674-
675-
err := o.search.Search(ctx, sPrm)
664+
func (o objectSource) SearchOne(ctx context.Context, cnr cid.ID, filters objectSDK.SearchFilters) (oid.ID, error) {
665+
var id oid.ID
666+
res, _, err := o.server.ProcessSearch(ctx, &protoobject.SearchV2Request{
667+
Body: &protoobject.SearchV2Request_Body{
668+
ContainerId: cnr.ProtoMessage(),
669+
Version: 1,
670+
Filters: filters.ProtoMessage(),
671+
Cursor: "",
672+
Count: 1,
673+
Attributes: nil,
674+
},
675+
MetaHeader: &protosession.RequestMetaHeader{
676+
Version: version.Current().ProtoMessage(),
677+
Ttl: 2,
678+
},
679+
})
676680
if err != nil {
677-
return nil, err
681+
return id, err
678682
}
679683

680-
return sw.ids, nil
684+
if len(res) == 1 {
685+
return res[0].ID, nil
686+
}
687+
return id, nil
681688
}
682689

683690
// IsLocalNodePublicKey checks whether given binary-encoded public key is

0 commit comments

Comments
 (0)