-
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?
Changes from all commits
ba7df89
db72d08
abf573d
6f87b7f
1f8567a
60a0008
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,14 @@ import ( | |
"github.com/pingcap/tidb/pkg/store/driver/txn" | ||
"github.com/pingcap/tidb/pkg/table/temptable" | ||
"github.com/pingcap/tidb/pkg/tablecodec" | ||
"github.com/pingcap/tidb/pkg/util/logutil" | ||
"github.com/pingcap/tidb/pkg/util/redact" | ||
"github.com/pingcap/tidb/pkg/util/tableutil" | ||
"github.com/pingcap/tidb/pkg/util/tracing" | ||
tikvstore "github.com/tikv/client-go/v2/kv" | ||
"github.com/tikv/client-go/v2/oracle" | ||
"github.com/tikv/client-go/v2/txnkv/transaction" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// baseTxnContextProvider is a base class for the transaction context providers that implement `TxnContextProvider` in different isolation. | ||
|
@@ -268,6 +271,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 commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure either. That's why I named it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, considering various historical features (e.g., 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
|
||
} | ||
|
||
// ActivateTxn activates the transaction and set the relevant context variables. | ||
func (p *baseTxnContextProvider) ActivateTxn() (kv.Transaction, error) { | ||
if p.txn != nil { | ||
|
@@ -304,6 +311,15 @@ func (p *baseTxnContextProvider) ActivateTxn() (kv.Transaction, error) { | |
sessVars.SetInTxn(true) | ||
} | ||
|
||
// verify start_ts is later than any previous commit_ts in the session | ||
dveeden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if !p.usePresetStartTS() && sessVars.LastCommitTS > 0 && sessVars.LastCommitTS > sessVars.TxnCtx.StartTS { | ||
logutil.BgLogger().Panic("check session lastCommitTS failed", | ||
zap.Uint64("lastCommitTS", sessVars.LastCommitTS), | ||
zap.Uint64("startTS", sessVars.TxnCtx.StartTS), | ||
zap.String("sql", redact.String(sessVars.EnableRedactLog, sessVars.StmtCtx.OriginalSQL)), | ||
) | ||
} | ||
|
||
txn.SetVars(sessVars.KVVars) | ||
|
||
p.SetOptionsOnTxnActive(txn) | ||
|
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.
This field seems to overlap with the newly added
CommitTS
in the KV interface. Additionally,LazyTxn
is a structure that is no longer needed once a transaction is completed. Or just retain only one of them?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.
This is because
kv.Transaction
will be set to nil inchangeToInvalid
inLazyTxn.Commit
.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.
How about returning the
commitTS
of beforechangeToInvalid
, likeThere 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.
Actually the reason is
CommitTS
has to be saved until the next transaction. If we changedoCommit
to returnCommitTS
, we have to,CommitTS
insession
doCommit
Since we have to save to save
CommitTS
, it would be simpler to saveCommitTS
insidedoCommit
.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.
Can we store commit ts in
doCommit
?