Skip to content

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

Merged
ti-chi-bot[bot] merged 2 commits intotikv:masterfrom
lcwangchao:codex/no_wait_ts0_master
Feb 9, 2026
Merged

txnkv: support to SetCommitWaitUntilTSOTimeout and do not wait TSO#1876
ti-chi-bot[bot] merged 2 commits intotikv:masterfrom
lcwangchao:codex/no_wait_ts0_master

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

    • Improved timeout handling for commit operations. When a zero timeout is configured, the system now immediately returns an error instead of applying a default timeout, providing stricter control over commit wait behavior.
  • Tests

    • Added test coverage for no-wait scenarios with commit operations.

Signed-off-by: Chao Wang <cclcwangchao@hotmail.com>
@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 9, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

Warning

Rate limit exceeded

@lcwangchao has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

This change modifies the CommitWaitUntilTSO timeout handling in both tests and the transaction implementation. When the timeout is set to zero, the system now immediately returns an error instead of falling back to a default behavior. The test infrastructure is updated to exercise this no-wait scenario.

Changes

Cohort / File(s) Summary
CommitWaitUntilTSO timeout implementation
txnkv/transaction/txn.go
Modified GetTimestampForCommit to treat zero timeout as an immediate error condition, replacing the previous default 1-second cap with the configured timeout value directly.
CommitWaitUntilTSO test coverage
integration_tests/option_test.go
Added setNoWait test parameter to exercise zero timeout scenario, with test case expecting error for no-wait behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes touch a critical commit path with modified timeout semantics and new error handling, but are localized to two well-scoped files with relatively few lines modified.

Possibly related PRs

Suggested labels

lgtm, approved, size/M

Suggested reviewers

  • tiancaiamao
  • cfzjywxk
  • ekexium

Poem

🐰 A rabbit hops through timeout schemes,
Where zero waits break default dreams,
No more delay, no fallback sleep—
Errors fast, commitments deep! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically refers to the main changes: adding support for SetCommitWaitUntilTSOTimeout and implementing no-wait behavior for TSO, which directly matches the PR objectives and file modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

@lcwangchao
Copy link
Contributor Author

@coderabbitai review this PR again

@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

@lcwangchao I'll review the PR again for you.

✅ 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)

373-377: ⚠️ Potential issue | 🟡 Minor

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

The comment on GetCommitWaitUntilTSOTimeout says zero means "it is not set and the default timeout should be used," but with this PR, zero now triggers an immediate ErrCommitTSLag. This should be updated to reflect the new semantics.

📝 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
+// If it returns zero, the commit will fail immediately with ErrCommitTSLag when the PD TSO lags behind the expected value.
 func (txn *KVTxn) GetCommitWaitUntilTSOTimeout() time.Duration {
 	return txn.commitWaitUntilTSOTimeout
 }

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 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

[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
Copy link

ti-chi-bot bot commented Feb 9, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-09 03:23:58.371097078 +0000 UTC m=+155254.065236918: ☑️ agreed by cfzjywxk.
  • 2026-02-09 03:28:09.769493558 +0000 UTC m=+155505.463633398: ☑️ agreed by ekexium.

@ti-chi-bot ti-chi-bot bot merged commit 6977197 into tikv:master Feb 9, 2026
13 checks passed
@lcwangchao lcwangchao deleted the codex/no_wait_ts0_master branch February 9, 2026 03:41
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.

support active-active

3 participants