2020-10-21 11:49:02 +00:00
|
|
|
package replicator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine"
|
2024-08-30 09:09:14 +00:00
|
|
|
objectwriter "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/common/writer"
|
2024-05-14 11:43:21 +00:00
|
|
|
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2020-10-21 11:49:02 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Replicator represents the utility that replicates
|
|
|
|
// local objects to remote nodes.
|
|
|
|
type Replicator struct {
|
|
|
|
*cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
// Option is an option for Policer constructor.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
putTimeout time.Duration
|
|
|
|
|
|
|
|
log *logger.Logger
|
|
|
|
|
2024-08-30 09:09:14 +00:00
|
|
|
remoteSender *objectwriter.RemoteSender
|
2020-10-21 11:49:02 +00:00
|
|
|
|
2024-05-14 11:43:21 +00:00
|
|
|
remoteGetter *getsvc.RemoteGetter
|
|
|
|
|
2020-11-19 08:21:58 +00:00
|
|
|
localStorage *engine.StorageEngine
|
2023-05-12 08:44:21 +00:00
|
|
|
|
|
|
|
metrics MetricsRegister
|
2020-10-21 11:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns Replicator instance.
|
|
|
|
func New(opts ...Option) *Replicator {
|
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
2024-10-21 07:22:54 +00:00
|
|
|
c.log = c.log.With(zap.String("component", "Object Replicator"))
|
2020-10-21 11:49:02 +00:00
|
|
|
|
|
|
|
return &Replicator{
|
|
|
|
cfg: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithPutTimeout returns option to set Put timeout of Replicator.
|
|
|
|
func WithPutTimeout(v time.Duration) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.putTimeout = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithLogger returns option to set Logger of Replicator.
|
|
|
|
func WithLogger(v *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithRemoteSender returns option to set remote object sender of Replicator.
|
2024-08-30 09:09:14 +00:00
|
|
|
func WithRemoteSender(v *objectwriter.RemoteSender) Option {
|
2020-10-21 11:49:02 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.remoteSender = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-14 11:43:21 +00:00
|
|
|
func WithRemoteGetter(v *getsvc.RemoteGetter) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.remoteGetter = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 11:49:02 +00:00
|
|
|
// WithLocalStorage returns option to set local object storage of Replicator.
|
2020-11-19 08:21:58 +00:00
|
|
|
func WithLocalStorage(v *engine.StorageEngine) Option {
|
2020-10-21 11:49:02 +00:00
|
|
|
return func(c *cfg) {
|
|
|
|
c.localStorage = v
|
|
|
|
}
|
|
|
|
}
|
2023-05-12 08:44:21 +00:00
|
|
|
|
|
|
|
func WithMetrics(v MetricsRegister) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.metrics = v
|
|
|
|
}
|
|
|
|
}
|