-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
txn: fix the ttlmanager and cleanup logic for 1pc and async commit #23342
Conversation
@@ -920,6 +920,9 @@ func (c *twoPhaseCommitter) execute(ctx context.Context) (err error) { | |||
if c.isOnePC() { | |||
// The error means the 1PC transaction failed. | |||
if err != nil { | |||
if c.getUndeterminedErr() == nil { | |||
c.cleanup(ctx) |
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.
Should we just use something like pessimisticRollbackMutations
if it's pessimistic transactions instead of cleanup
.
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 think there won't be too much difference, but maybe we can skip this for optimistic 1pc transactions. @sticnarf How do you think?
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.
We can always use pessimistic rollback because an optimistic one pc won't leave any waste.
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 changing cleanup()
?
cleanupKeysCtx := context.WithValue(context.Background(), TxnStartKey, ctx.Value(TxnStartKey))
var err error
if c.isPessimistic && c.isOnePC() {
err = c.pessimisticRollbackMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations)
} else {
err = c.cleanupMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations)
}
if err != nil {
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.
@youjiali1995 We needn't do cleanup for optimistic 1PC, so I suggest this:
if !c.isOnePC() {
err = c.cleanupMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations)
} else if c.isPessimistic {
err = c.pessimisticRollbackMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations)
}
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.
My mistake.
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.
LGTM
@@ -920,6 +920,9 @@ func (c *twoPhaseCommitter) execute(ctx context.Context) (err error) { | |||
if c.isOnePC() { | |||
// The error means the 1PC transaction failed. | |||
if err != nil { | |||
if c.getUndeterminedErr() == nil { | |||
c.cleanup(ctx) |
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 think there won't be too much difference, but maybe we can skip this for optimistic 1pc transactions. @sticnarf How do you think?
@MyonKeminta: Please use If you have approved this PR, please ignore this reply. This reply is being used as a temporary reply during the migration of the new bot and will be removed on April 1. 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 ti-community-infra/tichi repository. |
@sticnarf @youjiali1995 PTAL |
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.
Rest LGTM
store/tikv/txn.go
Outdated
@@ -250,7 +250,11 @@ func (txn *KVTxn) Commit(ctx context.Context) error { | |||
} | |||
defer func() { | |||
// For async commit transactions, the ttl manager will be closed in the asynchronous commit goroutine. | |||
if !committer.isAsyncCommit() { | |||
if committer.isAsyncCommit() || committer.isOnePC() { |
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.
Could we just always close the ttl manager here, seems at commit phase and the async commit/1pc transaction size will be small.
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 think it is okay. The chance is small that TTL expires before the primary lock is committed.
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 think yes because SafeWindow
(2s) is smaller than the interval of keepAlive(10s). It's nearly useless here.
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.
It seems to me not related to SafeWindow
. SafeWindow
only constrains the prewrite time.
store/tikv/2pc.go
Outdated
@@ -899,15 +899,20 @@ func (c *twoPhaseCommitter) cleanup(ctx context.Context) { | |||
}) | |||
|
|||
cleanupKeysCtx := context.WithValue(context.Background(), TxnStartKey, ctx.Value(TxnStartKey)) | |||
err := c.cleanupMutations(NewBackofferWithVars(cleanupKeysCtx, cleanupMaxBackoff, c.txn.vars), c.mutations) | |||
var err error | |||
if c.isPessimistic && c.isOnePC() { |
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 skipping cleanup for optimistic one pc? https://github.com/pingcap/tidb/pull/23342/files#r596528085
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 cannot see the line you refer to. I guess it's the |
Yes. |
Got, it's removed. |
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by writing |
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.
Lgtm
@sticnarf: Please use If you have approved this PR, please ignore this reply. This reply is being used as a temporary reply during the migration of the new bot and will be removed on April 1. 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 ti-community-infra/tichi repository. |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 76838b2
|
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-5.0 in PR #23388 |
What problem does this PR solve?
Issue Number: close #23331
Problem Summary:
There are two problems:
What is changed and how it works?
What's Changed:
ttlManager
if the execution result oftwoPhaseCommitter
is error.How it Works:
Related changes
Check List
Tests
Side effects
Release note