Skip to content

txnkv: support to SetCommitWaitUntilTSOTimeout and do not wait TSO#1875

Merged
ti-chi-bot[bot] merged 2 commits intotikv:tidb-8.5from
lcwangchao:no_wait_ts0
Feb 9, 2026
Merged

txnkv: support to SetCommitWaitUntilTSOTimeout and do not wait TSO#1875
ti-chi-bot[bot] merged 2 commits intotikv:tidb-8.5from
lcwangchao:no_wait_ts0

Conversation

@lcwangchao
Copy link
Contributor

@lcwangchao lcwangchao commented Feb 9, 2026

Summary

close #1854

This PR adds explicit no-wait behavior for commit-wait TSO checks.

When SetCommitWaitUntilTSO(...) is enabled, users can now set
SetCommitWaitUntilTSOTimeout(0) to fail immediately if PD TSO is behind the expected commit-wait timestamp, instead of waiting.

Motivation

In active-active replication scenarios, some callers prefer a fast-fail path rather than waiting for TSO catch-up. A zero timeout should represent this intent clearly.

Behavior Change

  • commitWaitUntilTSOTimeout > 0: keep existing bounded-wait behavior.
  • commitWaitUntilTSOTimeout == 0: return ErrCommitTSLag immediately on the first lag check.
  • Default behavior is unchanged because the transaction default timeout remains 1s.

Tests

Added integration coverage in TestSetCommitWaitUntilTSO for a new "no wait" case:

  • enable commit-wait TSO;
  • set timeout to 0;
  • mock lagging TSO;
  • verify the commit path returns error immediately.

Summary by CodeRabbit

  • Bug Fixes

    • Revised commit wait timeout handling to strictly enforce configured timeout values, immediately returning an error when timeout is not set.
  • Tests

    • Added test coverage for no-wait transaction commit scenarios.

@ti-chi-bot ti-chi-bot bot added the dco-signoff: yes Indicates the PR's author has signed the dco. label Feb 9, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The changes modify timeout handling in the commit-wait-until-TSO flow. When the timeout is zero, GetTimestampForCommit now immediately returns an error instead of using a default wait duration. A corresponding integration test validates this zero-timeout behavior.

Changes

Cohort / File(s) Summary
Commit Wait Timeout Logic
txnkv/transaction/txn.go
Replaced default 1-second maxSleep with direct use of commitWaitUntilTSOTimeout. When timeout is zero, immediately returns ErrCommitTSLag error instead of attempting wait.
Test Options and Scenarios
integration_tests/option_test.go
Added setNoWait test flag to options struct. Introduced "no wait" test case that forces SetCommitWaitUntilTSOTimeout to 0 and validates error handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

lgtm, approved, size/M

Suggested reviewers

  • tiancaiamao
  • cfzjywxk
  • ekexium

Poem

🐰 A timeout of zero means wait not at all,
No slumber, no linger, just answer the call!
The test catches errors with precision so tight,
Active-active awaits—this logic's just right! ✨

🚥 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 accurately describes the main changes: adding support for SetCommitWaitUntilTSOTimeout and implementing no-wait behavior when timeout is set to zero.
Linked Issues check ✅ Passed The PR implements explicit no-wait mode for commit-wait TSO checks via SetCommitWaitUntilTSOTimeout(0), enabling fast-fail behavior for active-active replication scenarios as required by issue #1854.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing SetCommitWaitUntilTSOTimeout support and no-wait behavior. The test additions and transaction logic modifications align with the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@ti-chi-bot ti-chi-bot bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 9, 2026
Signed-off-by: Chao Wang <cclcwangchao@hotmail.com>
@lcwangchao
Copy link
Contributor Author

/retest

@lcwangchao
Copy link
Contributor Author

@coderabbitai review this PR again

@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

@lcwangchao, I'll review the changes in this PR again.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
txnkv/transaction/txn.go (1)

320-324: ⚠️ Potential issue | 🟡 Minor

Stale doc comment: zero now means "no wait", not "use default".

The comment on GetCommitWaitUntilTSOTimeout says zero means "not set and the default timeout should be used," but with this PR, zero now means immediate failure. This will confuse future readers.

Suggested fix
-// GetCommitWaitUntilTSOTimeout returns the timeout to wait for the commit tso reach the expected value.
-// If it returns zero, it means it is not set and the default timeout should be used
+// GetCommitWaitUntilTSOTimeout returns the timeout to wait for the commit TSO to reach the expected value.
+// If it returns zero, the commit will fail immediately with ErrCommitTSLag when PD TSO lags.
🧹 Nitpick comments (1)
txnkv/transaction/txn.go (1)

1886-1917: Duplicate comment block and clean logic for the zero-timeout path look correct.

Two issues in this segment:

  1. The comment block at lines 1886–1888 is duplicated verbatim at lines 1907–1909. The first occurrence (1886–1888) is now orphaned — it no longer sits adjacent to the maxSleep assignment. Please remove one of the two.

  2. The zero-timeout fast-fail logic (lines 1910–1917) is correct and aligns with the PR objective.

Remove the duplicate comment block
-	// maxSleep is the maximum time we are allowed to wait for the expected commit TS.
-	// It is 1 second by default to avoid infinite blocking but can be overridden by commitWaitUntilTSOTimeout.
-	// If the TSO drift is larger than the maxSleep, return error directly.
 	start := time.Now()

Signed-off-by: Chao Wang <cclcwangchao@hotmail.com>
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 9, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 9, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, 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 added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 9, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 9, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-09 03:23:47.001017572 +0000 UTC m=+155242.695157422: ☑️ agreed by cfzjywxk.
  • 2026-02-09 03:27:59.424904287 +0000 UTC m=+155495.119044137: ☑️ agreed by ekexium.

@lcwangchao
Copy link
Contributor Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 621e353 into tikv:tidb-8.5 Feb 9, 2026
16 of 17 checks passed
@lcwangchao lcwangchao deleted the no_wait_ts0 branch February 9, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants