[#602] blobovnicza: Init before using

Fix blobovnicza size: after restart size metric resets.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-08-15 16:53:38 +03:00 committed by Evgenii Stratonikov
parent f7042c5a6f
commit 2e49d7ea7e
2 changed files with 20 additions and 17 deletions

View file

@ -45,8 +45,6 @@ func (b *Blobovnicza) Open() error {
// Init initializes internal database structure. // Init initializes internal database structure.
// //
// If Blobovnicza is already initialized, no action is taken. // If Blobovnicza is already initialized, no action is taken.
//
// Should not be called in read-only configuration.
func (b *Blobovnicza) Init() error { func (b *Blobovnicza) Init() error {
b.log.Debug(logs.BlobovniczaInitializing, b.log.Debug(logs.BlobovniczaInitializing,
zap.Uint64("object size limit", b.objSizeLimit), zap.Uint64("object size limit", b.objSizeLimit),
@ -58,25 +56,27 @@ func (b *Blobovnicza) Init() error {
return nil return nil
} }
err := b.boltDB.Update(func(tx *bbolt.Tx) error { if !b.boltOptions.ReadOnly {
return b.iterateBucketKeys(func(lower, upper uint64, key []byte) (bool, error) { err := b.boltDB.Update(func(tx *bbolt.Tx) error {
// create size range bucket return b.iterateBucketKeys(func(lower, upper uint64, key []byte) (bool, error) {
// create size range bucket
rangeStr := stringifyBounds(lower, upper) rangeStr := stringifyBounds(lower, upper)
b.log.Debug(logs.BlobovniczaCreatingBucketForSizeRange, b.log.Debug(logs.BlobovniczaCreatingBucketForSizeRange,
zap.String("range", rangeStr)) zap.String("range", rangeStr))
_, err := tx.CreateBucketIfNotExists(key) _, err := tx.CreateBucketIfNotExists(key)
if err != nil { if err != nil {
return false, fmt.Errorf("(%T) could not create bucket for bounds %s: %w", return false, fmt.Errorf("(%T) could not create bucket for bounds %s: %w",
b, rangeStr, err) b, rangeStr, err)
} }
return false, nil return false, nil
})
}) })
}) if err != nil {
if err != nil { return err
return err }
} }
info, err := os.Stat(b.path) info, err := os.Stat(b.path)

View file

@ -136,5 +136,8 @@ func (b *Blobovniczas) openBlobovniczaNoCache(p string) (*blobovnicza.Blobovnicz
if err := blz.Open(); err != nil { if err := blz.Open(); err != nil {
return nil, fmt.Errorf("could not open blobovnicza %s: %w", p, err) 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 return blz, nil
} }