-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
session: track LastCommitTS in SessionVars and check timestamps of later txns are larger #57305
base: master
Are you sure you want to change the base?
Conversation
Hi @b6g. Thanks for your PR. I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Hi @b6g. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
pkg/session/session.go
Outdated
@@ -929,6 +929,21 @@ func (s *session) CommitTxn(ctx context.Context) error { | |||
s.sessionVars.StmtCtx.MergeExecDetails(nil, commitDetail) | |||
} | |||
|
|||
if err == nil { | |||
// save CommitTS in sessionVars for invariant check | |||
// TODO: enable LastCommitTS with a session variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add a session variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in a separate PR #57313, to make review easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per discussion in #57313 (comment), we don't need a session variable.
e8df58f
to
e053b6f
Compare
5cc54f3
to
8297ca5
Compare
/ok-to-test |
4e39c69
to
31193ac
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #57305 +/- ##
================================================
+ Coverage 73.5156% 73.5884% +0.0728%
================================================
Files 1681 1681
Lines 464346 464373 +27
================================================
+ Hits 341367 341725 +358
+ Misses 102149 101830 -319
+ Partials 20830 20818 -12
Flags with carried forward coverage won't be shown. Click here to find out more.
|
fbfaf0f
to
3c7fb77
Compare
The client-go PR is merged and go.mod is updated. The PR is ready for review. PTAL Thanks! |
go.mod
Outdated
@@ -109,7 +109,7 @@ require ( | |||
github.com/tdakkota/asciicheck v0.2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run the make bazel_preapre
and upload the dependencies.
Some tests failed with
Was it because the client-go PR was just merged and it takes time to create |
1af9227
to
ef63538
Compare
The error was,
|
/test build |
d0c5266
to
e1ee91c
Compare
e1ee91c
to
9a2b35a
Compare
Merge conflicts are resolved. PTAL |
pkg/session/session.go
Outdated
logutil.BgLogger().Panic("check lastCommitTS failed", | ||
zap.Uint64("sessionLastCommitTS", s.sessionVars.LastCommitTS), | ||
zap.Uint64("txnLastCommitTS", s.txn.lastCommitTS), | ||
zap.String("sql", s.sessionVars.StmtCtx.OriginalSQL), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zap.String("sql", s.sessionVars.StmtCtx.OriginalSQL), | |
zap.String("sql", redact.String(s.sessionVars.EnableRedactLog, s.sessionVars.StmtCtx.OriginalSQL)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also for the other log
pkg/kv/kv.go
Outdated
@@ -251,6 +251,8 @@ type Transaction interface { | |||
IsReadOnly() bool | |||
// StartTS returns the transaction start timestamp. | |||
StartTS() uint64 | |||
// CommitTS returns the transaction commit timestamp. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// CommitTS returns the transaction commit timestamp. | |
// CommitTS returns the commit timestamp of the already committed transaction, or zero if it's not committed yet. |
@@ -268,6 +270,10 @@ func (p *baseTxnContextProvider) getTxnStartTS() (uint64, error) { | |||
return txn.StartTS(), nil | |||
} | |||
|
|||
func (p *baseTxnContextProvider) usePresetStartTS() bool { | |||
return p.constStartTS != 0 || p.sctx.GetSessionVars().SnapshotTS != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this: SnapshotTS != 0
should imply a staleness txn ctx provider? It won't hurt though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure either. That's why I named it Preset
. The point is we don't check StartTS if it is preset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, considering various historical features (e.g., tidb_snapshot
, stale read, etc.), careful attention is required to ensure accurate and comprehensive condition checks. Any oversight could lead to unexpected tidb-server panics.
An alternative approach is to reverse the logic—confirming that the current transaction is activated by a PD-allocated timestamp before proceeding with the check. This seems to be a more reliable method.
like
- if !usePresetStartTS
+ if activiatedByPDAllocatedTS
@b6g: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
708731b
to
60a0008
Compare
[FORMAT CHECKER NOTIFICATION] Notice: To remove the For example:
📖 For more info, you can check the "Contribute Code" section in the development guide. |
ping |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ekexium The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
The PR is good to merge as is. We could improve the |
I think I need another approval |
@Benjamin2037 @yudongusa |
What problem does this PR solve?
Issue Number: close #57165
Problem Summary:
This PR checks the invariant that timestamps of transactions in a session should increase monotonically.
It saves the timestamp of the last transaction in
SessionVars
, after the transaction is committed. The saved timestamp is compared with thestart_ts
and thecommit_ts
of the next transaction.This PR depends on the TiKV client-go PR, tikv/client-go#1489, which exports
commit_ts
of the transaction.What changed and how does it work?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.