[#915] blobovnicza: Re-use Bolt transaction in syncFullnessCounter
Make `syncFullnessCounter` to accept `bbolt.Tx` argument of Bolt transaction within which counter should be synchronized. Pass corresponding transaction during `Init`. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
feb0a65efb
commit
2920c5203b
2 changed files with 15 additions and 20 deletions
|
@ -65,7 +65,7 @@ func (b *Blobovnicza) Init() error {
|
||||||
|
|
||||||
b.log.Debug("bucket already exists, initializing state")
|
b.log.Debug("bucket already exists, initializing state")
|
||||||
|
|
||||||
return true, b.syncFullnessCounter()
|
return true, b.syncFullnessCounter(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -52,8 +52,7 @@ func (b *Blobovnicza) full() bool {
|
||||||
return b.filled.Load() >= b.fullSizeLimit
|
return b.filled.Load() >= b.fullSizeLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Blobovnicza) syncFullnessCounter() error {
|
func (b *Blobovnicza) syncFullnessCounter(tx *bbolt.Tx) error {
|
||||||
err := b.boltDB.View(func(tx *bbolt.Tx) error {
|
|
||||||
sz := uint64(0)
|
sz := uint64(0)
|
||||||
|
|
||||||
if err := b.iterateBucketKeys(func(lower, upper uint64, key []byte) (bool, error) {
|
if err := b.iterateBucketKeys(func(lower, upper uint64, key []byte) (bool, error) {
|
||||||
|
@ -72,9 +71,5 @@ func (b *Blobovnicza) syncFullnessCounter() error {
|
||||||
b.filled.Store(sz)
|
b.filled.Store(sz)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not sync fullness counter: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue