2020-09-26 07:54:03 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
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"
|
|
|
|
"github.com/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "github.com/TrueCloudLab/frostfs-sdk-go/object/id"
|
2020-12-02 23:45:25 +00:00
|
|
|
"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 {
|
2022-12-30 11:19:42 +00:00
|
|
|
cfg
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2022-03-03 14:19:05 +00:00
|
|
|
getObject(*execCtx, client.NodeInfo) (*object.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-09-28 04:46:10 +00:00
|
|
|
get(client.NodeInfo) (getClient, error)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
traverserGenerator interface {
|
2022-05-31 17:00:41 +00:00
|
|
|
GenerateTraverser(cid.ID, *oid.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-26 07:54:03 +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.localStorage = new(storageEngineWrapper)
|
|
|
|
c.assembly = true
|
|
|
|
c.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 {
|
2022-12-30 11:19:42 +00:00
|
|
|
var s Service
|
|
|
|
s.cfg.initDefault()
|
2020-09-26 07:54:03 +00:00
|
|
|
|
|
|
|
for i := range opts {
|
2022-12-30 11:19:42 +00:00
|
|
|
opts[i](&s.cfg)
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 11:19:42 +00:00
|
|
|
return &s
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2022-09-28 07:41:01 +00:00
|
|
|
c.log = &logger.Logger{Logger: l.With(zap.String("component", "Object.Get service"))}
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2022-01-13 15:01:50 +00:00
|
|
|
Get(client.NodeInfo) (client.MultiAddressClient, 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) {
|
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
|
|
|
|
}
|
|
|
|
}
|