2020-12-10 12:26:40 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/client"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
|
|
internalclient "github.com/TrueCloudLab/frostfs-node/pkg/services/object/internal/client"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement"
|
|
|
|
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
oid "github.com/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
|
|
|
|
|
|
|
type traverseGeneratorWrapper util.TraverserGenerator
|
|
|
|
|
|
|
|
func newUniqueAddressWriter(w IDListWriter) IDListWriter {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (c *clientWrapper) searchObjects(exec *execCtx, info client.NodeInfo) ([]oid.ID, error) {
|
2021-05-20 08:05:18 +00:00
|
|
|
if exec.prm.forwarder != nil {
|
2021-09-28 04:46:10 +00:00
|
|
|
return exec.prm.forwarder(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
|
|
|
|
|
2022-12-30 11:00:01 +00:00
|
|
|
prm.SetContext(exec.ctx)
|
2021-11-01 08:35:33 +00:00
|
|
|
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)
|
2022-12-30 11:00:01 +00:00
|
|
|
prm.SetContainerID(exec.prm.cnr)
|
|
|
|
prm.SetFilters(exec.prm.filters)
|
2021-11-01 08:35:33 +00:00
|
|
|
|
|
|
|
res, err := internalclient.SearchObjects(prm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.IDList(), nil
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (e *storageEngineWrapper) search(exec *execCtx) ([]oid.ID, error) {
|
2022-05-23 13:12:32 +00:00
|
|
|
var selectPrm engine.SelectPrm
|
2022-12-30 11:00:01 +00:00
|
|
|
selectPrm.WithFilters(exec.prm.filters)
|
|
|
|
selectPrm.WithContainerID(exec.prm.cnr)
|
2022-05-23 13:12:32 +00:00
|
|
|
|
2022-10-04 13:01:16 +00:00
|
|
|
r, err := e.storage.Select(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
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (e *traverseGeneratorWrapper) generateTraverser(cnr cid.ID, epoch uint64) (*placement.Traverser, error) {
|
|
|
|
return (*util.TraverserGenerator)(e).GenerateTraverser(cnr, nil, epoch)
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|