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