Skip to content
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

Merged
merged 46 commits into from
May 30, 2022
Merged

Conversation

crazycs520
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #6840

What is changed and how it works?

test> begin;
Query OK, 0 rows affected
Time: 0.000s
test> insert into t values (1);
Query OK, 1 row affected
Time: 0.001s
test> savepoint s1;
Query OK, 0 rows affected
Time: 0.001s
test> insert into t values (2);
Query OK, 1 row affected
Time: 0.001s
test> select * from t;
+---+
| a |
+---+
| 1 |
| 2 |
+---+
2 rows in set
Time: 0.007s
test> rollback to s1;
Query OK, 0 rows affected
Time: 0.000s
test> commit;
Query OK, 0 rows affected
Time: 0.001s
test> select * from t;
+---+
| a |
+---+
| 1 |
+---+
1 row in set

Related PR: tikv/client-go#490

Check List

Tests

  • Unit test
  • Integration test

Documentation

  • Contains syntax changes

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Support savepoint in transaction.

bb7133 and others added 23 commits April 14, 2022 15:55
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>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
Signed-off-by: crazycs520 <crazycs520@gmail.com>
@crazycs520 crazycs520 requested a review from a team as a code owner May 9, 2022 05:42
@ti-chi-bot
Copy link
Member

ti-chi-bot commented May 9, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • ekexium
  • lcwangchao
  • you06

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 9, 2022
Signed-off-by: crazycs520 <crazycs520@gmail.com>
@sre-bot
Copy link
Contributor

sre-bot commented May 9, 2022

@ti-chi-bot ti-chi-bot added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels May 27, 2022
func (txn *LazyTxn) RollbackMemDBToCheckpoint(savepoint *tikv.MemDBCheckpoint) {
txn.flushStmtBuf()
txn.Transaction.RollbackMemDBToCheckpoint(savepoint)
txn.cleanup()
Copy link
Contributor

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.

Copy link
Contributor

@cfzjywxk cfzjywxk May 27, 2022

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Member

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:

tidb/kv/kv.go

Line 436 in 7f023bd

Begin(opts ...tikv.TxnOption) (Transaction, error)

We don't have to solve it in this PR.

Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bb7133
Copy link
Member

bb7133 commented May 30, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: dbe4831

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 30, 2022
@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-realtikv-test

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label May 30, 2022
@crazycs520
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 7956fb7

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 30, 2022
@ti-chi-bot ti-chi-bot merged commit b598bd2 into pingcap:master May 30, 2022
@sre-bot
Copy link
Contributor

sre-bot commented May 30, 2022

TiDB MergeCI notify

🔴 Bad News! [1] CI still failing after this pr merged.
These failed integration tests don't seem to be introduced by the current PR.

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-ddl-test 🔴 failed 2, success 4, total 6 10 min Existing failure
idc-jenkins-ci/integration-cdc-test 🟢 all 35 tests passed 35 min Existing passed
idc-jenkins-ci-tidb/integration-common-test 🟢 all 11 tests passed 17 min Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 12 tests passed 10 min Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 6 min 11 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 6 min 11 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 6 min 3 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 5 min 12 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 3 min 3 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

@breezewish
Copy link
Member

breezewish commented May 30, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. require-LGT3 Indicates that the PR requires three LGTM. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

please support savepoint
10 participants