From 0e697266c37dd17470a06f50bf90be56d9923d91 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Mon, 7 Aug 2023 13:31:56 +0300 Subject: [PATCH] [#563] writecache: Fix metrics and bolt delete Estimate cache size after delete objects to update metric. Update counters on small object deletion. Do not count bbolt DB file as FSTree object. Signed-off-by: Dmitrii Stepanov --- .../writecache/writecachebbolt/flush.go | 2 +- .../writecache/writecachebbolt/state.go | 3 +++ .../writecache/writecachebbolt/storage.go | 27 ++++++------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/pkg/local_object_storage/writecache/writecachebbolt/flush.go b/pkg/local_object_storage/writecache/writecachebbolt/flush.go index 78018eeae..4c1fb60e3 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/flush.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/flush.go @@ -246,7 +246,7 @@ func (c *cache) workerFlushSmall() { continue } - c.deleteFromDB([]string{objectCore.AddressOf(obj).EncodeToString()}) + c.deleteFromDB(objectCore.AddressOf(obj).EncodeToString()) } } diff --git a/pkg/local_object_storage/writecache/writecachebbolt/state.go b/pkg/local_object_storage/writecache/writecachebbolt/state.go index 950379751..03283dfef 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/state.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/state.go @@ -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) diff --git a/pkg/local_object_storage/writecache/writecachebbolt/storage.go b/pkg/local_object_storage/writecache/writecachebbolt/storage.go index ab0b59906..23f873d11 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/storage.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/storage.go @@ -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() } }