From 2e49d7ea7ee96b76629c0ae5bf6fd548e5d9aa8a Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Tue, 15 Aug 2023 16:53:38 +0300 Subject: [PATCH] [#602] blobovnicza: Init before using Fix blobovnicza size: after restart size metric resets. Signed-off-by: Dmitrii Stepanov --- .../blobovnicza/control.go | 34 +++++++++---------- .../blobstor/blobovniczatree/control.go | 3 ++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/pkg/local_object_storage/blobovnicza/control.go b/pkg/local_object_storage/blobovnicza/control.go index da4c870b..79bad91e 100644 --- a/pkg/local_object_storage/blobovnicza/control.go +++ b/pkg/local_object_storage/blobovnicza/control.go @@ -45,8 +45,6 @@ func (b *Blobovnicza) Open() error { // Init initializes internal database structure. // // If Blobovnicza is already initialized, no action is taken. -// -// Should not be called in read-only configuration. func (b *Blobovnicza) Init() error { b.log.Debug(logs.BlobovniczaInitializing, zap.Uint64("object size limit", b.objSizeLimit), @@ -58,25 +56,27 @@ func (b *Blobovnicza) Init() error { return nil } - err := b.boltDB.Update(func(tx *bbolt.Tx) error { - return b.iterateBucketKeys(func(lower, upper uint64, key []byte) (bool, error) { - // create size range bucket + if !b.boltOptions.ReadOnly { + err := b.boltDB.Update(func(tx *bbolt.Tx) error { + return b.iterateBucketKeys(func(lower, upper uint64, key []byte) (bool, error) { + // create size range bucket - rangeStr := stringifyBounds(lower, upper) - b.log.Debug(logs.BlobovniczaCreatingBucketForSizeRange, - zap.String("range", rangeStr)) + rangeStr := stringifyBounds(lower, upper) + b.log.Debug(logs.BlobovniczaCreatingBucketForSizeRange, + zap.String("range", rangeStr)) - _, err := tx.CreateBucketIfNotExists(key) - if err != nil { - return false, fmt.Errorf("(%T) could not create bucket for bounds %s: %w", - b, rangeStr, err) - } + _, err := tx.CreateBucketIfNotExists(key) + if err != nil { + return false, fmt.Errorf("(%T) could not create bucket for bounds %s: %w", + b, rangeStr, err) + } - return false, nil + return false, nil + }) }) - }) - if err != nil { - return err + if err != nil { + return err + } } info, err := os.Stat(b.path) diff --git a/pkg/local_object_storage/blobstor/blobovniczatree/control.go b/pkg/local_object_storage/blobstor/blobovniczatree/control.go index bc3d7d60..3a06310f 100644 --- a/pkg/local_object_storage/blobstor/blobovniczatree/control.go +++ b/pkg/local_object_storage/blobstor/blobovniczatree/control.go @@ -136,5 +136,8 @@ func (b *Blobovniczas) openBlobovniczaNoCache(p string) (*blobovnicza.Blobovnicz if err := blz.Open(); err != nil { return nil, fmt.Errorf("could not open blobovnicza %s: %w", p, err) } + if err := blz.Init(); err != nil { + return nil, fmt.Errorf("could not init blobovnicza %s: %w", p, err) + } return blz, nil }