镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

request: retry on MaxTimestampNotSynced - #580

Open
ariesdevil wants to merge 1 commit into
tikv:masterfrom
ariesdevil:fix/retry-max-ts-not-synced
Open

ariesdevil wants to merge 1 commit into
tikv:masterfrom
ariesdevil:fix/retry-max-ts-not-synced

Conversation

@ariesdevil

@ariesdevil ariesdevil commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

After a leader transfer, split or merge, the new leader rejects async-commit and 1PC prewrites with MaxTimestampNotSynced until it has synced max_ts from PD. This usually takes only a few milliseconds.

client-go treats this error as retryable: onRegionError backs off with BoMaxTsNotSynced (2ms to 500ms) and resends the request. This client returned the error to the caller instead, so a commit with use_async_commit() or try_one_pc() failed whenever its prewrite hit that window.

This PR backs off with the region backoff and resends, like client-go. TiKV checks max_ts before it writes anything, so resending is safe, even at commit points. If the backoff runs out, the region error is returned unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Operations encountering a temporary timestamp synchronization issue now retry instead of failing immediately, improving the chance that they complete successfully.
    • If retries are exhausted, the original region error is reported.

After a leader transfer, split or merge, the new leader rejects
async-commit and 1PC prewrites with MaxTimestampNotSynced until it has
synced max_ts from PD, which usually takes milliseconds.
handle_region_error returned the error to the caller, so a transaction
committed with use_async_commit or try_one_pc failed whenever its
prewrite hit that window.

TiKV checks the sync status before writing anything, so the rejection is
definitive and the cached leader remains valid. Back off with the region
backoff and resend, as client-go does with BoMaxTsNotSynced. This applies
to commit points too: only an UndeterminedResult is terminal for them.

Signed-off-by: Yijun Zhao <ariesdevil77@gmail.com>
@ti-chi-bot ti-chi-bot Bot added dco-signoff: yes Indicates the PR's author has signed the dco. contribution This PR is from a community contributor. labels Nov 2, 2026
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d2b3a8e8-cdea-4895-bc32-774c563aa3c7
Commits

Reviewing files that changed from the base of the PR and between 1b883bf and 03139c8.

Files selected for processing: 1
  • src/request/plan.rs

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

The request plan now retries MaxTimestampNotSynced without invalidating the cached leader. Tests cover success after retries and return of the region error when retries are exhausted.

Changes: Retry handling

Layer / File(s) Summary
Retry classification and validation
src/request/plan.rs
MaxTimestampNotSynced follows the retry path, while RaftEntryTooLarge remains terminal. Tests verify success after two retries and error return after three configured retries.

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

Change: Bug fix

Suggested reviewers: eduralph

Merge Risk: Minimal · up to 03139

No actionable merge-blocking risk is established; the new retry behavior follows the available protocol contract.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: retrying requests after MaxTimestampNotSynced errors.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clippy (1.99.0)

Clippy execution failed

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

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 2, 2026
@ariesdevil

Copy link
Copy Markdown
Contributor Author

@ekexium @pingyu PTAL.

@ekexium
ekexium self-requested a review November 2, 2026 08:16
@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 2, 2026
@ti-chi-bot

ti-chi-bot Bot commented Nov 2, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ekexium

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

The pull request process is described 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 commented Nov 2, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-11-02 10:36:45.609673346 +0000 UTC m=+490130.234823608: ☑️ agreed by ekexium.

@ti-chi-bot ti-chi-bot Bot added the approved label Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved contribution This PR is from a community contributor. dco-signoff: yes Indicates the PR's author has signed the dco. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. 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.

2 participants