2020-09-26 07:54:03 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
2021-03-23 18:40:36 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
2020-12-02 23:45:25 +00:00
|
|
|
objectSDK "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-12-02 23:45:25 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
|
|
"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-02 23:45:25 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
|
|
|
"go.uber.org/zap"
|
2020-09-26 07:54:03 +00:00
|
|
|
)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
// Service utility serving requests of Object.Get service.
|
2020-09-26 07:54:03 +00:00
|
|
|
type Service struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
// Option is a Service's constructor option.
|
2020-09-26 07:54:03 +00:00
|
|
|
type Option func(*cfg)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
type getClient interface {
|
2020-12-09 10:32:33 +00:00
|
|
|
getObject(*execCtx) (*objectSDK.Object, error)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-26 07:54:03 +00:00
|
|
|
type cfg struct {
|
2020-12-02 23:45:25 +00:00
|
|
|
assembly bool
|
|
|
|
|
|
|
|
log *logger.Logger
|
|
|
|
|
|
|
|
localStorage interface {
|
2020-12-09 10:32:33 +00:00
|
|
|
get(*execCtx) (*object.Object, error)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clientCache interface {
|
2021-05-20 15:17:16 +00:00
|
|
|
get(*network.Address) (getClient, error)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
traverserGenerator interface {
|
2021-01-12 14:55:02 +00:00
|
|
|
GenerateTraverser(*objectSDK.Address, uint64) (*placement.Traverser, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
currentEpochReceiver interface {
|
|
|
|
currentEpoch() (uint64, error)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
2020-12-02 23:45:25 +00:00
|
|
|
return &cfg{
|
|
|
|
assembly: true,
|
|
|
|
log: zap.L(),
|
|
|
|
localStorage: new(storageEngineWrapper),
|
|
|
|
clientCache: new(clientCacheWrapper),
|
|
|
|
}
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
// New creates, initializes and returns utility serving
|
|
|
|
// Object.Get service requests.
|
|
|
|
func New(opts ...Option) *Service {
|
2020-09-26 07:54:03 +00:00
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Service{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
// WithLogger returns option to specify Get service's logger.
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = l.With(zap.String("component", "Object.Get service"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithoutAssembly returns option to disable object assembling.
|
|
|
|
func WithoutAssembly() Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.assembly = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithLocalStorageEngine returns option to set local storage
|
|
|
|
// instance.
|
|
|
|
func WithLocalStorageEngine(e *engine.StorageEngine) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.localStorage.(*storageEngineWrapper).engine = e
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// WithClientConstructor returns option to set constructor of remote node clients.
|
|
|
|
func WithClientConstructor(v ClientConstructor) Option {
|
2020-12-02 23:45:25 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.clientCache.(*clientCacheWrapper).cache = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithTraverserGenerator returns option to set generator of
|
|
|
|
// placement traverser to get the objects from containers.
|
|
|
|
func WithTraverserGenerator(t *util.TraverserGenerator) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.traverserGenerator = t
|
|
|
|
}
|
2020-09-26 07:54:03 +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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|