-
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
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 72.9819% 73.4547% +0.4727%
================================================
Files 1693 1693
Lines 467972 468042 +70
================================================
+ Hits 341535 343799 +2264
+ Misses 105410 103227 -2183
+ Partials 21027 21016 -11
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 |
pkg/session/session.go
Outdated
zap.Uint64("txnLastCommitTS", s.txn.lastCommitTS), | ||
zap.String("sql", redact.String(s.sessionVars.EnableRedactLog, s.sessionVars.StmtCtx.OriginalSQL)), | ||
) | ||
return kv.ErrAssertionFailed |
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.
kv.ErrAssertionFailed
is an error contains key info.
Without any argument, it'll be confusing.
[tikv:8141]assertion failed: key: %s, assertion: %s, start_ts: %v, existing start ts: %v, existing commit ts: %v
Consider just create error by errors.Errorf(...)
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.
@b6g PTAL
pkg/session/test/txn/txn_test.go
Outdated
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("create table t(id int)") | ||
ts := oracle.GoTimeToTS(time.Now().Add(time.Minute)) |
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.
Better using a ts from timestamp oracle.
ts := oracle.GoTimeToTS(time.Now().Add(time.Minute)) | |
currentTS, err := store.GetOracle().GetTimestamp(context.Background(), &oracle.Option{TxnScope: oracle.GlobalTxnScope}) | |
ts := oracle.GoTimeToTS(oracle.GetTimeFromTS(currentTS).Add(time.Minute)) |
pkg/sessiontxn/isolation/base.go
Outdated
zap.Uint64("startTS", sessVars.TxnCtx.StartTS), | ||
zap.String("sql", redact.String(sessVars.EnableRedactLog, sessVars.StmtCtx.OriginalSQL)), | ||
) | ||
return nil, kv.ErrAssertionFailed |
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.
Same to the checking of commitTS, use errors.Errorf(...)
@@ -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.
Updated. PTAL. Need another approval to merge. Thanks! |
88102cb
to
85e0179
Compare
/retest |
2 similar comments
/retest |
/retest |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cfzjywxk, ekexium, you06, yudongusa 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 |
/retest |
@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. |
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.