[#1094] blobovnicza: calculate size in Init properly

If pre-existing blobovnicza is initialized, it's size should be updated
even if all buckets are in place.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-01-19 16:17:36 +03:00 committed by Alex Vanin
parent 418b553920
commit 651adf46c6
3 changed files with 19 additions and 43 deletions

View file

@ -4,8 +4,6 @@ import (
"encoding/binary"
"fmt"
"strconv"
"go.etcd.io/bbolt"
)
const firstBucketBound = uint64(32 * 1 << 10) // 32KB
@ -51,24 +49,3 @@ func (b *Blobovnicza) decSize(sz uint64) {
func (b *Blobovnicza) full() bool {
return b.filled.Load() >= b.fullSizeLimit
}
func (b *Blobovnicza) syncFullnessCounter(tx *bbolt.Tx) error {
sz := uint64(0)
if err := b.iterateBucketKeys(func(lower, upper uint64, key []byte) (bool, error) {
buck := tx.Bucket(key)
if buck == nil {
return false, fmt.Errorf("bucket not found %s", stringifyBounds(lower, upper))
}
sz += uint64(buck.Stats().KeyN) * (upper + lower) / 2
return false, nil
}); err != nil {
return err
}
b.filled.Store(sz)
return nil
}