From bf86973471d270da6034409e3a0d229e1b440bf6 Mon Sep 17 00:00:00 2001 From: Oleg Afanasyev Date: Mon, 11 Jul 2022 11:39:36 +0100 Subject: [PATCH] gc: fix NumKeysAffected counting more than collected Previously if key is not collected after a GC batch is sent out it would still be included as affected in GC stats. Those stats are mostly used for logging and tests, the unfortunate effect is that randomized test could fail. This commit fixes the bug. Release note: None --- pkg/kv/kvserver/gc/gc.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/kv/kvserver/gc/gc.go b/pkg/kv/kvserver/gc/gc.go index 5fc168809869..fc9b42d63291 100644 --- a/pkg/kv/kvserver/gc/gc.go +++ b/pkg/kv/kvserver/gc/gc.go @@ -379,6 +379,10 @@ func processReplicatedKeyRange( } if affected := isNewest && (sentBatchForThisKey || haveGarbageForThisKey); affected { info.NumKeysAffected++ + // If we reached newest timestamp for the key then we should reset sent + // batch to ensure subsequent keys are not included in affected keys if + // they don't have garbage. + sentBatchForThisKey = false } shouldSendBatch := batchGCKeysBytes >= KeyVersionChunkBytes if shouldSendBatch || isNewest && haveGarbageForThisKey {