From 76855bddac33a6c44c9ab077ca0ab623721cca95 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 4 Oct 2023 13:28:24 +0300 Subject: [PATCH] [#645] node: Allow to add blobtree substorage from config Signed-off-by: Dmitrii Stepanov --- cmd/frostfs-node/config.go | 19 ++++++ .../engine/shard/blobstor/blobtree/config.go | 60 +++++++++++++++++++ cmd/frostfs-node/validate.go | 3 +- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 cmd/frostfs-node/config/engine/shard/blobstor/blobtree/config.go diff --git a/cmd/frostfs-node/config.go b/cmd/frostfs-node/config.go index cc106cf95..ea0973e7d 100644 --- a/cmd/frostfs-node/config.go +++ b/cmd/frostfs-node/config.go @@ -22,6 +22,7 @@ import ( engineconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine" shardconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard" blobovniczaconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/blobstor/blobovnicza" + blobtreeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/blobstor/blobtree" fstreeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/blobstor/fstree" loggerconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/logger" nodeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/node" @@ -33,6 +34,7 @@ import ( netmapCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobtree" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/engine" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" @@ -302,6 +304,10 @@ func (a *applicationConfiguration) setShardStorageConfig(newConfig *shardCfg, ol sub := fstreeconfig.From((*config.Config)(storagesCfg[i])) sCfg.depth = sub.Depth() sCfg.noSync = sub.NoSync() + case blobtree.Type: + sub := blobtreeconfig.From((*config.Config)(storagesCfg[i])) + sCfg.depth = sub.Depth() + sCfg.size = sub.Size() default: return fmt.Errorf("invalid storage type: %s", storagesCfg[i].Type()) } @@ -834,6 +840,19 @@ func (c *cfg) getSubstorageOpts(shCfg shardCfg) []blobstor.SubStorage { return true }, }) + case blobtree.Type: + blobTreeOpts := []blobtree.Option{ + blobtree.WithPath(sRead.path), + blobtree.WithPerm(sRead.perm), + blobtree.WithDepth(sRead.depth), + blobtree.WithTargetSize(sRead.size), + } + ss = append(ss, blobstor.SubStorage{ + Storage: blobtree.New(blobTreeOpts...), + Policy: func(_ *objectSDK.Object, data []byte) bool { + return uint64(len(data)) < shCfg.smallSizeObjectLimit + }, + }) default: // should never happen, that has already // been handled: when the config was read diff --git a/cmd/frostfs-node/config/engine/shard/blobstor/blobtree/config.go b/cmd/frostfs-node/config/engine/shard/blobstor/blobtree/config.go new file mode 100644 index 000000000..47b653a45 --- /dev/null +++ b/cmd/frostfs-node/config/engine/shard/blobstor/blobtree/config.go @@ -0,0 +1,60 @@ +package blobtreeconfig + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobtree" +) + +// Config is a wrapper over the config section +// which provides access to Blobtree configurations. +type Config config.Config + +const ( + // SizeDefault is a default limit of estimates of single Blobtree file size. + SizeDefault = 4 * 1024 * 1024 + + // DepthDefault is a default shallow dir depth. + DepthDefault = 8 +) + +// From wraps config section into Config. +func From(c *config.Config) *Config { + return (*Config)(c) +} + +// Type returns the storage type. +func (x *Config) Type() string { + return blobtree.Type +} + +// Size returns the value of "size" config parameter. +// +// Returns SizeDefault if the value is not a positive number. +func (x *Config) Size() uint64 { + s := config.SizeInBytesSafe( + (*config.Config)(x), + "size", + ) + + if s > 0 { + return s + } + + return SizeDefault +} + +// ShallowDepth returns the value of "depth" config parameter. +// +// Returns ShallowDepthDefault if the value is not a positive number. +func (x *Config) Depth() uint64 { + d := config.UintSafe( + (*config.Config)(x), + "depth", + ) + + if d > 0 { + return d + } + + return DepthDefault +} diff --git a/cmd/frostfs-node/validate.go b/cmd/frostfs-node/validate.go index 80c90ec44..b3472a074 100644 --- a/cmd/frostfs-node/validate.go +++ b/cmd/frostfs-node/validate.go @@ -10,6 +10,7 @@ import ( loggerconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/logger" treeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/tree" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobtree" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" ) @@ -55,7 +56,7 @@ func validateConfig(c *config.Config) error { } for i := range blobstor { switch blobstor[i].Type() { - case fstree.Type, blobovniczatree.Type: + case fstree.Type, blobovniczatree.Type, blobtree.Type: default: return fmt.Errorf("unexpected storage type: %s (shard %d)", blobstor[i].Type(), shardNum) }