2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
2020-11-17 17:39:43 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Shard represents single shard of NeoFS Local Storage Engine.
|
|
|
|
type Shard struct {
|
|
|
|
*cfg
|
|
|
|
|
|
|
|
mtx *sync.RWMutex
|
|
|
|
|
|
|
|
weight WeightValues
|
2020-11-17 17:39:43 +00:00
|
|
|
|
|
|
|
blobStor *blobstor.BlobStor
|
|
|
|
|
|
|
|
metaBase *meta.DB
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Option represents Shard's constructor option.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
id *ID
|
2020-11-17 17:39:43 +00:00
|
|
|
|
|
|
|
blobOpts []blobstor.Option
|
|
|
|
|
|
|
|
metaOpts []meta.Option
|
|
|
|
|
|
|
|
log *logger.Logger
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return new(cfg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns new Shard instance.
|
|
|
|
func New(opts ...Option) *Shard {
|
|
|
|
c := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](c)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Shard{
|
2020-11-17 17:39:43 +00:00
|
|
|
cfg: c,
|
|
|
|
mtx: new(sync.RWMutex),
|
|
|
|
blobStor: blobstor.New(c.blobOpts...),
|
|
|
|
metaBase: meta.NewDB(c.metaOpts...),
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithID returns option to set shard identifier.
|
|
|
|
func WithID(id *ID) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.id = id
|
|
|
|
}
|
|
|
|
}
|
2020-11-17 17:39:43 +00:00
|
|
|
|
|
|
|
// WithBlobStorOptions returns option to set internal BlobStor options.
|
|
|
|
func WithBlobStorOptions(opts []blobstor.Option) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.blobOpts = opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithMetaBaseOptions returns option to set internal metabase options.
|
|
|
|
func WithMetaBaseOptions(opts []meta.Option) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.metaOpts = opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithLogger returns option to set Shard's logger.
|
|
|
|
func WithLogger(l *logger.Logger) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = l
|
|
|
|
}
|
|
|
|
}
|