Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export commitTS of KVTxn #1489

Merged
merged 3 commits into from
Nov 27, 2024
Merged

Export commitTS of KVTxn #1489

merged 3 commits into from
Nov 27, 2024

Conversation

b6g
Copy link
Contributor

@b6g b6g commented Nov 11, 2024

Ref: pingcap/tidb#57165
Close: #1488

Export KVTxn.CommitTS to make it available in TiDB.

Copy link

ti-chi-bot bot commented Nov 11, 2024

Welcome @b6g!

It looks like this is your first PR to tikv/client-go 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to tikv/client-go. 😃

@ti-chi-bot ti-chi-bot bot added dco-signoff: no Indicates the PR's author has not signed dco. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 11, 2024
@b6g b6g force-pushed the b6g/tsoinvariant1 branch from 337f334 to fdb6200 Compare November 11, 2024 03:12
@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. and removed dco-signoff: no Indicates the PR's author has not signed dco. labels Nov 11, 2024
@b6g b6g force-pushed the b6g/tsoinvariant1 branch from fdb6200 to be41b52 Compare November 11, 2024 09:29
@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 11, 2024
@b6g b6g force-pushed the b6g/tsoinvariant1 branch from be41b52 to da62319 Compare November 11, 2024 22:03
@ti-chi-bot ti-chi-bot bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 11, 2024
@b6g
Copy link
Contributor Author

b6g commented Nov 17, 2024

ping

@you06 you06 self-requested a review November 25, 2024 05:29
Copy link
Contributor

@you06 you06 left a comment

Choose a reason for hiding this comment

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

Export CommitTS LGTM.

I also take a look at pingcap/tidb#57305 which guarantee txn.commit_ts > txn.start_ts and txn.commit_ts > prev_txn.commit_ts in session.

To ensure the start_ts is greater than any exist commit_ts cross sessions, we may have a field last_commit_ts in store level and set it to the latest commit_ts. Each time, we fetch start_ts like this:

last_commit_ts = store.last_commit_ts.Load()
start_ts = oracle.GetTSO()
if start_ts < last_commit_ts {
  panic(...)
}

This may be another task, @cfzjywxk what's your idea.

@@ -1700,6 +1700,10 @@ func (txn *KVTxn) StartTS() uint64 {
return txn.startTS
}

func (txn *KVTxn) CommitTS() uint64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

There are still some tests using txn.GetCommitTS in 1pc_test.go.

cd integration_tests && go test ./...

Copy link
Contributor

Choose a reason for hiding this comment

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

@you06 Seems to be an enhancement to add a check before and after the ts allocation, how about filing an issue for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The integration_tests are fixed.

Sounds a good idea to check store's last_commit_ts is smaller than start_ts, because store's last_commit_ts is not directly allocated from pd.

Copy link
Contributor

Choose a reason for hiding this comment

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

how about filing an issue for it?

@cfzjywxk It's mentioned in pingcap/tidb#57165 IMO.

In theory, all read requests occurring after the write transaction should use a read_ts greater than the previous known transaction's commit_ts.

@ti-chi-bot ti-chi-bot bot added dco-signoff: no Indicates the PR's author has not signed dco. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed dco-signoff: yes Indicates the PR's author has signed the dco. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 25, 2024
@b6g b6g force-pushed the b6g/tsoinvariant1 branch from f47074d to 22f2749 Compare November 25, 2024 17:36
@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. and removed dco-signoff: no Indicates the PR's author has not signed dco. labels Nov 25, 2024
@b6g b6g force-pushed the b6g/tsoinvariant1 branch from 22f2749 to e689dcf Compare November 25, 2024 18:45
@@ -1704,6 +1704,10 @@ func (txn *KVTxn) StartTS() uint64 {
return txn.startTS
}

func (txn *KVTxn) CommitTS() uint64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (txn *KVTxn) CommitTS() uint64 {
// CommitTS returns the commit timestamp of the already committed transaction, zero if it's not committed yet.
func (txn *KVTxn) CommitTS() uint64 {

Exported functions need explicity comments from the ci & lint.

@ti-chi-bot ti-chi-bot bot added dco-signoff: no Indicates the PR's author has not signed dco. and removed dco-signoff: yes Indicates the PR's author has signed the dco. labels Nov 26, 2024
Signed-off-by: Bin Zhang <[email protected]>
@b6g b6g force-pushed the b6g/tsoinvariant1 branch from a97868a to 0e396b2 Compare November 26, 2024 17:06
@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. and removed dco-signoff: no Indicates the PR's author has not signed dco. labels Nov 26, 2024
Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Nov 27, 2024
@cfzjywxk cfzjywxk requested a review from you06 November 27, 2024 01:47
@b6g
Copy link
Contributor Author

b6g commented Nov 27, 2024

The Integration Test failed because of timeout. Is it expected? How to trigger it to re-run?

@b6g
Copy link
Contributor Author

b6g commented Nov 27, 2024

@you06 Can I get another approval to merge the PR? Thanks!

@ti-chi-bot ti-chi-bot bot added the lgtm label Nov 27, 2024
Copy link

ti-chi-bot bot commented Nov 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfzjywxk, you06

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

The pull request process is described here

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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 27, 2024
Copy link

ti-chi-bot bot commented Nov 27, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-27 01:46:30.714494546 +0000 UTC m=+600978.334149056: ☑️ agreed by cfzjywxk.
  • 2024-11-27 07:12:48.185389314 +0000 UTC m=+620555.805043827: ☑️ agreed by you06.

@ti-chi-bot ti-chi-bot bot merged commit 89643b0 into tikv:master Nov 27, 2024
12 checks passed
@cfzjywxk
Copy link
Contributor

@b6g
Thanks for the contribution!
For the tidb pr, besides the checking within the same session perhaps we could consider @you06 has proposed

last_commit_ts = store.last_commit_ts.Load()
start_ts = oracle.GetTSO()
if start_ts < last_commit_ts {
  panic(...)
}

checking the last commit timestamp after fetching a new ts.

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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export CommitTS of KVTxn
3 participants