-
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
*: support savepoint in transaction #34466
Conversation
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
[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 submitting an approval review. |
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/7956fb721906b363c02dbd0bc843d513304dfcff |
func (txn *LazyTxn) RollbackMemDBToCheckpoint(savepoint *tikv.MemDBCheckpoint) { | ||
txn.flushStmtBuf() | ||
txn.Transaction.RollbackMemDBToCheckpoint(savepoint) | ||
txn.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.
The cleanup
method would discard all the binlog mutations later. It's better to add comments to remind about it because it's not restored as other fields.
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.
Besides, there're still some transaction-related states or caches in tikvTxn
and KVTxn
, some of them could be affected by transaction executions. I'm not quite sure about the risks if they are not considered by the rollback process.
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.
txn.cleanup
will only clean the binlog which is generated in current statement. for rollback to savepoint
statement, the txn.mutations
will always be nil. So txn.cleanup
won't clear the old binlog.
But in another way, when binlog is enabled, execute savepoint
statement will return an error.
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 have verified tikvTxn
and tikv.KVTxn
, there are not any other fields that need to be rollback.
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.
Got, maybe we need to add some defensive checks or tests in case some staging states are added in the future but they are not restored.
@@ -235,6 +235,12 @@ type Transaction interface { | |||
SetDiskFullOpt(level kvrpcpb.DiskFullOpt) | |||
// clear allowed flag | |||
ClearDiskFullOpt() | |||
|
|||
// GetMemDBCheckpoint gets the transaction's memDB checkpoint. | |||
GetMemDBCheckpoint() *tikv.MemDBCheckpoint |
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 don't think it's a good practice to introduce more tikv
interface in kv
package, all interfaces should be abstracted.
But since we have such cases already like:
Line 436 in 7f023bd
Begin(opts ...tikv.TxnOption) (Transaction, error) |
We don't have to solve it in this PR.
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
/merge |
This pull request has been accepted and is ready to merge. Commit hash: dbe4831
|
/run-all-tests |
/run-realtikv-test |
Signed-off-by: crazycs520 <crazycs520@gmail.com>
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 7956fb7
|
TiDB MergeCI notify🔴 Bad News! [1] CI still failing after this pr merged.
|
Just curious, how is the behavior when involving with TiDB Binlog and TiCDC? For example, what will happen for the following SQL statements (the result is MySQL's output): CREATE TABLE t_test (id INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
START TRANSACTION;
INSERT
INTO t_test
VALUES (1);
SELECT *
FROM t_test;
id
---
1
SAVEPOINT tran2;
INSERT
INTO t_test
VALUES (2);
SELECT *
FROM t_test;
id
---
1
2
ROLLBACK TO tran2;
SELECT *
FROM t_test;
id
---
1
ROLLBACK;
SELECT *
FROM t_test;
id
--- (Source: https://stackoverflow.com/questions/1306869/are-nested-transactions-allowed-in-mysql) |
What problem does this PR solve?
Issue Number: close #6840
What is changed and how it works?
Related PR: tikv/client-go#490
Check List
Tests
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.