From 67a526f5f73b666b9ff6842c5704ae170bf22211 Mon Sep 17 00:00:00 2001 From: Dmytro Kozlov Date: Tue, 20 Dec 2022 20:11:38 +0200 Subject: [PATCH] lib/storage: fix collect downsampling metrics (#489) * lib/storage: fix downsampling * lib/storage: update logic * lib/storage: fix comments, removed unneeded check --- lib/storage/partition.go | 9 +++++---- lib/storage/table.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/storage/partition.go b/lib/storage/partition.go index b54ae1d84..d2dbc63b4 100644 --- a/lib/storage/partition.go +++ b/lib/storage/partition.go @@ -1238,10 +1238,6 @@ func atomicSetBool(p *uint64, b bool) { func (pt *partition) runFinalDedup() error { requiredDedupInterval, actualDedupInterval := pt.getRequiredDedupInterval() - if requiredDedupInterval <= actualDedupInterval { - // Deduplication isn't needed. - return nil - } t := time.Now() logger.Infof("starting final dedup for partition %s using requiredDedupInterval=%d ms, since the partition has smaller actualDedupInterval=%d ms", pt.bigPartsPath, requiredDedupInterval, actualDedupInterval) @@ -1252,6 +1248,11 @@ func (pt *partition) runFinalDedup() error { return nil } +func (pt *partition) isFinalDedupNeeded() bool { + requiredDedupInterval, actualDedupInterval := pt.getRequiredDedupInterval() + return requiredDedupInterval > actualDedupInterval +} + func (pt *partition) getRequiredDedupInterval() (int64, int64) { pws := pt.GetParts(nil, false) defer pt.PutParts(pws) diff --git a/lib/storage/table.go b/lib/storage/table.go index 690d21715..34dbdc5e5 100644 --- a/lib/storage/table.go +++ b/lib/storage/table.go @@ -455,7 +455,7 @@ func (tb *table) finalDedupWatcher() { timestamp := timestampFromTime(time.Now()) currentPartitionName := timestampToPartitionName(timestamp) for _, ptw := range ptws { - if ptw.pt.name == currentPartitionName { + if ptw.pt.name == currentPartitionName || !ptw.pt.isFinalDedupNeeded() { // Do not run final dedup for the current month. continue }