[#826] blobovniczatree: Do not create DB's on init

Blobovniczas will be created on write requests.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-11-27 16:01:48 +03:00
parent ad0697adc4
commit db49ad16cc
9 changed files with 46 additions and 18 deletions

View file

@ -183,6 +183,7 @@ type subStorageCfg struct {
leafWidth uint64 leafWidth uint64
openedCacheSize int openedCacheSize int
initWorkerCount int initWorkerCount int
initInAdvance bool
} }
// readConfig fills applicationConfiguration with raw configuration values // readConfig fills applicationConfiguration with raw configuration values
@ -302,6 +303,7 @@ func (a *applicationConfiguration) setShardStorageConfig(newConfig *shardCfg, ol
sCfg.leafWidth = sub.LeafWidth() sCfg.leafWidth = sub.LeafWidth()
sCfg.openedCacheSize = sub.OpenedCacheSize() sCfg.openedCacheSize = sub.OpenedCacheSize()
sCfg.initWorkerCount = sub.InitWorkerCount() sCfg.initWorkerCount = sub.InitWorkerCount()
sCfg.initInAdvance = sub.InitInAdvance()
case fstree.Type: case fstree.Type:
sub := fstreeconfig.From((*config.Config)(storagesCfg[i])) sub := fstreeconfig.From((*config.Config)(storagesCfg[i]))
sCfg.depth = sub.Depth() sCfg.depth = sub.Depth()
@ -802,6 +804,7 @@ func (c *cfg) getSubstorageOpts(shCfg shardCfg) []blobstor.SubStorage {
blobovniczatree.WithBlobovniczaLeafWidth(sRead.leafWidth), blobovniczatree.WithBlobovniczaLeafWidth(sRead.leafWidth),
blobovniczatree.WithOpenedCacheSize(sRead.openedCacheSize), blobovniczatree.WithOpenedCacheSize(sRead.openedCacheSize),
blobovniczatree.WithInitWorkerCount(sRead.initWorkerCount), blobovniczatree.WithInitWorkerCount(sRead.initWorkerCount),
blobovniczatree.WithInitInAdvance(sRead.initInAdvance),
blobovniczatree.WithLogger(c.log), blobovniczatree.WithLogger(c.log),
blobovniczatree.WithObjectSizeLimit(shCfg.smallSizeObjectLimit), blobovniczatree.WithObjectSizeLimit(shCfg.smallSizeObjectLimit),
} }

View file

@ -100,6 +100,7 @@ func TestEngineSection(t *testing.T) {
require.EqualValues(t, 50, blz.OpenedCacheSize()) require.EqualValues(t, 50, blz.OpenedCacheSize())
require.EqualValues(t, 10, blz.LeafWidth()) require.EqualValues(t, 10, blz.LeafWidth())
require.EqualValues(t, 10, blz.InitWorkerCount()) require.EqualValues(t, 10, blz.InitWorkerCount())
require.EqualValues(t, true, blz.InitInAdvance())
require.Equal(t, "tmp/0/blob", ss[1].Path()) require.Equal(t, "tmp/0/blob", ss[1].Path())
require.EqualValues(t, 0o644, ss[1].Perm()) require.EqualValues(t, 0o644, ss[1].Perm())

View file

@ -131,3 +131,13 @@ func (x *Config) InitWorkerCount() int {
return InitWorkerCountDefault return InitWorkerCountDefault
} }
// InitInAdvance returns the value of "init_in_advance" config parameter.
//
// Returns False if the value is not defined or invalid.
func (x *Config) InitInAdvance() bool {
return config.BoolSafe(
(*config.Config)(x),
"init_in_advance",
)
}

View file

@ -127,6 +127,7 @@ FROSTFS_STORAGE_SHARD_0_BLOBSTOR_0_WIDTH=4
FROSTFS_STORAGE_SHARD_0_BLOBSTOR_0_OPENED_CACHE_CAPACITY=50 FROSTFS_STORAGE_SHARD_0_BLOBSTOR_0_OPENED_CACHE_CAPACITY=50
FROSTFS_STORAGE_SHARD_0_BLOBSTOR_0_LEAF_WIDTH=10 FROSTFS_STORAGE_SHARD_0_BLOBSTOR_0_LEAF_WIDTH=10
FROSTFS_STORAGE_SHARD_0_BLOBSTOR_0_INIT_WORKER_COUNT=10 FROSTFS_STORAGE_SHARD_0_BLOBSTOR_0_INIT_WORKER_COUNT=10
FROSTFS_STORAGE_SHARD_0_BLOBSTOR_0_INIT_IN_ADVANCE=TRUE
### FSTree config ### FSTree config
FROSTFS_STORAGE_SHARD_0_BLOBSTOR_1_TYPE=fstree FROSTFS_STORAGE_SHARD_0_BLOBSTOR_1_TYPE=fstree
FROSTFS_STORAGE_SHARD_0_BLOBSTOR_1_PATH=tmp/0/blob FROSTFS_STORAGE_SHARD_0_BLOBSTOR_1_PATH=tmp/0/blob

View file

@ -174,7 +174,8 @@
"width": 4, "width": 4,
"opened_cache_capacity": 50, "opened_cache_capacity": 50,
"leaf_width": 10, "leaf_width": 10,
"init_worker_count": 10 "init_worker_count": 10,
"init_in_advance": true
}, },
{ {
"type": "fstree", "type": "fstree",

View file

@ -186,6 +186,7 @@ storage:
- type: blobovnicza - type: blobovnicza
path: tmp/0/blob/blobovnicza path: tmp/0/blob/blobovnicza
init_worker_count: 10 #count of workers to initialize blobovniczas init_worker_count: 10 #count of workers to initialize blobovniczas
init_in_advance: true
- type: fstree - type: fstree
path: tmp/0/blob # blobstor path path: tmp/0/blob # blobstor path

View file

@ -82,27 +82,29 @@ func (b *Blobovniczas) initializeDBs(ctx context.Context) error {
return err return err
} }
err = b.iterateSortedLeaves(egCtx, nil, func(p string) (bool, error) { if b.createDBInAdvance {
if _, found := visited[p]; found { err = b.iterateSortedLeaves(egCtx, nil, func(p string) (bool, error) {
return false, nil if _, found := visited[p]; found {
} return false, nil
eg.Go(func() error {
shBlz := b.getBlobovniczaWithoutCaching(p)
_, err := shBlz.Open()
if err != nil {
return err
} }
defer shBlz.Close() eg.Go(func() error {
shBlz := b.getBlobovniczaWithoutCaching(p)
_, err := shBlz.Open()
if err != nil {
return err
}
defer shBlz.Close()
b.log.Debug(logs.BlobovniczatreeBlobovniczaSuccessfullyInitializedClosing, zap.String("id", p)) b.log.Debug(logs.BlobovniczatreeBlobovniczaSuccessfullyInitializedClosing, zap.String("id", p))
return nil return nil
})
return false, nil
}) })
return false, nil
})
if err != nil { if err != nil {
_ = eg.Wait() _ = eg.Wait()
return err return err
}
} }
return eg.Wait() return eg.Wait()

View file

@ -16,6 +16,7 @@ func TestIterateSortedLeavesAndDBPathsAreSame(t *testing.T) {
WithBlobovniczaShallowWidth(5), WithBlobovniczaShallowWidth(5),
WithRootPath(t.TempDir()), WithRootPath(t.TempDir()),
) )
blz.createDBInAdvance = true
require.NoError(t, blz.Open(false)) require.NoError(t, blz.Open(false))
require.NoError(t, blz.Init()) require.NoError(t, blz.Init())
defer func() { defer func() {

View file

@ -26,6 +26,7 @@ type cfg struct {
waitBeforeDropDB time.Duration waitBeforeDropDB time.Duration
blzInitWorkerCount int blzInitWorkerCount int
blzMoveBatchSize int blzMoveBatchSize int
createDBInAdvance bool
} }
type Option func(*cfg) type Option func(*cfg)
@ -139,3 +140,10 @@ func WithInitWorkerCount(v int) Option {
c.blzInitWorkerCount = v c.blzInitWorkerCount = v
} }
} }
// WithInitInAdvance returns an option to create blobovnicza tree DB's in advance.
func WithInitInAdvance(v bool) Option {
return func(c *cfg) {
c.createDBInAdvance = v
}
}