2020-11-17 12:26:03 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
2021-10-08 12:25:45 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util"
|
2020-11-17 12:26:03 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// StorageEngine represents NeoFS local storage engine.
|
|
|
|
type StorageEngine struct {
|
|
|
|
*cfg
|
|
|
|
|
|
|
|
mtx *sync.RWMutex
|
|
|
|
|
|
|
|
shards map[string]*shard.Shard
|
2021-10-08 12:25:45 +00:00
|
|
|
|
|
|
|
shardPools map[string]util.WorkerPool
|
2021-11-09 15:46:12 +00:00
|
|
|
|
|
|
|
blockExec struct {
|
|
|
|
mtx sync.RWMutex
|
|
|
|
|
|
|
|
err error
|
|
|
|
}
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Option represents StorageEngine's constructor option.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
log *logger.Logger
|
2021-03-15 13:09:27 +00:00
|
|
|
|
2021-03-16 08:14:56 +00:00
|
|
|
metrics MetricRegister
|
2021-10-08 12:25:45 +00:00
|
|
|
|
|
|
|
shardPoolSize uint32
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return &cfg{
|
|
|
|
log: zap.L(),
|
2021-10-08 12:25:45 +00:00
|
|
|
|
|
|
|
shardPoolSize: 20,
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns new StorageEngine instance.
|
|
|
|
func New(opts ...Option) *StorageEngine {
|
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &StorageEngine{
|
2021-10-08 12:25:45 +00:00
|
|
|
cfg: c,
|
|
|
|
mtx: new(sync.RWMutex),
|
|
|
|
shards: make(map[string]*shard.Shard),
|
|
|
|
shardPools: make(map[string]util.WorkerPool),
|
2020-11-17 12:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithLogger returns option to set StorageEngine's logger.
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = l
|
|
|
|
}
|
|
|
|
}
|
2021-03-15 13:09:27 +00:00
|
|
|
|
2021-03-16 08:14:56 +00:00
|
|
|
func WithMetrics(v MetricRegister) Option {
|
2021-03-15 13:09:27 +00:00
|
|
|
return func(c *cfg) {
|
2021-03-16 08:14:56 +00:00
|
|
|
c.metrics = v
|
2021-03-15 13:09:27 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-08 12:25:45 +00:00
|
|
|
|
|
|
|
// WithShardPoolSize returns option to specify size of worker pool for each shard.
|
|
|
|
func WithShardPoolSize(sz uint32) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.shardPoolSize = sz
|
|
|
|
}
|
|
|
|
}
|