2020-09-26 07:54:03 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
|
|
|
"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"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/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 {
|
|
|
|
*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 {
|
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
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-09-26 07:54:03 +00:00
|
|
|
func defaultCfg() *cfg {
|
2020-12-02 23:45:25 +00:00
|
|
|
return &cfg{
|
2022-09-28 07:41:01 +00:00
|
|
|
log: &logger.Logger{Logger: zap.L()},
|
2020-12-02 23:45:25 +00:00
|
|
|
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) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|