forked from TrueCloudLab/frostfs-node
[#698] blobovnicza: Store counter values
Blobovnicza initialization take a long time because of bucket Stat() call. So now blobovnicza stores counters in META bucket. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
5e8c08da3e
commit
e54dc3dc7c
8 changed files with 152 additions and 7 deletions
|
@ -104,7 +104,17 @@ func (b *Blobovnicza) Init() error {
|
|||
func (b *Blobovnicza) initializeCounters() error {
|
||||
var size uint64
|
||||
var items uint64
|
||||
var sizeExists bool
|
||||
var itemsCountExists bool
|
||||
|
||||
err := b.boltDB.View(func(tx *bbolt.Tx) error {
|
||||
size, sizeExists = hasDataSize(tx)
|
||||
items, itemsCountExists = hasItemsCount(tx)
|
||||
|
||||
if sizeExists && itemsCountExists {
|
||||
return nil
|
||||
}
|
||||
|
||||
return b.iterateAllDataBuckets(tx, func(lower, upper uint64, b *bbolt.Bucket) (bool, error) {
|
||||
keysN := uint64(b.Stats().KeyN)
|
||||
size += keysN * upper
|
||||
|
@ -115,6 +125,20 @@ func (b *Blobovnicza) initializeCounters() error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("can't determine DB size: %w", err)
|
||||
}
|
||||
if (!sizeExists || !itemsCountExists) && !b.boltOptions.ReadOnly {
|
||||
b.log.Debug(logs.BlobovniczaSavingCountersToMeta, zap.Uint64("size", size), zap.Uint64("items", items))
|
||||
if err := b.boltDB.Update(func(tx *bbolt.Tx) error {
|
||||
if err := saveDataSize(tx, size); err != nil {
|
||||
return err
|
||||
}
|
||||
return saveItemsCount(tx, items)
|
||||
}); err != nil {
|
||||
b.log.Debug(logs.BlobovniczaSavingCountersToMetaFailed, zap.Uint64("size", size), zap.Uint64("items", items))
|
||||
return fmt.Errorf("can't save blobovnicza's size and items count: %w", err)
|
||||
}
|
||||
b.log.Debug(logs.BlobovniczaSavingCountersToMetaSuccess, zap.Uint64("size", size), zap.Uint64("items", items))
|
||||
}
|
||||
|
||||
b.dataSize.Store(size)
|
||||
b.itemsCount.Store(items)
|
||||
b.metrics.AddOpenBlobovniczaSize(size)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue