Skip to content

Commit

Permalink
MyRocks: Returning an error on ROLLBACK TO SAVEPOINT if modifying rows (
Browse files Browse the repository at this point in the history
facebook#52)

Summary:
MyRocks did neither rollback nor return an error on ROLLBACK TO
SAVEPOINT, which was confusing to users. This diff makes MyRocks return
an error on ROLLBACK TO SAVEPOINT if modifying rows. Users can
at least know that.
Real fix is to support rollback on savepoint, not to return an error,
which will happen in future release.

Differential Revision: https://reviews.facebook.net/D55161
  • Loading branch information
yoshinorim authored and inikep committed May 20, 2022
1 parent 5cc5da7 commit 6f3e80e
Show file tree
Hide file tree
Showing 10 changed files with 336 additions and 29 deletions.
44 changes: 44 additions & 0 deletions mysql-test/suite/rocksdb/r/delete.result
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,48 @@ a b
BEGIN;
DELETE FROM t1 WHERE a <= 4 ORDER BY b DESC LIMIT 1;
SAVEPOINT spt1;
DELETE FROM t1;
RELEASE SAVEPOINT spt1;
ROLLBACK;
SELECT a,b FROM t1;
a b
10000 foobar
10000 foobar
2 b
2 b
4 d
4 d
5 e
5 e
6 f
6 f
7 g
7 g
8 h
8 h
BEGIN;
DELETE FROM t1 WHERE a <= 4 ORDER BY b DESC LIMIT 1;
SAVEPOINT spt1;
DELETE FROM t1;
INSERT INTO t1 (a,b) VALUES (1,'a');
ROLLBACK TO SAVEPOINT spt1;
ERROR HY000: MyRocks currently does not support ROLLBACK TO SAVEPOINT if modifying rows.
COMMIT;
ERROR HY000: This transaction was rolled back and cannot be committed. Only supported operation is to roll it back, so all pending changes will be discarded. Please restart another transaction.
SELECT a,b FROM t1;
a b
10000 foobar
10000 foobar
2 b
2 b
4 d
4 d
5 e
5 e
6 f
6 f
7 g
7 g
8 h
8 h
DROP TABLE t1;
7 changes: 2 additions & 5 deletions mysql-test/suite/rocksdb/r/insert.result
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,18 @@ SAVEPOINT spt1;
INSERT INTO t1 SET a = 11, b = 'f';
INSERT t1 SET b = DEFAULT;
ROLLBACK TO SAVEPOINT spt1;
ERROR HY000: MyRocks currently does not support ROLLBACK TO SAVEPOINT if modifying rows.
INSERT INTO t1 (b,a) VALUES ('test1',10);
COMMIT;
ERROR HY000: This transaction was rolled back and cannot be committed. Only supported operation is to roll it back, so all pending changes will be discarded. Please restart another transaction.
SELECT a,b FROM t1;
a b
1 a
10 NULL
10 foo
10 test1
100 foo
11 abc
11 f
2 b
20 NULL
3 c
4 d
5 e
NULL NULL
DROP TABLE t1;
103 changes: 103 additions & 0 deletions mysql-test/suite/rocksdb/r/rpl_savepoint.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
include/master-slave.inc
Warnings:
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
[connection master]
drop table if exists t1;
create table t1 (id int primary key, value int);
insert into t1 values (1,1), (2,2), (3,3);
begin;
insert into t1 values (11, 1);
savepoint a;
insert into t1 values (12, 1);
rollback to savepoint a;
ERROR HY000: MyRocks currently does not support ROLLBACK TO SAVEPOINT if modifying rows.
commit;
ERROR HY000: This transaction was rolled back and cannot be committed. Only supported operation is to roll it back, so all pending changes will be discarded. Please restart another transaction.
commit;
select * from t1;
id value
1 1
2 2
3 3
include/sync_slave_sql_with_master.inc
select * from t1;
id value
1 1
2 2
3 3
begin;
insert into t1 values (21, 1);
savepoint a;
insert into t1 values (22, 1);
rollback to savepoint a;
ERROR HY000: MyRocks currently does not support ROLLBACK TO SAVEPOINT if modifying rows.
insert into t1 values (23, 1);
ERROR HY000: This transaction was rolled back and cannot be committed. Only supported operation is to roll it back, so all pending changes will be discarded. Please restart another transaction.
commit;
ERROR HY000: This transaction was rolled back and cannot be committed. Only supported operation is to roll it back, so all pending changes will be discarded. Please restart another transaction.
commit;
select * from t1;
id value
1 1
2 2
3 3
include/sync_slave_sql_with_master.inc
select * from t1;
id value
1 1
2 2
3 3
begin;
insert into t1 values (31, 1);
savepoint a;
insert into t1 values (32, 1);
savepoint b;
insert into t1 values (33, 1);
rollback to savepoint a;
ERROR HY000: MyRocks currently does not support ROLLBACK TO SAVEPOINT if modifying rows.
insert into t1 values (34, 1);
ERROR HY000: This transaction was rolled back and cannot be committed. Only supported operation is to roll it back, so all pending changes will be discarded. Please restart another transaction.
rollback;
select * from t1;
id value
1 1
2 2
3 3
include/sync_slave_sql_with_master.inc
select * from t1;
id value
1 1
2 2
3 3
SET autocommit=off;
select * from t1;
id value
1 1
2 2
3 3
SAVEPOINT A;
select * from t1;
id value
1 1
2 2
3 3
SAVEPOINT A;
insert into t1 values (35, 35);
ROLLBACK TO SAVEPOINT A;
ERROR HY000: MyRocks currently does not support ROLLBACK TO SAVEPOINT if modifying rows.
START TRANSACTION;
ERROR HY000: This transaction was rolled back and cannot be committed. Only supported operation is to roll it back, so all pending changes will be discarded. Please restart another transaction.
select * from t1;
id value
1 1
2 2
3 3
include/sync_slave_sql_with_master.inc
select * from t1;
id value
1 1
2 2
3 3
drop table t1;
include/rpl_end.inc
26 changes: 14 additions & 12 deletions mysql-test/suite/rocksdb/r/update.result
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,22 @@ UPDATE t1 SET b = 'update2' WHERE a <= 100;
SAVEPOINT spt1;
UPDATE t1 SET b = '';
ROLLBACK TO SAVEPOINT spt1;
ERROR HY000: MyRocks currently does not support ROLLBACK TO SAVEPOINT if modifying rows.
UPDATE t1 SET b = 'upd' WHERE a = 10050;
COMMIT;
ERROR HY000: This transaction was rolled back and cannot be committed. Only supported operation is to roll it back, so all pending changes will be discarded. Please restart another transaction.
SELECT * FROM t1 ORDER BY pk;
a b pk
51 1
52 2
53 3
54 4
55 5
10050 upd 6
51 7
52 8
53 9
54 10
55 11
10050 upd 12
51 NULL 1
52 NULL 2
53 NULL 3
54 NULL 4
55 NULL 5
10050 NULL 6
51 NULL 7
52 NULL 8
53 NULL 9
54 NULL 10
55 NULL 11
10050 NULL 12
DROP TABLE t1;
8 changes: 4 additions & 4 deletions mysql-test/suite/rocksdb/t/delete.test
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ BEGIN;
DELETE FROM t1 WHERE a <= 4 ORDER BY b DESC LIMIT 1;
SAVEPOINT spt1;

--disable_parsing

DELETE FROM t1;
RELEASE SAVEPOINT spt1;
ROLLBACK;
Expand All @@ -92,10 +90,12 @@ DELETE FROM t1 WHERE a <= 4 ORDER BY b DESC LIMIT 1;
SAVEPOINT spt1;
DELETE FROM t1;
INSERT INTO t1 (a,b) VALUES (1,'a');
--error ER_UNKNOWN_ERROR
ROLLBACK TO SAVEPOINT spt1;
--error ER_UNKNOWN_ERROR
COMMIT;

--enable_parsing
--sorted_result
SELECT a,b FROM t1;

DROP TABLE t1;

2 changes: 2 additions & 0 deletions mysql-test/suite/rocksdb/t/insert.test
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ INSERT t1 (a) VALUE (10),(20);
SAVEPOINT spt1;
INSERT INTO t1 SET a = 11, b = 'f';
INSERT t1 SET b = DEFAULT;
--error ER_UNKNOWN_ERROR
ROLLBACK TO SAVEPOINT spt1;
INSERT INTO t1 (b,a) VALUES ('test1',10);
--error ER_UNKNOWN_ERROR
COMMIT;
--sorted_result
SELECT a,b FROM t1;
Expand Down
7 changes: 7 additions & 0 deletions mysql-test/suite/rocksdb/t/rpl_savepoint.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
!include suite/rpl/my.cnf

[mysqld.1]
binlog_format=row
[mysqld.2]
binlog_format=row

90 changes: 90 additions & 0 deletions mysql-test/suite/rocksdb/t/rpl_savepoint.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
--source include/have_rocksdb.inc

source include/master-slave.inc;

connection master;
--disable_warnings
drop table if exists t1;
--enable_warnings

connection master;

create table t1 (id int primary key, value int);
insert into t1 values (1,1), (2,2), (3,3);

begin;
insert into t1 values (11, 1);
savepoint a;
insert into t1 values (12, 1);
--error ER_UNKNOWN_ERROR
rollback to savepoint a;
--error ER_UNKNOWN_ERROR
commit;
commit;
select * from t1;

--source include/sync_slave_sql_with_master.inc
connection slave;

select * from t1;

connection master;
begin;
insert into t1 values (21, 1);
savepoint a;
insert into t1 values (22, 1);
--error ER_UNKNOWN_ERROR
rollback to savepoint a;
--error ER_UNKNOWN_ERROR
insert into t1 values (23, 1);
--error ER_UNKNOWN_ERROR
commit;
commit;
select * from t1;

--source include/sync_slave_sql_with_master.inc
connection slave;
select * from t1;


connection master;
begin;
insert into t1 values (31, 1);
savepoint a;
insert into t1 values (32, 1);
savepoint b;
insert into t1 values (33, 1);
--error ER_UNKNOWN_ERROR
rollback to savepoint a;
--error ER_UNKNOWN_ERROR
insert into t1 values (34, 1);
rollback;
select * from t1;

--source include/sync_slave_sql_with_master.inc
connection slave;
select * from t1;

### GitHub Issue#195
connection master;
SET autocommit=off;
select * from t1;
SAVEPOINT A;
select * from t1;
SAVEPOINT A;
insert into t1 values (35, 35);
--error ER_UNKNOWN_ERROR
ROLLBACK TO SAVEPOINT A;
--error ER_UNKNOWN_ERROR
START TRANSACTION;
select * from t1;
--source include/sync_slave_sql_with_master.inc
connection slave;
select * from t1;


connection master;
drop table t1;

--source include/rpl_end.inc

2 changes: 2 additions & 0 deletions mysql-test/suite/rocksdb/t/update.test
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ BEGIN;
UPDATE t1 SET b = 'update2' WHERE a <= 100;
SAVEPOINT spt1;
UPDATE t1 SET b = '';
--error ER_UNKNOWN_ERROR
ROLLBACK TO SAVEPOINT spt1;
UPDATE t1 SET b = 'upd' WHERE a = 10050;
--error ER_UNKNOWN_ERROR
COMMIT;
SELECT * FROM t1 ORDER BY pk;

Expand Down
Loading

0 comments on commit 6f3e80e

Please sign in to comment.