2020-12-10 12:26:40 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
2023-04-04 09:54:21 +00:00
|
|
|
"context"
|
2020-12-10 12:26:40 +00:00
|
|
|
"sync"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
2024-10-02 11:52:54 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
|
|
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/internal/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-12-10 12:26:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type uniqueIDWriter struct {
|
|
|
|
mtx sync.Mutex
|
|
|
|
|
2022-10-05 08:19:19 +00:00
|
|
|
written map[oid.ID]struct{}
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
writer IDListWriter
|
|
|
|
}
|
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
type clientConstructorWrapper struct {
|
|
|
|
constructor ClientConstructor
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type clientWrapper struct {
|
2022-01-13 15:01:50 +00:00
|
|
|
client client.MultiAddressClient
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 13:01:16 +00:00
|
|
|
type storageEngineWrapper struct {
|
|
|
|
storage *engine.StorageEngine
|
|
|
|
}
|
2020-12-10 12:26:40 +00:00
|
|
|
|
2023-08-24 18:55:36 +00:00
|
|
|
func newUniqueAddressWriter(w IDListWriter) *uniqueIDWriter {
|
|
|
|
if w, ok := w.(*uniqueIDWriter); ok {
|
|
|
|
return w
|
|
|
|
}
|
2020-12-10 12:26:40 +00:00
|
|
|
return &uniqueIDWriter{
|
2022-10-05 08:19:19 +00:00
|
|
|
written: make(map[oid.ID]struct{}),
|
2020-12-10 12:26:40 +00:00
|
|
|
writer: w,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (w *uniqueIDWriter) WriteIDs(list []oid.ID) error {
|
2020-12-10 12:26:40 +00:00
|
|
|
w.mtx.Lock()
|
|
|
|
|
|
|
|
for i := 0; i < len(list); i++ { // don't use range, slice mutates in body
|
2022-10-05 08:19:19 +00:00
|
|
|
if _, ok := w.written[list[i]]; !ok {
|
2020-12-10 12:26:40 +00:00
|
|
|
// mark address as processed
|
2022-10-05 08:19:19 +00:00
|
|
|
w.written[list[i]] = struct{}{}
|
2020-12-10 12:26:40 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// exclude processed address
|
|
|
|
list = append(list[:i], list[i+1:]...)
|
|
|
|
i--
|
|
|
|
}
|
|
|
|
|
|
|
|
w.mtx.Unlock()
|
|
|
|
|
|
|
|
return w.writer.WriteIDs(list)
|
|
|
|
}
|
|
|
|
|
2021-09-28 04:46:10 +00:00
|
|
|
func (c *clientConstructorWrapper) get(info client.NodeInfo) (searchClient, error) {
|
|
|
|
clt, err := c.constructor.Get(info)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
return &clientWrapper{
|
|
|
|
client: clt,
|
2021-09-28 04:46:10 +00:00
|
|
|
}, nil
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
func (c *clientWrapper) searchObjects(ctx context.Context, exec *execCtx, info client.NodeInfo) ([]oid.ID, error) {
|
2021-05-20 08:05:18 +00:00
|
|
|
if exec.prm.forwarder != nil {
|
2023-04-04 10:05:40 +00:00
|
|
|
return exec.prm.forwarder(ctx, info, c.client)
|
2021-05-20 08:05:18 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
var sessionInfo *util.SessionInfo
|
|
|
|
|
|
|
|
if tok := exec.prm.common.SessionToken(); tok != nil {
|
|
|
|
sessionInfo = &util.SessionInfo{
|
|
|
|
ID: tok.ID(),
|
2022-05-25 16:09:12 +00:00
|
|
|
Owner: tok.Issuer(),
|
2022-05-18 15:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
key, err := exec.svc.keyStore.GetKey(sessionInfo)
|
2021-10-26 12:07:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-11-01 08:35:33 +00:00
|
|
|
var prm internalclient.SearchObjectsPrm
|
|
|
|
|
|
|
|
prm.SetClient(c.client)
|
|
|
|
prm.SetPrivateKey(key)
|
|
|
|
prm.SetSessionToken(exec.prm.common.SessionToken())
|
|
|
|
prm.SetBearerToken(exec.prm.common.BearerToken())
|
|
|
|
prm.SetTTL(exec.prm.common.TTL())
|
|
|
|
prm.SetXHeaders(exec.prm.common.XHeaders())
|
|
|
|
prm.SetNetmapEpoch(exec.curProcEpoch)
|
|
|
|
prm.SetContainerID(exec.containerID())
|
|
|
|
prm.SetFilters(exec.searchFilters())
|
|
|
|
|
2023-04-06 12:36:37 +00:00
|
|
|
res, err := internalclient.SearchObjects(ctx, prm)
|
2021-11-01 08:35:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.IDList(), nil
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
func (e *storageEngineWrapper) search(ctx context.Context, exec *execCtx) ([]oid.ID, error) {
|
2024-10-02 11:52:54 +00:00
|
|
|
cnr, err := exec.getContainer()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-05-23 13:12:32 +00:00
|
|
|
var selectPrm engine.SelectPrm
|
|
|
|
selectPrm.WithFilters(exec.searchFilters())
|
2024-10-02 11:52:54 +00:00
|
|
|
selectPrm.WithContainerID(exec.containerID(), container.IsIndexedContainer(cnr))
|
2022-05-23 13:12:32 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
r, err := e.storage.Select(ctx, selectPrm)
|
2020-12-10 12:26:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return idsFromAddresses(r.AddressList()), nil
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func idsFromAddresses(addrs []oid.Address) []oid.ID {
|
|
|
|
ids := make([]oid.ID, len(addrs))
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
for i := range addrs {
|
2022-05-31 17:00:41 +00:00
|
|
|
ids[i] = addrs[i].Object()
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ids
|
|
|
|
}
|