Skip to content

Fix flaky test test_temporary_lock_quota_is_retained_across_rounds - #126965

Merged
Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-kafka-tmp-lock-quota-run-length
Oct 22, 2026
Merged

Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-kafka-tmp-lock-quota-run-length

Conversation

@groeneai

@groeneai groeneai commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #121478

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not required (CI fix).

Description

test_storage_kafka/test_multi_consumer_quota.py::test_temporary_lock_quota_is_retained_across_rounds, added in #121478, fails in Integration tests (arm_binary, 2/4) with No consumer kept a non-zero temporary-lock quota for 4 consecutive rounds. It failed 7 times, never on amd: 6 times on 5 unrelated PRs and once on master in Integration tests (arm_binary, distributed plan, 2/4) (master, #125968, #118942, #126772).

The four kafka_tmp_r* tables run on one server, start consuming in the same query and use the same settings, so their slow-path rounds fire together. Each round releases its temporary locks before get_metadata, which takes 150-560 ms on that runner, so every round re-contests the three leftover partitions. The first reader grows its quota to 2, the second takes 1, the rest drop to 0, and each quota cycles 1, 2, 0. All three leftovers are still taken in every round, so lockTemporaryLocksLocked works as intended. Only the threshold of 4 assumes that rounds do not overlap.

The threshold is lowered to 2. The old inverted shrink condition reset a quota of 1 to 0 in the next round, so it can never produce two consecutive non-zero quotas, and the test still separates the two behaviours. All seven recorded failures already contain a run of 2.

Validation: 10 separate runs pass, each in its second round. With the old shrink condition restored in KeeperHandlingConsumer.cpp, 3 of 3 runs fail, with every quota alternating 1, 0.


Workflow [PR]
Sync PR [sync-upstream/pr/126965]

Version info

  • Merged into: 26.11.1.493-master (included in 26.11 and later)

The test from ClickHouse#121478 fails in `Integration tests (arm_binary, 2/4)` with
"No consumer kept a non-zero temporary-lock quota for 4 consecutive rounds"
(6 failures on 5 unrelated PRs, none on master or amd).

The four `kafka_tmp_r*` tables share one server and one schedule, so their
slow-path rounds fire together. Each round releases its temporary locks before
`get_metadata`, which takes 150-560 ms on that runner, so every round
re-contests the three leftover partitions: the first reader grows its quota to
2, the second takes 1, the others drop to 0, and each quota cycles 1, 2, 0.
`lockTemporaryLocksLocked` behaves as specified (all leftovers are taken in
every round); only the threshold of 4 assumed non-overlapping rounds.

Lower the threshold to 2. The old inverted shrink condition reset a quota of 1
to 0 in the next round, so it can never produce two consecutive non-zero
quotas, and the test still separates the two behaviours. All six recorded CI
failures already contain a run of 2. Locally 10 separate runs pass, and with
the old condition restored in `KeeperHandlingConsumer.cpp` 3 of 3 runs fail
with every quota alternating 1, 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (3 nits).

# Sev Finding Verdict Evidence / action
1 💡 Failure count in the description was stale: a 7th failure landed on master (arm_binary, distributed plan, 2/4, 88a5db8) AGREE, fixed in the description Its quota sequences reach a run of 2 in round 2, so the new threshold passes it
2 💡 The test docstring still says the fixed code "converges to 1"; CI shows 1, 2, 0 cycles and x86 reaches 3 Noted, not blocking Pre-existing sentence; its point (the absolute value is not asserted) still holds
3 💡 At threshold 2 the log-based oracle is not robust to two runs of the test sharing one server log DISAGREE Not reachable in CI: no --count is passed, the flaky check gives each worker its own cluster with a fresh instance dir (helpers/cluster.py:3889-3897), and logs rotate at 1000M

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261020-142000

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, from recorded CI data: the test's own longest_nonzero_run on the quota sequences of all 6 CI failures gives FAIL 6/6 at threshold 4, PASS 6/6 at 2. Not reproducible on local x86 (base test 10/10 green, as on amd CI).
b Root cause explained? The four replicas' rounds fire together; each releases its temporary locks before a 150-560 ms get_metadata, so every round re-contests the three leftover partitions and quotas rotate 1, 2, 0. The threshold of 4 assumes non-overlapping rounds.
c Fix matches root cause? Yes. The threshold is lowered to the largest run the fixed code guarantees under overlapping rounds (2), which is also the smallest run the old code can never produce.
d Test intent preserved / new tests added? Yes. With the pre-#121478 shrink condition restored, 3 of 3 runs fail with No consumer kept a non-zero temporary-lock quota for 2 consecutive rounds, every quota alternating 1, 0.
e Both directions demonstrated? Yes. CI data: threshold 4 fails 6/6, threshold 2 passes 6/6. Locally: 10/10 separate runs pass on master, 3/3 fail on the mutant.
f Fix is general across code paths? N/A (test-only change). No other test reads the constant.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only change).
h Backward compatible? (maintainer-approved exception only) N/A (test-only change).
i Invariants and contracts preserved? Yes. The assertion is unchanged ("some consumer keeps a non-zero quota for one more round"). Only its run length changes, and all three uses of the constant stay consistent.

Session id: cron:clickhouse-impl-slot-40:20261020-123800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @kssenii, could you review this and add the can be tested label so CI runs? The new StorageKafka2 test asserted a temporary-lock quota stays non-zero for 4 consecutive rounds, but on arm the four co-located replicas' rounds overlap and re-contest the leftover partitions every round (quotas cycle 1, 2, 0), so the threshold is lowered to 2, which the old inverted shrink condition can never reach.

@clickhouse-gh

clickhouse-gh Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [214b097]

Summary: ✅


AI Review

Summary

The PR lowers REQUIRED_NONZERO_RUN from four rounds to two in the Kafka temporary-lock quota regression test, accommodating overlapping replica polling rounds. Two consecutive non-zero quotas still distinguish the fixed implementation from the original inverted shrink condition. The linked CI failure sequences and reported positive and mutation runs support the change. No actionable findings.

Final Verdict

Status: ✅ Approve

@Algunenano
Algunenano added this pull request to the merge queue Oct 21, 2026
Merged via the queue into ClickHouse:master with commit 81ae09f Oct 22, 2026
526 of 528 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
@clickhouse-gh clickhouse-gh Bot added comp-kafka Kafka table engine: consumers and producers on librdkafka, the Kafka2 engine that keeps offsets i... and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-kafka Kafka table engine: consumers and producers on librdkafka, the Kafka2 engine that keeps offsets i... pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants