Repository navigation
Fix priority backlog acknowledgement after expired tasks - #12595
Conversation
b0f5594 to
36d12bd
Compare
|
Claude finished @cbsandeep10's task in 47s —— View job Reviewed 2 files, 2 findings. |
| // but where the rangeid has moved higher, to prevent excessive reads on the next load. | ||
| if tr.outstandingTasks.Empty() { | ||
| // Expired tasks advance readLevel without entering outstandingTasks. Once no tasks | ||
| // remain outstanding, they and the empty range can be acknowledged. |
There was a problem hiding this comment.
nit (textual): This change looks correct to me. It's safe because getTasksPump is the only thing that moves readLevel after init, and the stale-read guard above it still runs first. But the new comment drops the explanation of why acking [readLevel, newReadLevel] is safe. That reasoning was the most useful part of the old comment. Consider keeping it, e.g.:
// This is called after reading the range (tr.readLevel, newReadLevel] and finding no tasks
// (the stale-read check above guards against signalNewTasks having moved readLevel). Every
// task at or below tr.readLevel was either loaded into outstandingTasks or dropped as
// expired/already-acked, so if nothing is outstanding, everything up to newReadLevel is acked.
// This lets us advance the ack level on an idle queue whose range ID has moved higher.There was a problem hiding this comment.
Updated the comment.
| t := s.T() | ||
| s := &BacklogManagerTestSuite{} | ||
| s.SetT(t) | ||
| s.SetupTest() |
There was a problem hiding this comment.
nit (testing): Building a new BacklogManagerTestSuite inside s.Run and shadowing s doesn't match how the rest of this file is written. It also throws away the outer SetupTest state that was already built for this test, and it silently resets fields like fairness. That's harmless today because of the skip, but easy to break later. Testify's s.Run already points s.T() at the subtest, so calling s.SetupTest() directly gives the same isolation with less code:
| t := s.T() | |
| s := &BacklogManagerTestSuite{} | |
| s.SetT(t) | |
| s.SetupTest() | |
| s.SetupTest() |
Another option is to split this into two top-level tests (..._ExpiredTail and ..._ExpiredTailWithGap).
There was a problem hiding this comment.
Updated the test.
f4bd6a9 to
60d2a59
Compare
| {name: "no_gap", maxReadLevelOffset: 2}, | ||
| {name: "with_gap", maxReadLevelOffset: 100}, | ||
| } { | ||
| s.Run(tc.name, func() { |
There was a problem hiding this comment.
slight preference for the style where these are two suite-level tests and they pass a parameter into a shared helper. but it's fine if you want to leave it
Advance the priority backlog reader's acknowledgement level across scanned ranges when no tasks remain outstanding, including when expired tasks have moved the read level ahead of the acknowledgement level. Preserve the stale-read guard and protection for unfinished tasks. Add deterministic regressions for expired tails with and without trailing ID gaps. Extend the existing drain test to verify that scanning a gap does not advance acknowledgement or reset the backlog count while tasks remain unfinished. Enable the expired-only priority backlog test. Fixes #12472. If valid tasks finish before the reader scans an expired tail, or if all tasks have expired, the priority reader can leave acknowledgement stuck until another task is written and completed. Expired tasks advance the read level without entering the outstanding-task map, so requiring equal acknowledgement and read levels prevents further acknowledgement. This affects production queue behavior: the persisted acknowledgement level stays stale, expired tasks cannot be garbage-collected, and the approximate backlog count is not reset. Advancing acknowledgement when no tasks remain outstanding lets the queue move past expired tasks without waiting for a new task. - [x] covered by existing tests - [x] added new unit test(s) - Passed 100 race-enabled local repetitions of the priority backlog drain, gap-handling, expired-task, and out-of-order completion tests using `disable_grpc_modules,test_dep` build tags. - Passed both complete backlog manager suites (priority and fair) with race detection. - Earlier CI stress run: [100 repetitions with race detection for the priority backlog regression tests](https://github.com/temporalio/temporal/actions/runs/38959302448). - Passed `make lint-code-fast` with zero issues. Full-package race validation also encountered a pre-existing backlog-count assertion in `TestMatchingEngine_Fair_Suite/TestMultipleWorkersLesserNumberOfPollersThanTasksDBErrors`; it reproduced 15/20 times on unchanged base commit `b88a7ebdd`. (cherry picked from commit 4fa3ed4)
What changed?
Advance the priority backlog reader's acknowledgement level across scanned ranges when no tasks remain outstanding, including when expired tasks have moved the read level ahead of the acknowledgement level. Preserve the stale-read guard and protection for unfinished tasks.
Add deterministic regressions for expired tails with and without trailing ID gaps. Extend the existing drain test to verify that scanning a gap does not advance acknowledgement or reset the backlog count while tasks remain unfinished. Enable the expired-only priority backlog test.
Why?
Fixes #12472.
If valid tasks finish before the reader scans an expired tail, or if all tasks have expired, the priority reader can leave acknowledgement stuck until another task is written and completed. Expired tasks advance the read level without entering the outstanding-task map, so requiring equal acknowledgement and read levels prevents further acknowledgement.
This affects production queue behavior: the persisted acknowledgement level stays stale, expired tasks cannot be garbage-collected, and the approximate backlog count is not reset. Advancing acknowledgement when no tasks remain outstanding lets the queue move past expired tasks without waiting for a new task.
How did you test it?
disable_grpc_modules,test_depbuild tags.make lint-code-fastwith zero issues.Full-package race validation also encountered a pre-existing backlog-count assertion in
TestMatchingEngine_Fair_Suite/TestMultipleWorkersLesserNumberOfPollersThanTasksDBErrors; it reproduced 15/20 times on unchanged base commitb88a7ebdd.