From dc81b4b50ca6ec8862e3efba32586c13474ba66d Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Fri, 27 Oct 2023 09:53:12 +0300 Subject: [PATCH] [#725] writecache: Fix metric values Signed-off-by: Dmitrii Stepanov --- pkg/local_object_storage/engine/writecache.go | 7 ------- .../writecache/writecachebadger/delete.go | 2 +- .../writecache/writecachebadger/put.go | 2 +- .../writecache/writecachebadger/state.go | 10 ++++++++++ .../writecache/writecachebadger/storage.go | 2 +- .../writecache/writecachebbolt/delete.go | 1 + .../writecache/writecachebbolt/flush.go | 1 + .../writecache/writecachebbolt/put.go | 1 + .../writecache/writecachebbolt/state.go | 1 + .../writecache/writecachebbolt/storage.go | 3 ++- pkg/metrics/writecache.go | 20 ------------------- 11 files changed, 19 insertions(+), 31 deletions(-) diff --git a/pkg/local_object_storage/engine/writecache.go b/pkg/local_object_storage/engine/writecache.go index 2e518c6ff..00a40105e 100644 --- a/pkg/local_object_storage/engine/writecache.go +++ b/pkg/local_object_storage/engine/writecache.go @@ -68,16 +68,10 @@ func (m *writeCacheMetrics) Get(d time.Duration, success bool, st writecache.Sto func (m *writeCacheMetrics) Delete(d time.Duration, success bool, st writecache.StorageType) { m.metrics.AddMethodDuration(m.shardID, "Delete", success, d, st.String()) - if success { - m.metrics.DecActualCount(m.shardID, st.String()) - } } func (m *writeCacheMetrics) Put(d time.Duration, success bool, st writecache.StorageType) { m.metrics.AddMethodDuration(m.shardID, "Put", success, d, st.String()) - if success { - m.metrics.IncActualCount(m.shardID, st.String()) - } } func (m *writeCacheMetrics) SetEstimateSize(db, fstree uint64) { @@ -99,7 +93,6 @@ func (m *writeCacheMetrics) Flush(success bool, st writecache.StorageType) { } func (m *writeCacheMetrics) Evict(st writecache.StorageType) { - m.metrics.DecActualCount(m.shardID, st.String()) m.metrics.IncOperationCounter(m.shardID, "Evict", metrics.NullBool{}, st.String()) } diff --git a/pkg/local_object_storage/writecache/writecachebadger/delete.go b/pkg/local_object_storage/writecache/writecachebadger/delete.go index afab78547..f96bf2707 100644 --- a/pkg/local_object_storage/writecache/writecachebadger/delete.go +++ b/pkg/local_object_storage/writecache/writecachebadger/delete.go @@ -59,7 +59,7 @@ func (c *cache) Delete(ctx context.Context, addr oid.Address) error { storagelog.OpField("db DELETE"), ) deleted = true - c.objCounters.DecDB() + c.decDB() } return err } diff --git a/pkg/local_object_storage/writecache/writecachebadger/put.go b/pkg/local_object_storage/writecache/writecachebadger/put.go index c03a0d336..2071ba1d0 100644 --- a/pkg/local_object_storage/writecache/writecachebadger/put.go +++ b/pkg/local_object_storage/writecache/writecachebadger/put.go @@ -76,7 +76,7 @@ func (c *cache) put(obj objectInfo) error { storagelog.StorageTypeField(wcStorageType), storagelog.OpField("db PUT"), ) - c.objCounters.IncDB() + c.incDB() } return err } diff --git a/pkg/local_object_storage/writecache/writecachebadger/state.go b/pkg/local_object_storage/writecache/writecachebadger/state.go index 994dfa3d5..e098eb060 100644 --- a/pkg/local_object_storage/writecache/writecachebadger/state.go +++ b/pkg/local_object_storage/writecache/writecachebadger/state.go @@ -55,3 +55,13 @@ func (c *cache) initCounters() error { return nil } + +func (c *cache) incDB() { + c.objCounters.IncDB() + c.metrics.SetActualCounters(c.objCounters.DB(), 0) +} + +func (c *cache) decDB() { + c.objCounters.DecDB() + c.metrics.SetActualCounters(c.objCounters.DB(), 0) +} diff --git a/pkg/local_object_storage/writecache/writecachebadger/storage.go b/pkg/local_object_storage/writecache/writecachebadger/storage.go index 9ff54bee0..04337b7a6 100644 --- a/pkg/local_object_storage/writecache/writecachebadger/storage.go +++ b/pkg/local_object_storage/writecache/writecachebadger/storage.go @@ -73,7 +73,7 @@ func (c *cache) deleteFromDB(keys []internalKey) []internalKey { } for i := 0; i < errorIndex; i++ { - c.objCounters.DecDB() + c.decDB() c.metrics.Evict(writecache.StorageTypeDB) storagelog.Write(c.log, storagelog.AddressField(keys[i]), diff --git a/pkg/local_object_storage/writecache/writecachebbolt/delete.go b/pkg/local_object_storage/writecache/writecachebbolt/delete.go index e4d9c219f..15c83eed1 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/delete.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/delete.go @@ -83,6 +83,7 @@ func (c *cache) Delete(ctx context.Context, addr oid.Address) error { storagelog.OpField("fstree DELETE"), ) deleted = true + // counter changed by fstree c.estimateCacheSize() } return metaerr.Wrap(err) diff --git a/pkg/local_object_storage/writecache/writecachebbolt/flush.go b/pkg/local_object_storage/writecache/writecachebbolt/flush.go index c3b0f89bb..cc1b7753a 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/flush.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/flush.go @@ -70,6 +70,7 @@ func (c *cache) runFlushLoop() { case <-tt.C: c.flushSmallObjects() tt.Reset(defaultFlushInterval) + c.estimateCacheSize() case <-c.closeCh: return } diff --git a/pkg/local_object_storage/writecache/writecachebbolt/put.go b/pkg/local_object_storage/writecache/writecachebbolt/put.go index 1d9957219..63fa544ed 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/put.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/put.go @@ -131,6 +131,7 @@ func (c *cache) putBig(ctx context.Context, addr string, prm common.PutPrm) erro storagelog.StorageTypeField(wcStorageType), storagelog.OpField("fstree PUT"), ) + // counter changed by fstree c.estimateCacheSize() return nil diff --git a/pkg/local_object_storage/writecache/writecachebbolt/state.go b/pkg/local_object_storage/writecache/writecachebbolt/state.go index 91d54b0ea..8749ec601 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/state.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/state.go @@ -72,5 +72,6 @@ func (c *cache) initCounters() error { return fmt.Errorf("could not read write-cache DB counter: %w", err) } c.objCounters.cDB.Store(inDB) + c.estimateCacheSize() return nil } diff --git a/pkg/local_object_storage/writecache/writecachebbolt/storage.go b/pkg/local_object_storage/writecache/writecachebbolt/storage.go index bbd66d57c..bff9385dc 100644 --- a/pkg/local_object_storage/writecache/writecachebbolt/storage.go +++ b/pkg/local_object_storage/writecache/writecachebbolt/storage.go @@ -73,7 +73,7 @@ func (c *cache) deleteFromDB(key string) { err := c.db.Batch(func(tx *bbolt.Tx) error { b := tx.Bucket(defaultBucket) key := []byte(key) - recordDeleted = !recordDeleted && b.Get(key) != nil + recordDeleted = b.Get(key) != nil return b.Delete(key) }) @@ -122,6 +122,7 @@ func (c *cache) deleteFromDisk(ctx context.Context, keys []string) []string { storagelog.OpField("fstree DELETE"), ) c.metrics.Evict(writecache.StorageTypeFSTree) + // counter changed by fstree c.estimateCacheSize() } } diff --git a/pkg/metrics/writecache.go b/pkg/metrics/writecache.go index 7e6083a49..c8f815ca5 100644 --- a/pkg/metrics/writecache.go +++ b/pkg/metrics/writecache.go @@ -10,16 +10,10 @@ import ( type WriteCacheMetrics interface { AddMethodDuration(shardID string, method string, success bool, d time.Duration, storageType string) - - IncActualCount(shardID string, storageType string) - DecActualCount(shardID string, storageType string) SetActualCount(shardID string, count uint64, storageType string) - SetEstimateSize(shardID string, size uint64, storageType string) SetMode(shardID string, mode string) - IncOperationCounter(shardID string, operation string, success NullBool, storageType string) - Close(shardID string) } @@ -65,20 +59,6 @@ func (m *writeCacheMetrics) AddMethodDuration(shardID string, method string, suc ).Observe(d.Seconds()) } -func (m *writeCacheMetrics) IncActualCount(shardID string, storageType string) { - m.actualCount.With(prometheus.Labels{ - shardIDLabel: shardID, - storageLabel: storageType, - }).Inc() -} - -func (m *writeCacheMetrics) DecActualCount(shardID string, storageType string) { - m.actualCount.With(prometheus.Labels{ - shardIDLabel: shardID, - storageLabel: storageType, - }).Dec() -} - func (m *writeCacheMetrics) SetActualCount(shardID string, count uint64, storageType string) { m.actualCount.With(prometheus.Labels{ shardIDLabel: shardID,