2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
2023-04-04 09:54:21 +00:00
|
|
|
"context"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
2024-07-15 15:03:43 +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/core/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-11-23 11:25:57 +00:00
|
|
|
"go.uber.org/zap"
|
2020-09-22 06:51:47 +00:00
|
|
|
)
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// Service is an utility serving requests
|
|
|
|
// of Object.Search service.
|
2020-09-22 06:51:47 +00:00
|
|
|
type Service struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// Option is a Service's constructor option.
|
2020-09-22 06:51:47 +00:00
|
|
|
type Option func(*cfg)
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
type searchClient interface {
|
2022-10-05 08:09:53 +00:00
|
|
|
// searchObjects searches objects on the specified node.
|
|
|
|
// MUST NOT modify execCtx as it can be accessed concurrently.
|
2023-04-04 09:54:21 +00:00
|
|
|
searchObjects(context.Context, *execCtx, client.NodeInfo) ([]oid.ID, error)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
type ClientConstructor interface {
|
2022-01-13 15:01:50 +00:00
|
|
|
Get(client.NodeInfo) (client.MultiAddressClient, error)
|
2021-03-23 18:40:36 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
type cfg struct {
|
|
|
|
log *logger.Logger
|
2020-11-18 13:04:09 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
localStorage interface {
|
2023-04-12 14:01:29 +00:00
|
|
|
search(context.Context, *execCtx) ([]oid.ID, error)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2020-11-23 11:25:57 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
clientConstructor interface {
|
2021-09-28 04:46:10 +00:00
|
|
|
get(client.NodeInfo) (searchClient, error)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2020-11-23 12:59:06 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
traverserGenerator interface {
|
2024-07-15 15:03:43 +00:00
|
|
|
GenerateTraverser(cid.ID, *oid.ID, uint64) (*placement.Traverser, *container.Container, error)
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
currentEpochReceiver interface {
|
2023-08-24 17:54:29 +00:00
|
|
|
Epoch() (uint64, error)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2021-10-26 13:02:46 +00:00
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
keyStore *util.KeyStorage
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// New creates, initializes and returns utility serving
|
|
|
|
// Object.Get service requests.
|
2023-07-06 09:53:37 +00:00
|
|
|
func New(e *engine.StorageEngine,
|
|
|
|
cc ClientConstructor,
|
|
|
|
tg *util.TraverserGenerator,
|
|
|
|
ns netmap.Source,
|
|
|
|
ks *util.KeyStorage,
|
2023-10-31 11:56:55 +00:00
|
|
|
opts ...Option,
|
|
|
|
) *Service {
|
2023-07-06 09:53:37 +00:00
|
|
|
c := &cfg{
|
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
|
|
|
clientConstructor: &clientConstructorWrapper{
|
|
|
|
constructor: cc,
|
|
|
|
},
|
|
|
|
localStorage: &storageEngineWrapper{
|
|
|
|
storage: e,
|
|
|
|
},
|
2023-08-24 17:57:53 +00:00
|
|
|
traverserGenerator: tg,
|
2023-08-24 17:54:29 +00:00
|
|
|
currentEpochReceiver: ns,
|
|
|
|
keyStore: ks,
|
2023-07-06 09:53:37 +00:00
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Service{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// WithLogger returns option to specify Get service's logger.
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
2020-09-22 06:51:47 +00:00
|
|
|
return func(c *cfg) {
|
2022-09-28 07:41:01 +00:00
|
|
|
c.log = &logger.Logger{Logger: l.With(zap.String("component", "Object.Search service"))}
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
}
|