Skip to content

tests: scope failpoint lock counts to each test's own keys (fixes #525, mitigates #516)#551

Open
eduralph wants to merge 1 commit into
tikv:masterfrom
getwyrd:fix/failpoint-lock-residue
Open

tests: scope failpoint lock counts to each test's own keys (fixes #525, mitigates #516)#551
eduralph wants to merge 1 commit into
tikv:masterfrom
getwyrd:fix/failpoint-lock-residue

Conversation

@eduralph

@eduralph eduralph commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

The txn_cleanup_* failpoint tests count locks with a whole-keyspace scan (count_locks / wait_for_locks_count over ..). txn_cleanup_locks_batch_size stubs cleanup via the before-cleanup-locks failpoint and leaves its locks in place — and since they're async-commit locks, they resolve in the background and drain at an unpredictable rate. A later serial test's unbounded scan then catches the still-draining residue and over-counts — the flaky 575 vs 512 / 513 vs 512 in #525.

Fix (test-only)

  • Add count_locks_of / wait_for_locks_count_of that count only the caller's own keys, making the assertions immune to residual locks from other tests.
  • Switch all txn_cleanup_* count assertions to the scoped variants.
  • Have txn_cleanup_locks_batch_size resolve its own locks before returning, so it no longer seeds residue for the next serial test.
  • Remove the now-unused whole-keyspace wrappers.

No client (src/) change.

Fixes #525.

Scope note: this does not address #516 (the txn_cleanup_2pc_locks 600s timeout). An earlier revision of this description suggested it might, by removing residue that amplifies cleanup_locks — that reasoning was wrong: txn_cleanup_2pc_locks runs first in the serial suite (it is consistently reported as ( 1/54 )), so no residue from the other cleanup tests can reach it. #516 is a separate, still-undiagnosed stall and is left untouched here.

Testing

Ran the suite repeatedly against a local multi-region cluster (MULTI_REGION=1, the aggressive-split config/tikv.toml) — stable across 10+ runs at ~5s each; the previously-observed count drift does not recur. make check clean.

Summary by CodeRabbit

  • Tests
    • Improved transaction cleanup and lock-resolution test reliability by checking locks only for the keys involved in each test.
    • Reduced flaky assertions caused by asynchronous lock draining between tests.
    • Added explicit cleanup handling to ensure locks are fully released before test completion.

@ti-chi-bot ti-chi-bot Bot added the dco-signoff: yes Indicates the PR's author has signed the dco. label Jul 18, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 18, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign coocood for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added contribution This PR is from a community contributor. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 18, 2026
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@eduralph, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b73c3f22-7892-4f79-b438-8125067a5c35

📥 Commits

Reviewing files that changed from the base of the PR and between 5cc7b3f and dde652f.

📒 Files selected for processing (1)
  • tests/failpoint_tests.rs
📝 Walkthrough

Walkthrough

Failpoint transaction tests now scope lock counting and polling to their generated keys. Cleanup scenarios also perform explicit cleanup where needed and verify key-specific committed or rolled-back results.

Changes

Failpoint lock assertions

Layer / File(s) Summary
Add key-scoped lock helpers
tests/failpoint_tests.rs
Removes whole-keyspace lock helpers and adds helpers to count locks for supplied keys and wait for the scoped count to reach an expected value.
Update transaction cleanup tests
tests/failpoint_tests.rs
Replaces whole-keyspace lock checks with key-scoped assertions, adds explicit cleanup in one scenario, and verifies committed or rolled-back state for the test keys.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • tikv/client-rust#547: Adds failpoint rollback-after-prewrite tests that also assert pessimistic transaction locks are cleared.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: scoping failpoint lock counts to each test’s own keys.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The txn_cleanup_* failpoint tests counted locks with a whole-keyspace scan
(count_locks / wait_for_locks_count over `..`). Because txn_cleanup_locks_batch_size
stubs cleanup via the before-cleanup-locks failpoint and leaves its locks in place —
and those are async-commit locks, which resolve in the background and drain at an
unpredictable rate — a later serial test's unbounded scan would catch the still-draining
residue and over-count (flaky '575 vs 512' / '513 vs 512'; tikv#525). The same residue
enlarges cleanup_locks' cross-region work and can push it past the CI timeout (tikv#516).

Fix, test-only:
- Add count_locks_of / wait_for_locks_count_of that count only the caller's own keys,
  making the assertions immune to residual locks from other tests.
- Switch all txn_cleanup_* count assertions to the scoped variants.
- Have txn_cleanup_locks_batch_size resolve its own locks before returning, so it no
  longer seeds residue for the next serial test.
- Remove the now-unused whole-keyspace wrappers.

Suite is stable across repeated runs locally; no client (src/) change.

Signed-off-by: Eduard R. <eduard@ralphovi.net>
@eduralph
eduralph force-pushed the fix/failpoint-lock-residue branch from 5cc7b3f to dde652f Compare July 22, 2026 22:23
@eduralph

Copy link
Copy Markdown
Contributor Author

@pingyu - ping for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. dco-signoff: yes Indicates the PR's author has signed the dco. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: "txn_cleanup_locks_batch_size" is flaky

1 participant