From c173b5b52d173f82176a51bdcc1cb0b3d2b8331a Mon Sep 17 00:00:00 2001 From: sumeerbhola Date: Sat, 16 Nov 2024 12:14:03 -0500 Subject: [PATCH] rac2: fix incorrect assertion when send-queue becomes empty The indexToSend in this case was being updated before the loop, but the preciseSizeSum was incrementally deducted inside the loop. This meant that if more than one item was being popped and the queue was becoming empty, the code would incorrectly assert that preciseSizeSum should be 0 after subtracting the tokens for the first entry. Fixes #135289, #135344 Epic: none Release note: None --- pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go b/pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go index b3a47a9e6f6e..79e81ad7a4f2 100644 --- a/pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go +++ b/pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go @@ -2601,6 +2601,7 @@ func (rss *replicaSendStream) handleReadyEntriesRaftMuAndStreamLocked( } rss.mu.sendQueue.indexToSend = event.sendingEntries[n-1].id.index + 1 var sendTokensToDeduct [admissionpb.NumWorkClasses]kvflowcontrol.Tokens + var sendQPreciseSizeDelta kvflowcontrol.Tokens for _, entry := range event.sendingEntries { if !entry.usesFlowControl { continue @@ -2628,11 +2629,14 @@ func (rss *replicaSendStream) handleReadyEntriesRaftMuAndStreamLocked( if inSendQueue && entry.id.index >= rss.mu.nextRaftIndexInitial { // Was in send-queue and had eval tokens deducted for it. rss.mu.sendQueue.originalEvalTokens[WorkClassFromRaftPriority(entry.pri)] -= tokens - rss.applySendQueuePreciseSizeDeltaRaftMuAndStreamLocked(ctx, -tokens) + sendQPreciseSizeDelta -= tokens } rss.raftMu.tracker.Track(ctx, entry.id, pri, tokens) sendTokensToDeduct[WorkClassFromRaftPriority(pri)] += tokens } + if sendQPreciseSizeDelta != 0 { + rss.applySendQueuePreciseSizeDeltaRaftMuAndStreamLocked(ctx, sendQPreciseSizeDelta) + } flag := AdjNormal if directive.preventSendQNoForceFlush { flag = AdjPreventSendQueue