forked from TrueCloudLab/frostfs-node
[#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:
parent
b9c22e21b1
commit
6bf7a00cfe
2 changed files with 26 additions and 4 deletions
|
@ -32,16 +32,24 @@ func (s *Shard) Open() error {
|
||||||
|
|
||||||
// Init initializes all Shard's components.
|
// Init initializes all Shard's components.
|
||||||
func (s *Shard) Init() error {
|
func (s *Shard) Init() error {
|
||||||
components := []interface{ Init() error }{
|
var fMetabase func() error
|
||||||
s.blobStor, s.metaBase,
|
|
||||||
|
if s.needRefillMetabase() {
|
||||||
|
fMetabase = s.refillMetabase
|
||||||
|
} else {
|
||||||
|
fMetabase = s.metaBase.Init
|
||||||
|
}
|
||||||
|
|
||||||
|
components := []func() error{
|
||||||
|
s.blobStor.Init, fMetabase,
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.hasWriteCache() {
|
if s.hasWriteCache() {
|
||||||
components = append(components, s.writeCache)
|
components = append(components, s.writeCache.Init)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, component := range components {
|
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)
|
return fmt.Errorf("could not initialize %T: %w", component, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ type Option func(*cfg)
|
||||||
type ExpiredObjectsCallback func(context.Context, []*object.Address)
|
type ExpiredObjectsCallback func(context.Context, []*object.Address)
|
||||||
|
|
||||||
type cfg struct {
|
type cfg struct {
|
||||||
|
refillMetabase bool
|
||||||
|
|
||||||
rmBatchSize int
|
rmBatchSize int
|
||||||
|
|
||||||
useWriteCache bool
|
useWriteCache bool
|
||||||
|
@ -139,6 +141,11 @@ func (s Shard) hasWriteCache() bool {
|
||||||
return s.cfg.useWriteCache
|
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
|
// WithRemoverBatchSize returns option to set batch size
|
||||||
// of single removal operation.
|
// of single removal operation.
|
||||||
func WithRemoverBatchSize(sz int) Option {
|
func WithRemoverBatchSize(sz int) Option {
|
||||||
|
@ -178,3 +185,10 @@ func WithExpiredObjectsCallback(cb ExpiredObjectsCallback) Option {
|
||||||
c.expiredTombstonesCallback = cb
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue