Skip to content

Commit ceebec6

Browse files
author
Anibal Pinto
committed
WL#9837: Group Replication: Transaction savepoint support
This worklog goal is to improve Group Replication by adding support to SAVEPOINT. The SAVEPOINT statement sets a named transaction savepoint with a name of identifier. If the current transaction has a savepoint with the same name, the old savepoint is deleted and a new one is set. The ROLLBACK TO identifier command reverts the state of the transaction back to what was when executed the command SAVEPOINT identifier. The RELEASE SAVEPOINT statement removes the named savepoint from the set of savepoints of the current transaction. No commit or rollback occurs. It returns an error if the savepoint does not exist.
1 parent c786f91 commit ceebec6

31 files changed

+1463
-128
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
CREATE TABLE t1(a int primary key);
2+
CREATE TABLE t2(a int primary key);
3+
BEGIN;
4+
#
5+
# Insert values on table and savepoints
6+
#
7+
SAVEPOINT S1;
8+
INSERT INTO t1 values(3);
9+
INSERT INTO t1 values(4);
10+
SAVEPOINT S2;
11+
INSERT INTO t1 values(5);
12+
INSERT INTO t1 values(6);
13+
SAVEPOINT S3;
14+
SAVEPOINT S4;
15+
#
16+
# RELEASE S4
17+
#
18+
RELEASE SAVEPOINT S4;
19+
INSERT INTO t1 values(7);
20+
SELECT * FROM t1;
21+
a
22+
3
23+
4
24+
5
25+
6
26+
7
27+
#
28+
# ROLLBACK TO S2
29+
#
30+
ROLLBACK TO S2;
31+
#
32+
# Confirm S3 was removed when rollbacking to S2
33+
#
34+
ROLLBACK TO S3;
35+
ERROR 42000: SAVEPOINT S3 does not exist
36+
SELECT * FROM t1;
37+
a
38+
3
39+
4
40+
INSERT INTO t1 values(7);
41+
SELECT * FROM t1;
42+
a
43+
3
44+
4
45+
7
46+
#
47+
# Confirm S2 exists after ROLLBACK TO S2
48+
#
49+
ROLLBACK TO S2;
50+
SELECT * FROM t1;
51+
a
52+
3
53+
4
54+
COMMIT;
55+
#
56+
# Check the multitable update on 'rollback to savepoint'
57+
#
58+
BEGIN;
59+
INSERT INTO t1 values (5);
60+
SAVEPOINT S1;
61+
DELETE FROM t1;
62+
INSERT INTO t1 values (1);
63+
INSERT INTO t2 SELECT * FROM t1;
64+
UPDATE t1,t2 SET t1.a=3, t2.a=3;
65+
SELECT * FROM t1;
66+
a
67+
3
68+
SELECT * FROM t2;
69+
a
70+
3
71+
ROLLBACK TO SAVEPOINT S1;
72+
INSERT INTO t2 SELECT * FROM t1;
73+
COMMIT;
74+
SELECT * FROM t1;
75+
a
76+
3
77+
4
78+
5
79+
SELECT * FROM t2;
80+
a
81+
3
82+
4
83+
5
84+
DROP TABLE t1;
85+
DROP TABLE t2;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SET @save_session_debug= @@SESSION.debug;
2+
SET @@SESSION.debug = "+d,transaction_write_set_savepoint_clear_on_commit_rollback";
3+
CREATE TABLE t1 (c1 INT PRIMARY KEY);
4+
BEGIN;
5+
SAVEPOINT S0;
6+
INSERT INTO t1 VALUES (0);
7+
COMMIT;
8+
BEGIN;
9+
SAVEPOINT S1;
10+
INSERT INTO t1 VALUES (1);
11+
ROLLBACK;
12+
BEGIN;
13+
SAVEPOINT S2;
14+
INSERT INTO t1 VALUES (2);
15+
COMMIT;
16+
include/assert.inc ['There are two values in table t1']
17+
SET @@SESSION.debug= @save_session_debug;
18+
DROP TABLE t1;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SET @save_session_debug= @@SESSION.debug;
2+
SET @@SESSION.debug = "+d,transaction_write_set_savepoint_add_savepoint";
3+
CREATE TABLE t1 (c1 INT PRIMARY KEY);
4+
BEGIN;
5+
SAVEPOINT S0;
6+
INSERT INTO t1 VALUES (0);
7+
SAVEPOINT S0;
8+
ROLLBACK TO S0;
9+
COMMIT;
10+
include/assert.inc ['There is one value in table t1']
11+
SET @@SESSION.debug= @save_session_debug;
12+
DROP TABLE t1;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
SET @save_session_debug= @@SESSION.debug;
2+
SET @@SESSION.debug = "+d,transaction_write_set_savepoint_level";
3+
CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY);
4+
CREATE TABLE t2 (c1 INT NOT NULL PRIMARY KEY);
5+
CREATE TABLE t3 (c1 INT NOT NULL PRIMARY KEY);
6+
CREATE TABLE t4 (c1 INT NOT NULL PRIMARY KEY);
7+
CREATE TRIGGER t1_tr1 BEFORE INSERT ON t1 FOR EACH ROW
8+
BEGIN
9+
SAVEPOINT S1;
10+
INSERT INTO t2 VALUES (NEW.c1);
11+
END|
12+
CREATE FUNCTION f1(x INT) RETURNS INT
13+
BEGIN
14+
INSERT INTO t2 VALUES (x);
15+
SAVEPOINT S1;
16+
INSERT INTO t1 VALUES (100);
17+
ROLLBACK TO S1;
18+
RETURN (1);
19+
END|
20+
BEGIN;
21+
SAVEPOINT S1;
22+
INSERT INTO t1 VALUES (1);
23+
ROLLBACK TO S1;
24+
SELECT f1(102);
25+
f1(102)
26+
1
27+
SET @@SESSION.debug = "+d,transaction_write_set_size_2";
28+
SELECT f1(101);
29+
f1(101)
30+
1
31+
COMMIT;
32+
SET @@SESSION.debug= @save_session_debug;
33+
CREATE TRIGGER t3_tr1 AFTER INSERT ON t3 FOR EACH ROW
34+
BEGIN
35+
DECLARE EXIT HANDLER FOR SQLEXCEPTION
36+
BEGIN
37+
ROLLBACK TO SAVEPOINT inside_trigger;
38+
INSERT INTO t4 VALUES (NEW.c1*20);
39+
END;
40+
SAVEPOINT inside_trigger;
41+
INSERT INTO t4 VALUES (NEW.c1);
42+
RELEASE SAVEPOINT inside_trigger;
43+
END|
44+
INSERT INTO t3 values (1);
45+
INSERT INTO t4 values (2);
46+
INSERT INTO t3 values (2);
47+
SELECT * FROM t1;
48+
SELECT * FROM t2;
49+
c1 101
50+
c1 102
51+
SELECT * FROM t3;
52+
c1 1
53+
c1 2
54+
SELECT * FROM t4;
55+
c1 1
56+
c1 2
57+
c1 40
58+
include/assert.inc ['There are no values in table t1']
59+
include/assert.inc ['There are 2 values in table t2']
60+
include/assert.inc ['There are 2 values in table t3']
61+
include/assert.inc ['There are 3 values in table t4']
62+
DROP FUNCTION f1;
63+
DROP TABLE t1;
64+
DROP TABLE t2;
65+
DROP TABLE t3;
66+
DROP TABLE t4;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--transaction-write-set-extraction=XXHASH64
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
###############################################################################
2+
#
3+
# Basic test to confirm the correct behavior when executing SAVEPOINT,
4+
# ROLLBACK TO and RELEASE SAVEPOINT commands
5+
#
6+
# The execution of SELECT guarantee the correct values on TABLE after process
7+
# SAVEPOINT commands
8+
#
9+
# Test:
10+
# 0. Create a table to insert data
11+
# 1. Create a transaction and insert values and savepoints (S1, S2, S3, S4)
12+
# 2. Release savepoint S4
13+
# 4. Rollback to a savepoint S2 and verify that savepoint S3 disappeared
14+
# 5. Insert more values and rollback to S2 to verify that rollback don't
15+
# remove savepoint
16+
# 6. Check the multitable update on 'rollback to savepoint' is proper.
17+
# 7. Clean-up
18+
#
19+
###############################################################################
20+
21+
--source include/have_log_bin.inc
22+
23+
CREATE TABLE t1(a int primary key);
24+
CREATE TABLE t2(a int primary key);
25+
26+
BEGIN;
27+
28+
--echo #
29+
--echo # Insert values on table and savepoints
30+
--echo #
31+
32+
SAVEPOINT S1;
33+
INSERT INTO t1 values(3);
34+
INSERT INTO t1 values(4);
35+
SAVEPOINT S2;
36+
INSERT INTO t1 values(5);
37+
INSERT INTO t1 values(6);
38+
SAVEPOINT S3;
39+
SAVEPOINT S4;
40+
41+
--echo #
42+
--echo # RELEASE S4
43+
--echo #
44+
45+
RELEASE SAVEPOINT S4;
46+
47+
INSERT INTO t1 values(7);
48+
SELECT * FROM t1;
49+
50+
--echo #
51+
--echo # ROLLBACK TO S2
52+
--echo #
53+
54+
ROLLBACK TO S2;
55+
56+
--echo #
57+
--echo # Confirm S3 was removed when rollbacking to S2
58+
--echo #
59+
60+
--error ER_SP_DOES_NOT_EXIST
61+
ROLLBACK TO S3;
62+
63+
SELECT * FROM t1;
64+
65+
INSERT INTO t1 values(7);
66+
67+
SELECT * FROM t1;
68+
69+
--echo #
70+
--echo # Confirm S2 exists after ROLLBACK TO S2
71+
--echo #
72+
73+
ROLLBACK TO S2;
74+
SELECT * FROM t1;
75+
76+
COMMIT;
77+
78+
--echo #
79+
--echo # Check the multitable update on 'rollback to savepoint'
80+
--echo #
81+
82+
BEGIN;
83+
INSERT INTO t1 values (5);
84+
85+
SAVEPOINT S1;
86+
DELETE FROM t1;
87+
INSERT INTO t1 values (1);
88+
INSERT INTO t2 SELECT * FROM t1;
89+
UPDATE t1,t2 SET t1.a=3, t2.a=3;
90+
91+
SELECT * FROM t1;
92+
SELECT * FROM t2;
93+
94+
ROLLBACK TO SAVEPOINT S1;
95+
INSERT INTO t2 SELECT * FROM t1;
96+
COMMIT;
97+
98+
SELECT * FROM t1;
99+
SELECT * FROM t2;
100+
101+
# Clean-up
102+
DROP TABLE t1;
103+
DROP TABLE t2;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--transaction-write-set-extraction=XXHASH64
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
###############################################################################
2+
# This test confirm that all information about SAVEPOINT identifiers is erased
3+
# after a COMMIT or ROLLBACK
4+
#
5+
# Test:
6+
# 0. Enable debug point that asserts that when adding a SAVEPOINT it's the
7+
# only one on savepoint map
8+
# 1. Create a table to insert data
9+
# 2. Commit a transaction and verify that when created a SAVEPOINT was the only
10+
# one identifier
11+
# 3. Rollback a transaction and verify that when created a SAVEPOINT was the only
12+
# one identifier
13+
# 4. Commit a transaction and verify that when created a SAVEPOINT was the only
14+
# one identifier
15+
#
16+
###############################################################################
17+
18+
--source include/have_debug.inc
19+
--source include/have_binlog_format_row.inc
20+
21+
SET @save_session_debug= @@SESSION.debug;
22+
SET @@SESSION.debug = "+d,transaction_write_set_savepoint_clear_on_commit_rollback";
23+
24+
CREATE TABLE t1 (c1 INT PRIMARY KEY);
25+
26+
BEGIN;
27+
SAVEPOINT S0;
28+
INSERT INTO t1 VALUES (0);
29+
COMMIT;
30+
31+
BEGIN;
32+
SAVEPOINT S1;
33+
INSERT INTO t1 VALUES (1);
34+
ROLLBACK;
35+
36+
BEGIN;
37+
SAVEPOINT S2;
38+
INSERT INTO t1 VALUES (2);
39+
COMMIT;
40+
41+
--let $assert_text= 'There are two values in table t1'
42+
--let $assert_cond= [SELECT COUNT(*) AS count FROM t1, count, 1] = 2
43+
--source include/assert.inc
44+
45+
# Cleanup
46+
SET @@SESSION.debug= @save_session_debug;
47+
DROP TABLE t1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--transaction-write-set-extraction=XXHASH64
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
###############################################################################
2+
# This test confirm that when adding a SAVEPOINT with a identifier already
3+
# defined in transaction, the older one will be replaced by the new definirtion
4+
#
5+
# Test:
6+
# 0. Enable debug point that asserts that the SAVEPOINT position is equal
7+
# to write_set size and when executing ROLLBACK TO the write_set size is 1
8+
# 1. Create a table to insert data
9+
# 2. Create SAVEPOINT S0
10+
# 3. Insert values on t1
11+
# 4. Redefine SAVEPOINT S0 that will overwrite previous definition
12+
# 5. ROLLBACK TO S0 that won't modify the content of t1
13+
#
14+
###############################################################################
15+
16+
17+
--source include/have_debug.inc
18+
--source include/have_binlog_format_row.inc
19+
20+
SET @save_session_debug= @@SESSION.debug;
21+
SET @@SESSION.debug = "+d,transaction_write_set_savepoint_add_savepoint";
22+
23+
CREATE TABLE t1 (c1 INT PRIMARY KEY);
24+
25+
BEGIN;
26+
27+
SAVEPOINT S0;
28+
INSERT INTO t1 VALUES (0);
29+
30+
SAVEPOINT S0;
31+
ROLLBACK TO S0;
32+
33+
COMMIT;
34+
35+
--let $assert_text= 'There is one value in table t1'
36+
--let $assert_cond= [SELECT COUNT(*) AS count FROM t1, count, 1] = 1
37+
--source include/assert.inc
38+
39+
# Cleanup
40+
SET @@SESSION.debug= @save_session_debug;
41+
DROP TABLE t1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--transaction-write-set-extraction=XXHASH64

0 commit comments

Comments
 (0)