2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/client"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
|
|
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
oid "github.com/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 {
|
2022-12-30 11:19:42 +00:00
|
|
|
cfg
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2022-05-31 17:00:41 +00:00
|
|
|
searchObjects(*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 {
|
2022-05-31 17:00:41 +00:00
|
|
|
search(*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 {
|
2022-05-31 17:00:41 +00:00
|
|
|
generateTraverser(cid.ID, uint64) (*placement.Traverser, error)
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 11:06:47 +00:00
|
|
|
epochSource epochSource
|
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
|
|
|
}
|
|
|
|
|
2022-12-30 11:06:47 +00:00
|
|
|
type epochSource interface {
|
|
|
|
Epoch() (uint64, error)
|
|
|
|
}
|
|
|
|
|
2022-12-30 11:19:42 +00:00
|
|
|
func (c *cfg) initDefault() {
|
|
|
|
c.log = &logger.Logger{Logger: zap.L()}
|
|
|
|
c.clientConstructor = new(clientConstructorWrapper)
|
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.
|
|
|
|
func New(opts ...Option) *Service {
|
2022-12-30 11:19:42 +00:00
|
|
|
var s Service
|
|
|
|
s.cfg.initDefault()
|
2020-09-22 06:51:47 +00:00
|
|
|
|
|
|
|
for i := range opts {
|
2022-12-30 11:19:42 +00:00
|
|
|
opts[i](&s.cfg)
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 11:19:42 +00:00
|
|
|
return &s
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// WithLocalStorageEngine returns option to set local storage
|
|
|
|
// instance.
|
2022-10-14 09:35:19 +00:00
|
|
|
func WithLocalStorageEngine(e *engine.StorageEngine) Option {
|
2020-09-22 06:51:47 +00:00
|
|
|
return func(c *cfg) {
|
2022-10-04 13:01:16 +00:00
|
|
|
c.localStorage = &storageEngineWrapper{
|
|
|
|
storage: e,
|
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-18 13:04:09 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
// WithClientConstructor returns option to set constructor of remote node clients.
|
|
|
|
func WithClientConstructor(v ClientConstructor) Option {
|
2020-11-18 13:04:09 +00:00
|
|
|
return func(c *cfg) {
|
2021-03-23 18:40:36 +00:00
|
|
|
c.clientConstructor.(*clientConstructorWrapper).constructor = v
|
2020-11-18 13:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 11:25:57 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// WithTraverserGenerator returns option to set generator of
|
|
|
|
// placement traverser to get the objects from containers.
|
|
|
|
func WithTraverserGenerator(t *util.TraverserGenerator) Option {
|
2020-11-23 12:59:06 +00:00
|
|
|
return func(c *cfg) {
|
2020-12-10 12:26:40 +00:00
|
|
|
c.traverserGenerator = (*traverseGeneratorWrapper)(t)
|
2020-11-23 12:59:06 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
// WithNetMapSource returns option to set network
|
|
|
|
// map storage to receive current network state.
|
|
|
|
func WithNetMapSource(nmSrc netmap.Source) Option {
|
|
|
|
return func(c *cfg) {
|
2022-12-30 11:06:47 +00:00
|
|
|
c.epochSource = nmSrc
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-26 13:02:46 +00:00
|
|
|
|
|
|
|
// WithKeyStorage returns option to set private
|
|
|
|
// key storage for session tokens and node key.
|
|
|
|
func WithKeyStorage(store *util.KeyStorage) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.keyStore = store
|
|
|
|
}
|
|
|
|
}
|