writecache: Fix metrics and bolt delete #571
3 changed files with 12 additions and 20 deletions
|
@ -246,7 +246,7 @@ func (c *cache) workerFlushSmall() {
|
|||
continue
|
||||
}
|
||||
|
||||
c.deleteFromDB([]string{objectCore.AddressOf(obj).EncodeToString()})
|
||||
c.deleteFromDB(objectCore.AddressOf(obj).EncodeToString())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,6 +68,9 @@ func (c *cache) initCounters() error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("could not read write-cache FS counter: %w", err)
|
||||
}
|
||||
if inFS > 0 {
|
||||
inFS-- //small.bolt DB file
|
||||
}
|
||||
|
||||
c.objCounters.cDB.Store(inDB)
|
||||
c.objCounters.cFS.Store(inFS)
|
||||
|
|
|
@ -63,36 +63,24 @@ func (c *cache) openStore(readOnly bool) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *cache) deleteFromDB(keys []string) []string {
|
||||
if len(keys) == 0 {
|
||||
return keys
|
||||
}
|
||||
|
||||
var errorIndex int
|
||||
func (c *cache) deleteFromDB(key string) {
|
||||
err := c.db.Batch(func(tx *bbolt.Tx) error {
|
||||
b := tx.Bucket(defaultBucket)
|
||||
for errorIndex = range keys {
|
||||
if err := b.Delete([]byte(keys[errorIndex])); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return b.Delete([]byte(key))
|
||||
})
|
||||
for i := 0; i < errorIndex; i++ {
|
||||
|
||||
if err == nil {
|
||||
c.objCounters.DecDB()
|
||||
c.metrics.Evict(writecache.StorageTypeDB)
|
||||
storagelog.Write(c.log,
|
||||
storagelog.AddressField(keys[i]),
|
||||
storagelog.AddressField(key),
|
||||
storagelog.StorageTypeField(wcStorageType),
|
||||
storagelog.OpField("db DELETE"),
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
c.estimateCacheSize()
|
||||
} else {
|
||||
c.log.Error(logs.WritecacheCantRemoveObjectsFromTheDatabase, zap.Error(err))
|
||||
}
|
||||
|
||||
copy(keys, keys[errorIndex:])
|
||||
return keys[:len(keys)-errorIndex]
|
||||
}
|
||||
|
||||
func (c *cache) deleteFromDisk(ctx context.Context, keys []string) []string {
|
||||
|
@ -125,6 +113,7 @@ func (c *cache) deleteFromDisk(ctx context.Context, keys []string) []string {
|
|||
)
|
||||
c.metrics.Evict(writecache.StorageTypeFSTree)
|
||||
c.objCounters.DecFS()
|
||||
c.estimateCacheSize()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue