1--source include/have_rocksdb.inc
2--source include/master-slave.inc
3--source include/have_debug.inc
4--source include/have_debug_sync.inc
5
6connection master;
7--disable_warnings
8drop table if exists t1;
9--enable_warnings
10
11connection master;
12
13create table t0 (a int) engine=myisam;
14insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
15create table t1(a int) engine=myisam;
16insert into t1 select A.a + B.a* 10 + C.a * 100 from t0 A, t0 B, t0 C;
17create table t2 (
18  pk int primary key,
19  kp1 int,
20  kp2 int,
21  col1 int,
22  key (kp1,kp2)
23) engine=rocksdb;
24# Use RBR for next few statements to avoid the
25#  'Unsafe statement written to the binary log' warnings.
26set @tmp_binlog_format=@@binlog_format;
27set @@binlog_format=ROW;
28insert into t2 select a,a,a,a from t1;
29create table t3 like t2;
30insert into t3 select * from t2;
31set binlog_format=@tmp_binlog_format;
32
33
34# For GitHub issue#166
35# Slave is suspended at ha_rocksdb::read_range_first() -> index_read_map_impl()
36# -> ha_rocksdb::get_row_by_rowid() -- which is after creating an iterator,
37# Seek(), Next() (getting pk=1)
38# and before GetForUpdate() and before creating a snapshot.
39# Deletes remove pk=2 and pk=3, then resumes update on slave.
40# The update resumes with GetForUpdate(pk=1),
41# index_next() -> secondary_index_read() -> get_row_by_rowid(pk=2)
42# then doesn't find a row.
43# The slave should not stop with error (Can't find a record).
44
45--source include/sync_slave_sql_with_master.inc
46
47connection slave;
48let $old_debug = `select @@global.debug`;
49set global debug_dbug= 'd,dbug.rocksdb.get_row_by_rowid';
50--source include/stop_slave.inc
51--source include/start_slave.inc
52
53connection master;
54update t2 set col1=100 where kp1 between 1 and 3 and mod(kp2,2)=0;
55
56connection slave;
57set debug_sync= 'now WAIT_FOR Reached';
58eval set global debug_dbug = '$old_debug';
59set sql_log_bin=0;
60delete from t2 where pk=2;
61delete from t2 where pk=3;
62set debug_sync= 'now SIGNAL signal.rocksdb.get_row_by_rowid_let_running';
63
64connection master;
65--source include/sync_slave_sql_with_master.inc
66connection slave;
67select * from t2 where pk < 5;
68
69# For GitHub issue#162 (result file must be updated after fixing #162)
70connection slave;
71set global debug_dbug= 'd,dbug.rocksdb.get_row_by_rowid';
72--source include/stop_slave.inc
73--source include/start_slave.inc
74
75connection master;
76update t3 set col1=100 where kp1 between 1 and 4 and mod(kp2,2)=0;
77
78connection slave;
79call mtr.add_suppression("Deadlock found when trying to get lock");
80set debug_sync= 'now WAIT_FOR Reached';
81eval set global debug_dbug = '$old_debug';
82set sql_log_bin=0;
83delete from t3 where pk=2;
84delete from t3 where pk=3;
85set debug_sync= 'now SIGNAL signal.rocksdb.get_row_by_rowid_let_running';
86
87connection master;
88--source include/sync_slave_sql_with_master.inc
89connection slave;
90# col1 for pk=4 should be 100
91select * from t3 where pk < 5;
92
93set debug_sync='RESET';
94# Cleanup
95connection master;
96drop table t0, t1, t2, t3;
97--source include/rpl_end.inc
98
99