2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
2023-04-04 10:05:40 +00:00
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-04-29 08:54:40 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
|
|
|
|
objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
|
|
|
|
searchsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
2024-11-07 14:32:10 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-09-22 06:51:47 +00:00
|
|
|
)
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStream) (*searchsvc.Prm, error) {
|
2022-05-12 16:37:46 +00:00
|
|
|
body := req.GetBody()
|
|
|
|
|
|
|
|
cnrV2 := body.GetContainerID()
|
|
|
|
if cnrV2 == nil {
|
|
|
|
return nil, errors.New("missing container ID")
|
|
|
|
}
|
|
|
|
|
|
|
|
var id cid.ID
|
|
|
|
|
|
|
|
err := id.ReadFromV2(*cnrV2)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid container ID: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
commonPrm, err := util.CommonPrmFromV2(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
p := new(searchsvc.Prm)
|
2021-10-26 13:02:46 +00:00
|
|
|
p.SetCommonParameters(commonPrm)
|
2020-12-11 11:59:16 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
p.SetWriter(&streamWriter{
|
|
|
|
stream: stream,
|
|
|
|
})
|
|
|
|
|
2021-04-29 08:54:40 +00:00
|
|
|
if !commonPrm.LocalOnly() {
|
2021-10-26 12:07:28 +00:00
|
|
|
key, err := s.keyStorage.GetKey(nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-04-04 10:05:40 +00:00
|
|
|
forwarder := &requestForwarder{
|
2023-05-30 07:14:37 +00:00
|
|
|
Request: req,
|
|
|
|
Key: key,
|
2023-04-04 10:05:40 +00:00
|
|
|
}
|
2021-04-29 08:54:40 +00:00
|
|
|
|
2023-04-04 10:05:40 +00:00
|
|
|
p.SetRequestForwarder(groupAddressRequestForwarder(forwarder.forwardRequest))
|
2021-04-29 08:54:40 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
p.WithContainerID(id)
|
2023-07-06 12:36:41 +00:00
|
|
|
p.WithSearchFilters(objectSDK.NewSearchFiltersFromV2(body.GetFilters()))
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
return p, nil
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
2021-06-22 12:19:30 +00:00
|
|
|
|
2023-04-04 10:05:40 +00:00
|
|
|
func groupAddressRequestForwarder(f func(context.Context, network.Address, client.MultiAddressClient, []byte) ([]oid.ID, error)) searchsvc.RequestForwarder {
|
|
|
|
return func(ctx context.Context, info client.NodeInfo, c client.MultiAddressClient) ([]oid.ID, error) {
|
2021-06-22 12:19:30 +00:00
|
|
|
var (
|
|
|
|
firstErr error
|
2022-05-31 17:00:41 +00:00
|
|
|
res []oid.ID
|
2021-09-28 06:02:02 +00:00
|
|
|
|
|
|
|
key = info.PublicKey()
|
2021-06-22 12:19:30 +00:00
|
|
|
)
|
|
|
|
|
2021-09-28 04:46:10 +00:00
|
|
|
info.AddressGroup().IterateAddresses(func(addr network.Address) (stop bool) {
|
2021-06-22 12:19:30 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
stop = err == nil
|
|
|
|
|
|
|
|
if stop || firstErr == nil {
|
|
|
|
firstErr = err
|
|
|
|
}
|
|
|
|
|
|
|
|
// would be nice to log otherwise
|
|
|
|
}()
|
|
|
|
|
2023-04-04 10:05:40 +00:00
|
|
|
res, err = f(ctx, addr, c, key)
|
2021-06-22 12:19:30 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
})
|
|
|
|
|
|
|
|
return res, firstErr
|
|
|
|
}
|
|
|
|
}
|