From 972ca83e23cd5cc1f87d36c29743c51f31570ca5 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 16 Jun 2022 18:21:10 +0300 Subject: [PATCH] [#1524] writecache: Add some bolt parameters to the configuration Signed-off-by: Evgenii Stratonikov --- cmd/neofs-node/config.go | 2 ++ .../writecache/options.go | 24 +++++++++++++++++++ .../writecache/storage.go | 3 +++ .../writecache/writecache.go | 3 +++ 4 files changed, 32 insertions(+) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index dd7f1bdd..ee7d0abd 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -403,6 +403,8 @@ func initShardOptions(c *cfg) { writeCacheOpts = []writecache.Option{ writecache.WithPath(writeCacheCfg.Path()), writecache.WithLogger(c.log), + writecache.WithMaxBatchSize(writeCacheCfg.BoltDB().MaxBatchSize()), + writecache.WithMaxBatchDelay(writeCacheCfg.BoltDB().MaxBatchDelay()), writecache.WithMaxMemSize(writeCacheCfg.MemSize()), writecache.WithMaxObjectSize(writeCacheCfg.MaxObjectSize()), writecache.WithSmallObjectSize(writeCacheCfg.SmallObjectSize()), diff --git a/pkg/local_object_storage/writecache/options.go b/pkg/local_object_storage/writecache/options.go index 71ecb442..64e1feba 100644 --- a/pkg/local_object_storage/writecache/options.go +++ b/pkg/local_object_storage/writecache/options.go @@ -1,6 +1,8 @@ package writecache import ( + "time" + "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "go.uber.org/zap" @@ -31,6 +33,10 @@ type options struct { maxCacheSize uint64 // objCounters is an ObjectCounters instance needed for cache size estimation. objCounters ObjectCounters + // maxBatchSize is the maximum batch size for the small object database. + maxBatchSize int + // maxBatchDelay is the maximum batch wait time for the small object database. + maxBatchDelay time.Duration } // WithLogger sets logger. @@ -107,3 +113,21 @@ func WithMaxCacheSize(sz uint64) Option { o.maxCacheSize = sz } } + +// WithMaxBatchSize sets max batch size for the small object database. +func WithMaxBatchSize(sz int) Option { + return func(o *options) { + if sz > 0 { + o.maxBatchSize = sz + } + } +} + +// WithMaxBatchDelay sets max batch delay for the small object database. +func WithMaxBatchDelay(d time.Duration) Option { + return func(o *options) { + if d > 0 { + o.maxBatchDelay = d + } + } +} diff --git a/pkg/local_object_storage/writecache/storage.go b/pkg/local_object_storage/writecache/storage.go index 4f2458c7..48c88e80 100644 --- a/pkg/local_object_storage/writecache/storage.go +++ b/pkg/local_object_storage/writecache/storage.go @@ -38,6 +38,9 @@ func (c *cache) openStore() error { return fmt.Errorf("could not open database: %w", err) } + c.db.MaxBatchSize = c.maxBatchSize + c.db.MaxBatchDelay = c.maxBatchDelay + err = c.db.Update(func(tx *bbolt.Tx) error { _, err := tx.CreateBucketIfNotExists(defaultBucket) return err diff --git a/pkg/local_object_storage/writecache/writecache.go b/pkg/local_object_storage/writecache/writecache.go index 763f58bf..52e0f8e8 100644 --- a/pkg/local_object_storage/writecache/writecache.go +++ b/pkg/local_object_storage/writecache/writecache.go @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree" "github.com/nspcc-dev/neofs-sdk-go/object" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" + "go.etcd.io/bbolt" "go.uber.org/zap" ) @@ -98,6 +99,8 @@ func New(opts ...Option) Cache { smallObjectSize: smallObjectSize, workersCount: defaultFlushWorkersCount, maxCacheSize: maxCacheSizeBytes, + maxBatchSize: bbolt.DefaultMaxBatchSize, + maxBatchDelay: bbolt.DefaultMaxBatchDelay, }, }