From 6bf7a00cfe8fd2298d3c39f5d93a4f5a3036f869 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 13 Sep 2021 16:56:07 +0300 Subject: [PATCH] [#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 --- pkg/local_object_storage/shard/control.go | 16 ++++++++++++---- pkg/local_object_storage/shard/shard.go | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index f5326a15..450afb47 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -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) } } diff --git a/pkg/local_object_storage/shard/shard.go b/pkg/local_object_storage/shard/shard.go index 0f470728..b851cca1 100644 --- a/pkg/local_object_storage/shard/shard.go +++ b/pkg/local_object_storage/shard/shard.go @@ -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 + } +}