2020-09-21 14:31:31 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
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/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
objutil "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2020-11-23 11:22:32 +00:00
|
|
|
"go.uber.org/zap"
|
2020-09-21 14:31:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MaxSizeSource interface {
|
2020-10-22 14:20:59 +00:00
|
|
|
// MaxObjectSize returns maximum payload size
|
|
|
|
// of physically stored object in system.
|
|
|
|
//
|
|
|
|
// Must return 0 if value can not be obtained.
|
2020-09-21 14:31:31 +00:00
|
|
|
MaxObjectSize() uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
type Service struct {
|
2022-12-30 11:19:42 +00:00
|
|
|
cfg
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
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-09-21 14:31:31 +00:00
|
|
|
type cfg struct {
|
2020-09-29 16:44:59 +00:00
|
|
|
keyStorage *objutil.KeyStorage
|
2020-09-21 14:31:31 +00:00
|
|
|
|
|
|
|
maxSizeSrc MaxSizeSource
|
|
|
|
|
2022-03-15 19:40:31 +00:00
|
|
|
localStore ObjectStorage
|
2020-09-21 14:31:31 +00:00
|
|
|
|
|
|
|
cnrSrc container.Source
|
|
|
|
|
|
|
|
netMapSrc netmap.Source
|
|
|
|
|
2021-09-24 10:36:54 +00:00
|
|
|
remotePool, localPool util.WorkerPool
|
2020-09-21 14:31:31 +00:00
|
|
|
|
2021-09-06 12:17:14 +00:00
|
|
|
netmapKeys netmap.AnnouncedKeys
|
2020-09-29 12:38:35 +00:00
|
|
|
|
|
|
|
fmtValidator *object.FormatValidator
|
2020-10-03 10:14:09 +00:00
|
|
|
|
|
|
|
fmtValidatorOpts []object.FormatValidatorOption
|
2020-10-21 15:11:50 +00:00
|
|
|
|
|
|
|
networkState netmap.State
|
2020-11-18 13:03:31 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
clientConstructor ClientConstructor
|
2020-11-23 11:22:32 +00:00
|
|
|
|
|
|
|
log *logger.Logger
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 11:19:42 +00:00
|
|
|
func (c *cfg) initDefault() {
|
|
|
|
c.remotePool = util.NewPseudoWorkerPool()
|
|
|
|
c.localPool = util.NewPseudoWorkerPool()
|
|
|
|
c.log = &logger.Logger{Logger: zap.L()}
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewService(opts ...Option) *Service {
|
2022-12-30 11:19:42 +00:00
|
|
|
var s Service
|
|
|
|
s.cfg.initDefault()
|
2020-09-21 14:31:31 +00:00
|
|
|
|
|
|
|
for i := range opts {
|
2022-12-30 11:19:42 +00:00
|
|
|
opts[i](&s.cfg)
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 11:19:42 +00:00
|
|
|
s.cfg.fmtValidator = object.NewFormatValidator(s.cfg.fmtValidatorOpts...)
|
2020-10-03 10:14:09 +00:00
|
|
|
|
2022-12-30 11:19:42 +00:00
|
|
|
return &s
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Service) Put(ctx context.Context) (*Streamer, error) {
|
|
|
|
return &Streamer{
|
2022-12-30 11:19:42 +00:00
|
|
|
cfg: &p.cfg,
|
2020-09-21 14:31:31 +00:00
|
|
|
ctx: ctx,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-09-29 16:44:59 +00:00
|
|
|
func WithKeyStorage(v *objutil.KeyStorage) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
2020-09-29 16:44:59 +00:00
|
|
|
c.keyStorage = v
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithMaxSizeSource(v MaxSizeSource) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.maxSizeSrc = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-15 19:40:31 +00:00
|
|
|
func WithObjectStorage(v ObjectStorage) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.localStore = v
|
2023-03-15 01:07:27 +00:00
|
|
|
c.fmtValidatorOpts = append(c.fmtValidatorOpts, object.WithLockSource(v))
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithContainerSource(v container.Source) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.cnrSrc = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithNetworkMapSource(v netmap.Source) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.netMapSrc = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-22 08:31:50 +00:00
|
|
|
func WithWorkerPools(remote, local util.WorkerPool) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
2023-02-22 08:31:50 +00:00
|
|
|
c.remotePool, c.localPool = remote, local
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-06 12:17:14 +00:00
|
|
|
func WithNetmapKeys(v netmap.AnnouncedKeys) Option {
|
2020-09-21 14:31:31 +00:00
|
|
|
return func(c *cfg) {
|
2021-09-06 12:17:14 +00:00
|
|
|
c.netmapKeys = v
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-03 10:14:09 +00:00
|
|
|
|
2020-10-21 15:11:50 +00:00
|
|
|
func WithNetworkState(v netmap.State) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.networkState = v
|
2021-02-15 08:28:42 +00:00
|
|
|
c.fmtValidatorOpts = append(c.fmtValidatorOpts, object.WithNetState(v))
|
2020-10-21 15:11:50 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-18 13:03:31 +00:00
|
|
|
|
2021-03-23 18:40:36 +00:00
|
|
|
func WithClientConstructor(v ClientConstructor) Option {
|
2020-11-18 13:03:31 +00:00
|
|
|
return func(c *cfg) {
|
2021-03-23 18:40:36 +00:00
|
|
|
c.clientConstructor = v
|
2020-11-18 13:03:31 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 11:22:32 +00:00
|
|
|
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = l
|
|
|
|
}
|
|
|
|
}
|