From 52b0c1f19afdd855c23e53a123dd2464ee175ccb Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 26 Nov 2020 17:26:21 +0300 Subject: [PATCH] [#216] blobovnicza: Add configuration values Signed-off-by: Leonard Lyubich --- .../blobovnicza/blobovnicza.go | 85 ++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/pkg/local_object_storage/blobovnicza/blobovnicza.go b/pkg/local_object_storage/blobovnicza/blobovnicza.go index 831fa9222..4f10a1fad 100644 --- a/pkg/local_object_storage/blobovnicza/blobovnicza.go +++ b/pkg/local_object_storage/blobovnicza/blobovnicza.go @@ -1,18 +1,53 @@ package blobovnicza +import ( + "os" + + "github.com/nspcc-dev/neofs-node/pkg/util/logger" + "go.etcd.io/bbolt" + "go.uber.org/atomic" + "go.uber.org/zap" +) + // Blobovnicza represents the implementation of NeoFS Blobovnicza. type Blobovnicza struct { *cfg + + filled *atomic.Uint64 + + boltDB *bbolt.DB } // Option is an option of Blobovnicza's constructor. type Option func(*cfg) type cfg struct { + boltDBCfg + + fullSizeLimit uint64 + + objSizeLimit uint64 + + log *logger.Logger +} + +type boltDBCfg struct { + perm os.FileMode + + path string + + boltOptions *bbolt.Options } func defaultCfg() *cfg { - return &cfg{} + return &cfg{ + boltDBCfg: boltDBCfg{ + perm: os.ModePerm, // 0777 + }, + fullSizeLimit: 1 << 30, // 1GB + objSizeLimit: 1 << 20, // 1MB + log: zap.L(), + } } // New creates and returns new Blobovnicza instance. @@ -24,6 +59,52 @@ func New(opts ...Option) *Blobovnicza { } return &Blobovnicza{ - cfg: c, + cfg: c, + filled: atomic.NewUint64(0), + } +} + +// WithPath returns option to set system path to Blobovnicza. +func WithPath(path string) Option { + return func(c *cfg) { + c.path = path + } +} + +// WithPermissions returns option to specify permission bits +// of Blobovnicza's system path. +func WithPermissions(perm os.FileMode) Option { + return func(c *cfg) { + c.perm = perm + } +} + +// WithSizeLimit returns option to specify maximum size +// of the objects stored in Blobovnicza. +func WithObjectSizeLimit(lim uint64) Option { + return func(c *cfg) { + c.objSizeLimit = lim + } +} + +// WithFullSizeLimit returns option to set maximum sum size +// of all stored objects. +func WithFullSizeLimit(lim uint64) Option { + return func(c *cfg) { + c.fullSizeLimit = lim + } +} + +// WithLogger returns option to specify Blobovnicza's logger. +func WithLogger(l *logger.Logger) Option { + return func(c *cfg) { + c.log = l.With(zap.String("component", "Blobovnicza")) + } +} + +// WithBoltDBOptions returns option to specify BoltDB options. +func WithBoltDBOptions(opts *bbolt.Options) Option { + return func(c *cfg) { + c.boltOptions = opts } }