[#585] writecache: Fix DB counter

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-08-11 12:51:41 +03:00
parent 58c8722c81
commit 2efe9cc1be
3 changed files with 31 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package writecachebbolt
import (
"context"
"fmt"
"math"
"os"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
@ -68,9 +69,12 @@ func (c *cache) openStore(readOnly bool) error {
}
func (c *cache) deleteFromDB(key string) {
var recordDeleted bool
err := c.db.Batch(func(tx *bbolt.Tx) error {
b := tx.Bucket(defaultBucket)
return b.Delete([]byte(key))
key := []byte(key)
recordDeleted = !recordDeleted && b.Get(key) != nil
return b.Delete(key)
})
if err == nil {
@ -80,7 +84,10 @@ func (c *cache) deleteFromDB(key string) {
storagelog.StorageTypeField(wcStorageType),
storagelog.OpField("db DELETE"),
)
c.estimateCacheSize()
if recordDeleted {
c.objCounters.cDB.Add(math.MaxUint64)
c.estimateCacheSize()
}
} else {
c.log.Error(logs.WritecacheCantRemoveObjectsFromTheDatabase, zap.Error(err))
}