From db49ad16cc2037bd365f2cd6e7b1c20689fadd06 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Mon, 27 Nov 2023 16:01:48 +0300 Subject: [PATCH] [#826] blobovniczatree: Do not create DB's on init Blobovniczas will be created on write requests. Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-node/config.go | 3 ++ cmd/frostfs-node/config/engine/config_test.go | 1 + .../shard/blobstor/blobovnicza/config.go | 10 ++++++ config/example/node.env | 1 + config/example/node.json | 3 +- config/example/node.yaml | 1 + .../blobstor/blobovniczatree/control.go | 36 ++++++++++--------- .../blobstor/blobovniczatree/iterate_test.go | 1 + .../blobstor/blobovniczatree/option.go | 8 +++++ 9 files changed, 46 insertions(+), 18 deletions(-) diff --git a/cmd/frostfs-node/config.go b/cmd/frostfs-node/config.go index a0d5fba9..2d80a411 100644 --- a/cmd/frostfs-node/config.go +++ b/cmd/frostfs-node/config.go @@ -183,6 +183,7 @@ type subStorageCfg struct { leafWidth uint64 openedCacheSize int initWorkerCount int + initInAdvance bool } // readConfig fills applicationConfiguration with raw configuration values @@ -302,6 +303,7 @@ func (a *applicationConfiguration) setShardStorageConfig(newConfig *shardCfg, ol sCfg.leafWidth = sub.LeafWidth() sCfg.openedCacheSize = sub.OpenedCacheSize() sCfg.initWorkerCount = sub.InitWorkerCount() + sCfg.initInAdvance = sub.InitInAdvance() case fstree.Type: sub := fstreeconfig.From((*config.Config)(storagesCfg[i])) sCfg.depth = sub.Depth() @@ -802,6 +804,7 @@ func (c *cfg) getSubstorageOpts(shCfg shardCfg) []blobstor.SubStorage { blobovniczatree.WithBlobovniczaLeafWidth(sRead.leafWidth), blobovniczatree.WithOpenedCacheSize(sRead.openedCacheSize), blobovniczatree.WithInitWorkerCount(sRead.initWorkerCount), + blobovniczatree.WithInitInAdvance(sRead.initInAdvance), blobovniczatree.WithLogger(c.log), blobovniczatree.WithObjectSizeLimit(shCfg.smallSizeObjectLimit), } diff --git a/cmd/frostfs-node/config/engine/config_test.go b/cmd/frostfs-node/config/engine/config_test.go index 185c6394..6c7b23cc 100644 --- a/cmd/frostfs-node/config/engine/config_test.go +++ b/cmd/frostfs-node/config/engine/config_test.go @@ -100,6 +100,7 @@ func TestEngineSection(t *testing.T) { require.EqualValues(t, 50, blz.OpenedCacheSize()) require.EqualValues(t, 10, blz.LeafWidth()) require.EqualValues(t, 10, blz.InitWorkerCount()) + require.EqualValues(t, true, blz.InitInAdvance()) require.Equal(t, "tmp/0/blob", ss[1].Path()) require.EqualValues(t, 0o644, ss[1].Perm()) diff --git a/cmd/frostfs-node/config/engine/shard/blobstor/blobovnicza/config.go b/cmd/frostfs-node/config/engine/shard/blobstor/blobovnicza/config.go index 1f7fc77f..37191cc7 100644 --- a/cmd/frostfs-node/config/engine/shard/blobstor/blobovnicza/config.go +++ b/cmd/frostfs-node/config/engine/shard/blobstor/blobovnicza/config.go @@ -131,3 +131,13 @@ func (x *Config) InitWorkerCount() int { 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", + ) +} diff --git a/config/example/node.env b/config/example/node.env index 9c8b90d3..be16f62b 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -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_LEAF_WIDTH=10 FROSTFS_STORAGE_SHARD_0_BLOBSTOR_0_INIT_WORKER_COUNT=10 +FROSTFS_STORAGE_SHARD_0_BLOBSTOR_0_INIT_IN_ADVANCE=TRUE ### FSTree config FROSTFS_STORAGE_SHARD_0_BLOBSTOR_1_TYPE=fstree FROSTFS_STORAGE_SHARD_0_BLOBSTOR_1_PATH=tmp/0/blob diff --git a/config/example/node.json b/config/example/node.json index c7cac250..ff38e389 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -174,7 +174,8 @@ "width": 4, "opened_cache_capacity": 50, "leaf_width": 10, - "init_worker_count": 10 + "init_worker_count": 10, + "init_in_advance": true }, { "type": "fstree", diff --git a/config/example/node.yaml b/config/example/node.yaml index 4cd023f5..1355113a 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -186,6 +186,7 @@ storage: - type: blobovnicza path: tmp/0/blob/blobovnicza init_worker_count: 10 #count of workers to initialize blobovniczas + init_in_advance: true - type: fstree path: tmp/0/blob # blobstor path diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/control.go b/pkg/local_object_storage/blobstor/blobovniczatree/control.go index f1d78dc5..bd98967c 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/control.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/control.go @@ -82,27 +82,29 @@ func (b *Blobovniczas) initializeDBs(ctx context.Context) error { return err } - err = b.iterateSortedLeaves(egCtx, nil, func(p string) (bool, error) { - if _, found := visited[p]; found { - return false, nil - } - eg.Go(func() error { - shBlz := b.getBlobovniczaWithoutCaching(p) - _, err := shBlz.Open() - if err != nil { - return err + if b.createDBInAdvance { + err = b.iterateSortedLeaves(egCtx, nil, func(p string) (bool, error) { + if _, found := visited[p]; found { + return false, nil } - 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)) - return nil + b.log.Debug(logs.BlobovniczatreeBlobovniczaSuccessfullyInitializedClosing, zap.String("id", p)) + return nil + }) + return false, nil }) - return false, nil - }) - if err != nil { - _ = eg.Wait() - return err + if err != nil { + _ = eg.Wait() + return err + } } return eg.Wait() diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/iterate_test.go b/pkg/local_object_storage/blobstor/blobovniczatree/iterate_test.go index 91fa27dd..c322fa7a 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/iterate_test.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/iterate_test.go @@ -16,6 +16,7 @@ func TestIterateSortedLeavesAndDBPathsAreSame(t *testing.T) { WithBlobovniczaShallowWidth(5), WithRootPath(t.TempDir()), ) + blz.createDBInAdvance = true require.NoError(t, blz.Open(false)) require.NoError(t, blz.Init()) defer func() { diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/option.go b/pkg/local_object_storage/blobstor/blobovniczatree/option.go index 93dc487e..d36074dc 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/option.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/option.go @@ -26,6 +26,7 @@ type cfg struct { waitBeforeDropDB time.Duration blzInitWorkerCount int blzMoveBatchSize int + createDBInAdvance bool } type Option func(*cfg) @@ -139,3 +140,10 @@ func WithInitWorkerCount(v int) Option { 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 + } +}