Skip to content

Commit

Permalink
rac2: fix incorrect assertion when send-queue becomes empty
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sumeerbhola committed Nov 16, 2024
1 parent 7e17180 commit c173b5b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c173b5b

Please sign in to comment.