[#789] shard: Add option to refill metabase on initialization

Add `WithRefillMetabase` option constructor which allows to set flag to
refill metabase.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-09-13 16:56:07 +03:00 committed by Alex Vanin
parent b9c22e21b1
commit 6bf7a00cfe
2 changed files with 26 additions and 4 deletions

View file

@ -32,16 +32,24 @@ func (s *Shard) Open() error {
// Init initializes all Shard's components.
func (s *Shard) Init() error {
components := []interface{ Init() error }{
s.blobStor, s.metaBase,
var fMetabase func() error
if s.needRefillMetabase() {
fMetabase = s.refillMetabase
} else {
fMetabase = s.metaBase.Init
}
components := []func() error{
s.blobStor.Init, fMetabase,
}
if s.hasWriteCache() {
components = append(components, s.writeCache)
components = append(components, s.writeCache.Init)
}
for _, component := range components {
if err := component.Init(); err != nil {
if err := component(); err != nil {
return fmt.Errorf("could not initialize %T: %w", component, err)
}
}

View file

@ -36,6 +36,8 @@ type Option func(*cfg)
type ExpiredObjectsCallback func(context.Context, []*object.Address)
type cfg struct {
refillMetabase bool
rmBatchSize int
useWriteCache bool
@ -139,6 +141,11 @@ func (s Shard) hasWriteCache() bool {
return s.cfg.useWriteCache
}
// needRefillMetabase returns true if metabase is needed to be refilled.
func (s Shard) needRefillMetabase() bool {
return s.cfg.refillMetabase
}
// WithRemoverBatchSize returns option to set batch size
// of single removal operation.
func WithRemoverBatchSize(sz int) Option {
@ -178,3 +185,10 @@ func WithExpiredObjectsCallback(cb ExpiredObjectsCallback) Option {
c.expiredTombstonesCallback = cb
}
}
// WithRefillMetabase returns option to set flag to refill the Metabase on Shard's initialization step.
func WithRefillMetabase(v bool) Option {
return func(c *cfg) {
c.refillMetabase = v
}
}