2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
2021-03-23 18:40:36 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
2021-05-31 11:03:17 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
2020-09-22 06:51:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2021-01-12 14:55:02 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
2020-11-19 08:24:02 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
|
2021-05-20 15:17:16 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/network"
|
2020-12-10 12:26:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
2020-11-23 11:25:57 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
|
|
|
"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 {
|
|
|
|
searchObjects(*execCtx) ([]*object.ID, error)
|
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
type ClientConstructor interface {
|
2021-05-20 15:17:16 +00:00
|
|
|
Get(*network.Address) (client.Client, 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 {
|
|
|
|
search(*execCtx) ([]*object.ID, error)
|
|
|
|
}
|
2020-11-23 11:25:57 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
clientConstructor interface {
|
2021-05-20 15:17:16 +00:00
|
|
|
get(*network.Address) (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 {
|
2021-05-31 11:03:17 +00:00
|
|
|
generateTraverser(*cid.ID, uint64) (*placement.Traverser, error)
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
currentEpochReceiver interface {
|
|
|
|
currentEpoch() (uint64, error)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{
|
2021-03-23 18:40:36 +00:00
|
|
|
log: zap.L(),
|
|
|
|
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 {
|
2020-09-22 06:51:47 +00:00
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
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) {
|
2020-12-10 12:26:40 +00:00
|
|
|
c.log = l.With(zap.String("component", "Object.Get 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.
|
|
|
|
func WithLocalStorageEngine(e *engine.StorageEngine) Option {
|
2020-09-22 06:51:47 +00:00
|
|
|
return func(c *cfg) {
|
2020-12-10 12:26:40 +00:00
|
|
|
c.localStorage = (*storageEngineWrapper)(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) {
|
|
|
|
c.currentEpochReceiver = &nmSrcWrapper{
|
|
|
|
nmSrc: nmSrc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|