Skip to content

Commit

Permalink
Supporting START TRANSACTION WITH CONSISTENT [ROCKSDB] SNAPSHOT
Browse files Browse the repository at this point in the history
Summary:
This adds two features in RocksDB.
1. Supporting START TRANSACTION WITH CONSISTENT SNAPSHOT
2. Getting current binlog position in addition to percona#1.
With these features, mysqldump can take consistent logical backup.

The second feature is done by START TRANSACTION WITH
CONSISTENT ROCKSDB SNAPSHOT. This is Facebook's extension, and
it works like existing START TRANSACTION WITH CONSISTENT INNODB SNAPSHOT.

This diff changed some existing codebase/behaviors.

- Original Facebook-MySQL always started InnoDB transaction
regardless of engine clause. For example, START TRANSACTION WITH
CONSISTENT MYISAM SNAPSHOT was accepted but it actually started
InnoDB transaction, not MyISAM. This patch does not allow
setting engine that does not support consistent snapshot.

mysql> start transaction with consistent myisam snapshot;
ERROR 1105 (HY000): Consistent Snapshot is not supported for this engine

Currently only InnoDB and RocksDB support consistent snapshot.
To check engines, I modified sql/sql_yacc.yy, trans_begin()
and ha_start_consistent_snapshot() to pass handlerton.

- Changed constant name from
  MYSQL_START_TRANS_OPT_WITH_CONS_INNODB_SNAPSHOT to
MYSQL_START_TRANS_OPT_WITH_CONS_ENGINE_SNAPSHOT, because it's no longer
InnoDB dependent.

- When not setting engine, START TRANSACTION WITH CONSISTENT SNAPSHOT
takes both InnoDB and RocksDB snapshots, and both InnoDB and RocksDB
participate in transaction. When executing COMMIT, both InnoDB and
RocksDB modifications are committed. Remember that XA is not supported yet,
so mixing engines is not recommended anyway.

- When setting engine, START TRANSACTION WITH CONSISTENT.. takes
snapshot for the specified engine only. But it starts both
InnoDB and RocksDB transactions.

Test Plan: mtr --suite=rocksdb,rocksdb_rpl, --repeat=3

Reviewers: hermanlee4, jonahcohen, jtolmer, tian.xia, maykov, spetrunia

Reviewed By: spetrunia

Subscribers: steaphan

Differential Revision: https://reviews.facebook.net/D32355
  • Loading branch information
yoshinorim authored and jtolmer committed Jan 5, 2016
1 parent 612bdaa commit d81d0bd
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 3 deletions.
107 changes: 107 additions & 0 deletions r/cons_snapshot_repeatable_read.result
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,110 @@ connection default;
disconnect con1;
disconnect con2;
DROP TABLE t1;
connect con1,localhost,root,,;
connect con2,localhost,root,,;
connection con1;
CREATE TABLE r1 (id int primary key, value int, value2 int) engine=ROCKSDB;
insert into r1 values (1,1,1),(2,2,2),(3,3,3),(4,4,4);
BEGIN;
connection con2;
INSERT INTO r1 values (5,5,5);
connection con1;
SELECT * FROM r1;
id value value2
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
connection con2;
INSERT INTO r1 values (6,6,6);
connection con1;
SELECT * FROM r1;
id value value2
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
COMMIT;
SELECT * FROM r1;
id value value2
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connection con2;
INSERT INTO r1 values (7,7,7);
connection con1;
SELECT * FROM r1;
id value value2
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
connection con2;
INSERT INTO r1 values (8,8,8);
connection con1;
SELECT * FROM r1;
id value value2
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
COMMIT;
SELECT * FROM r1;
id value value2
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connection con2;
INSERT INTO r1 values (9,9,9);
connection con1;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
connection con2;
INSERT INTO r1 values (10,10,10);
connection con1;
SELECT * FROM r1;
id value value2
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
START TRANSACTION WITH CONSISTENT SNAPSHOT;
INSERT INTO r1 values (11,11,11);
SELECT * FROM r1;
id value value2
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
8 8 8
9 9 9
10 10 10
11 11 11
drop table r1;
connection default;
disconnect con1;
disconnect con2;
67 changes: 66 additions & 1 deletion t/consistent_snapshot.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ connect (con2,localhost,root,,);

connection con1;

CREATE TABLE t1 (a INT, pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=rocksdb;
CREATE TABLE t1 (a INT, pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=ROCKSDB;
eval SET SESSION TRANSACTION ISOLATION LEVEL $trx_isolation;

# While a consistent snapshot transaction is executed,
Expand All @@ -38,5 +38,70 @@ disconnect con1;
disconnect con2;
DROP TABLE t1;

connect (con1,localhost,root,,);
connect (con2,localhost,root,,);

connection con1;
CREATE TABLE r1 (id int primary key, value int, value2 int) engine=ROCKSDB;
insert into r1 values (1,1,1),(2,2,2),(3,3,3),(4,4,4);

BEGIN;

connection con2;
INSERT INTO r1 values (5,5,5);

connection con1;
SELECT * FROM r1; # 5

connection con2;
INSERT INTO r1 values (6,6,6);

connection con1;
SELECT * FROM r1; # 5
COMMIT;
SELECT * FROM r1; # 6

START TRANSACTION WITH CONSISTENT SNAPSHOT;

connection con2;
INSERT INTO r1 values (7,7,7);

connection con1;
SELECT * FROM r1; # 6

connection con2;
INSERT INTO r1 values (8,8,8);

connection con1;
SELECT * FROM r1; # 6
COMMIT;
SELECT * FROM r1; # 8

START TRANSACTION WITH CONSISTENT SNAPSHOT;

connection con2;
INSERT INTO r1 values (9,9,9);

connection con1;
START TRANSACTION WITH CONSISTENT SNAPSHOT;

connection con2;
INSERT INTO r1 values (10,10,10);

connection con1;
SELECT * FROM r1; # 9

START TRANSACTION WITH CONSISTENT SNAPSHOT;
INSERT INTO r1 values (11,11,11);
SELECT * FROM r1; # self changes should be visible


drop table r1;

connection default;
disconnect con1;
disconnect con2;


--source include/wait_until_count_sessions.inc

3 changes: 1 addition & 2 deletions t/disabled.def
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
type_blob_indexes : MDEV-4097 (Indexes on text/blob fields are not allowed)
type_text_indexes : MDEV-4097 (Indexes on text/blob fields are not allowed)
cons_snapshot_repeatable_read : Consistent read does not work
cons_snapshot_serializable : Consistent read does not work
cons_snapshot_serializable : Consistent read does not work on serializable
select_for_update : Not supported?
select_lock_in_share_mode : Not supported?
level_read_committed : Not supported?
Expand Down

0 comments on commit d81d0bd

Please sign in to comment.