Debian Codegraph @

mysql-test/suite/ndb_rpl/t/ndb_rpl_last_conflict_epoch_var.test

raw
1 #
2 # Test engine native conflict resolution for ndb
3 # NDB$EPOCH() function
4 #
5 #
6 --source include/have_ndb.inc
7 --source include/have_binlog_format_mixed_or_row.inc
8 --source suite/ndb_rpl/ndb_master-slave.inc
9
10 --echo Setup circular replication
11
12 --disable_query_log
13 --connection slave
14 RESET MASTER;
15 let $SLAVE_SERVER_ID= `select @@server_id`;
16 echo SLAVE_SERVER_ID: $SLAVE_SERVER_ID;
17
18 --connection master
19 --replace_result $SLAVE_MYPORT SLAVE_PORT
20 --eval CHANGE REPLICATION SOURCE TO SOURCE_HOST="127.0.0.1",SOURCE_PORT=$SLAVE_MYPORT,SOURCE_USER="root"
21 START SLAVE;
22 let $MASTER_SERVER_ID= `select @@server_id`;
23 echo MASTER_SERVER_ID: $MASTER_SERVER_ID;
24
25 --echo Setup ndb_replication and t1$EX exceptions table
26
27 --disable_warnings
28 --connection master
29 drop table if exists mysql.ndb_replication;
30 CREATE TABLE mysql.ndb_replication
31 (db VARBINARY(63),
32 table_name VARBINARY(63),
33 server_id INT UNSIGNED,
34 binlog_type INT UNSIGNED,
35 conflict_fn VARBINARY(128),
36 PRIMARY KEY USING HASH (db,table_name,server_id))
37 ENGINE=NDB PARTITION BY KEY(db,table_name);
38 --enable_warnings
39
40 --echo Populate ndb_replication table as necessary
41 eval replace into mysql.ndb_replication values
42 ("test", "t1", $SLAVE_SERVER_ID, 7, NULL),
43 ("test", "t1", $MASTER_SERVER_ID, 7, "NDB\$EPOCH()");
44 --enable_query_log
45
46 create table test.t1 (
47 a int primary key,
48 b int,
49 c varchar(2000)) engine=ndb;
50
51 insert into test.t1 values (1,1,repeat("B", 1000));
52
53 --sync_slave_with_master slave
54
55 --connection slave
56 --echo Stopping Primary -> Secondary replication
57 stop slave;
58
59 --connection master
60 --echo Stopping Secondary -> Primary replication
61 stop slave;
62
63 --echo Making change on Primary
64 update test.t1 set b=2 where a=1;
65
66 --echo Making conflicting change on Secondary
67 --connection slave
68 begin;
69 update test.t1 set b=3 where a=1;
70 insert into test.t1 values (2,2,repeat("A", 1000));
71 commit;
72
73 --disable_query_log
74 --disable_result_log
75 --connection master
76 --echo Capturing session epoch from Master
77 select @master_session_epoch:=Variable_value
78 from performance_schema.global_status
79 where Variable_name="Ndb_last_commit_epoch_session";
80
81 --enable_result_log
82
83 --echo Show that last_conflict_epoch is 0
84 show status like 'ndb_conflict_last_conflict_epoch';
85
86 --echo Restart Secondary->Primary replication
87 start slave;
88
89 --connection slave
90 --sync_slave_with_master master
91 --connection master
92
93 --echo Check that max_replicated_epoch is
94 --echo still < the saved session epoch
95 --disable_result_log
96
97 select @max_replicated_epoch:=Variable_value
98 from performance_schema.global_status
99 where Variable_name="Ndb_slave_max_replicated_epoch";
100
101 --enable_result_log
102 --echo Max replicated epoch should be < committed epoch
103 # select @max_replicated_epoch < @master_session_epoch;
104 select @max_replicated_epoch+0 < @master_session_epoch+0 as '@max_replicated_epoch < @master_session_epoch';
105
106 --disable_result_log
107 select @conflict_detected_epoch:=Variable_value
108 from performance_schema.global_status
109 where Variable_name="ndb_conflict_last_conflict_epoch";
110 --enable_result_log
111
112 --echo Some invariants :
113 # select @conflict_detected_epoch != 0;
114 select @conflict_detected_epoch+0 != 0 as '@conflict_detected_epoch != 0';
115 # select @conflict_detected_epoch > @max_replicated_epoch;
116 select @conflict_detected_epoch+0 > @max_replicated_epoch+0 as '@conflict_detected_epoch > @max_replicated_epoch';
117
118 --echo Primary has detected the problem, but Secondary
119 --echo is unaware as the slave is offline.
120 --echo Now bring it back
121
122 --connection slave
123 start slave;
124
125 --echo Now sync up
126 --connection master
127 --sync_slave_with_master slave
128 --connection slave
129 --sync_slave_with_master master
130 --connection master
131
132 --echo Now lets check that the max replicated epoch
133 --echo on the Primary is == the last_conflict_epoch
134 --disable_result_log
135 select @max_replicated_epoch:=Variable_value
136 from performance_schema.global_status
137 where Variable_name="Ndb_slave_max_replicated_epoch";
138
139 select @conflict_detected_epoch:=Variable_value
140 from performance_schema.global_status
141 where Variable_name="ndb_conflict_last_conflict_epoch";
142
143 --enable_result_log
144 # select @max_replicated_epoch = @conflict_detected_epoch;
145 select @max_replicated_epoch+0 = @conflict_detected_epoch+0 as '@max_replicated_epoch = @conflict_detected_epoch';
146
147 --echo Cleanup
148
149 drop table test.t1;
150 drop table mysql.ndb_replication;
151
152 --sync_slave_with_master slave
153 --connection slave
154 --sync_slave_with_master master
155 --connection master
156 stop slave;
157
158 --source include/rpl_end.inc