[#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.
//
// 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)

View file

@ -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
}