From 30f98916f911d53fd673e250234c1cd6d7866e88 Mon Sep 17 00:00:00 2001 From: rtm0 <149964189+rtm0@users.noreply.github.com> Date: Tue, 27 Aug 2024 22:30:37 +0300 Subject: [PATCH] Move rowsAddedTotal counter to Storage (#6841) ### Describe Your Changes Reduced the scope of rowsAddedTotal variable from global to Storage. This metric clearly belongs to a given Storage object as it counts the number of records added by a given Storage instance. Reducing the scope improves the incapsulation and allows to reset this variable during the unit tests (i.e. every time a new Storage object is created by a test, that object gets a new variable). Signed-off-by: Artem Fetishev --- lib/storage/storage.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 2995326b1..3da53cdf4 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -40,6 +40,8 @@ const ( // Storage represents TSDB storage. type Storage struct { + rowsAddedTotal atomic.Uint64 + tooSmallTimestampRows atomic.Uint64 tooBigTimestampRows atomic.Uint64 @@ -552,7 +554,7 @@ func (m *Metrics) Reset() { // UpdateMetrics updates m with metrics from s. func (s *Storage) UpdateMetrics(m *Metrics) { - m.RowsAddedTotal = rowsAddedTotal.Load() + m.RowsAddedTotal += s.rowsAddedTotal.Load() m.DedupsDuringMerge = dedupsDuringMerge.Load() m.SnapshotsCount += uint64(s.mustGetSnapshotsCount()) @@ -1606,8 +1608,6 @@ func (s *Storage) ForceMergePartitions(partitionNamePrefix string) error { return s.tb.ForceMergePartitions(partitionNamePrefix) } -var rowsAddedTotal atomic.Uint64 - // AddRows adds the given mrs to s. // // The caller should limit the number of concurrent AddRows calls to the number @@ -1629,7 +1629,7 @@ func (s *Storage) AddRows(mrs []MetricRow, precisionBits uint8) { mrs = nil } s.add(ic.rrs, ic.tmpMrs, mrsBlock, precisionBits) - rowsAddedTotal.Add(uint64(len(mrsBlock))) + s.rowsAddedTotal.Add(uint64(len(mrsBlock))) } putMetricRowsInsertCtx(ic) }