File: gr_read_committed_isolation.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (256 lines) | stat: -rw-r--r-- 9,909 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
################################################################################
# The aim of the testcase is to test GR with 'READ-COMMITTED' isolation level
#
# Test:
# 0. Start 2 servers with GR
# 1. Set isolation level to 'READ-COMMITTED' on both server1, server2
# 2. Create a table (t1), Insert some data
# 3. Check the negative scenarios with conflicting transaction,
#    3.1 set a debug sync and execute a transaction (T1) on server_1 so that it
#         is blocked before broadcast.
#    3.2 check that changes made in connection server_1 has not propogated and
#        wait until server1 reaches the debug sync point.
#    3.3 execute a conflicting transaction (T2) on server2 that will reach
#        certification first.
#    3.4 Signal the waiting thread on server1 to resume.
#    3.5 Check the error on server1, it will rollback T1 as it is conflicting
#        with T2.
#    Another conflicting transaction, but transaction will rollback
#    3.6 ROLL BACK a transaction on server1
#    3.7 Execute a transaction on server2
#    3.8 Transaction originated on server2 will be successful as ROLLED BACK
#        transactions are not broadcasted.
# 4. Check the positive scenarios with non-conflicting transaction,
#    4.1 set a debug sync and execute a transaction (T1) on server_1 so that it
#         is blocked before broadcast.
#    4.2 wait until server1 reaches the debug sync point.
#    4.3 execute a non-conflicting transaction (T2) on server2 that will reach
#        certification first.
#    4.4 Signal the waiting thread on server1 to resume.
#    4.5 Check that both T1 and T2 are executed successfully.
# 5. Validate that server1, server2 has same set of data and assert that number
#    of negatively certified queries are expected ones.
# 6. clean-up
################################################################################

--source include/big_test.inc
--source include/have_debug_sync.inc
--source include/have_group_replication_plugin.inc
--source include/group_replication.inc

--echo
--echo ## 1. Set global isolation level to 'READ-COMMITTED' on server1, server2
--let $rpl_connection_name= server1
--source include/rpl_connection.inc
# Store default isolation level
SET @transaction_isolation_global_orig = @@global.transaction_isolation;
SET GLOBAL transaction_isolation= 'READ-COMMITTED';
SET @transaction_isolation_session_orig = @@global.transaction_isolation;
SET SESSION transaction_isolation= 'READ-COMMITTED';

--let $rpl_connection_name= server2
--source include/rpl_connection.inc
SET @transaction_isolation_global_orig = @@global.transaction_isolation;
SET GLOBAL transaction_isolation= 'READ-COMMITTED';
SET @transaction_isolation_session_orig = @@global.transaction_isolation;
SET SESSION transaction_isolation= 'READ-COMMITTED';

--echo
--echo ## 2. Create table and insert some data
--let $rpl_connection_name= server1
--source include/rpl_connection.inc
CREATE TABLE t1 (a INT PRIMARY KEY);
INSERT INTO t1 VALUES (10),(20);
--source include/rpl_sync.inc

--echo
--echo ## 3.1 Set a debug sync before broadcast message to group on server1
--echo ##    Commit a transaction that will be blocked before broadcast.
--let $rpl_connection_name= server_1
--source include/rpl_connection.inc
SET @debug_save= @@GLOBAL.DEBUG;
SET @@GLOBAL.DEBUG='d,group_replication_before_message_broadcast';
BEGIN;
UPDATE t1 set a= 1 where a= 10;
--send COMMIT

--echo
--echo ## 3.2 Wait until server_1 connection reaches the
--echo ##    'group_replication_before_message_broadcast' debug sync point.
--let $rpl_connection_name= server1
--source include/rpl_connection.inc

# Assert that data on t1 remain unchanged
--let $assert_text= 'Table t1 should contain a row with a=10'
--let $assert_cond= [SELECT COUNT(*) AS count FROM t1 where t1.a= 10, count, 1]= 1
--source include/assert.inc

--let $assert_text= 'Table t1 should contain a row with a=20'
--let $assert_cond= [SELECT COUNT(*) AS count FROM t1 where t1.a= 20, count, 1]= 1
--source include/assert.inc

--let $wait_condition=SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'debug sync point: now'
--source include/wait_condition.inc

--echo
--echo ## 3.3. Execute a transaction on server2, that will reach first
--echo ##    certification, since server_1 is blocked before broadcast.
--let $rpl_connection_name= server2
--source include/rpl_connection.inc
BEGIN;
UPDATE t1 SET a=3 WHERE a=10;
DELETE FROM t1 where a=20;
COMMIT;

--echo
--echo ## 3.4 Signal the waiting thread on server1 to resume.
--let $rpl_connection_name= server1
--source include/rpl_connection.inc
SET DEBUG_SYNC='now SIGNAL waiting';
SET @@GLOBAL.DEBUG= @debug_save;

--echo
--echo ## 3.5 It will end up in an error stating that it was aborted, since
--echo ##     transactions are conflicting and server2 was ordered first.
--let $rpl_connection_name= server2
--source include/rpl_connection.inc
--let $sync_slave_connection= server1
--source include/sync_slave_sql_with_master.inc

--let $rpl_connection_name= server_1
--source include/rpl_connection.inc
--error ER_TRANSACTION_ROLLBACK_DURING_COMMIT
--reap

--echo
--echo ## 3.6 ROLL BACK a transaction on server1
--let $rpl_connection_name= server_1
--source include/rpl_connection.inc
BEGIN;
UPDATE t1 set a= 30 where a= 3;
--send ROLLBACK

--echo
--echo ## 3.7 Execute a transaction on server2
--let $rpl_connection_name= server2
--source include/rpl_connection.inc
BEGIN;
UPDATE t1 SET a=10 WHERE a=3;
COMMIT;
--let $sync_slave_connection= server1
--source include/sync_slave_sql_with_master.inc

--echo
--echo ## 3.8 Transaction originated on server2 will be successful as ROLLED BACK
--echo ##     transactions are not broadcasted.
--let $rpl_connection_name= server_1
--source include/rpl_connection.inc
--reap

--echo ## Validating data on server1 and server2
--let $rpl_connection_name= server1
--source include/rpl_connection.inc
--let $assert_text= 'Table t1 has a row with a=10'
--let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.a = 10, count, 1]" = "1"
--source include/assert.inc

--let $assert_text= 'Table t1 will contain 1 row after the above execution'
--let $assert_cond= "[SELECT COUNT(*) AS count FROM t1, count, 1]" = "1"
--source include/assert.inc

# Check that t1 on Server1, Server2 has same data
--let $diff_tables= server1:test.t1, server2:test.t1
--source include/diff_tables.inc

--echo
--echo ## Checking the positive case in which there is no conflict.
--echo
--echo ## 4.1 Commit a transaction that will be block before broadcast.
--echo ##     Set a debug sync before broadcast message to group on server1.
--let $rpl_connection_name= server_1
--source include/rpl_connection.inc
SELECT * FROM t1;
SET @@GLOBAL.DEBUG='d,group_replication_before_message_broadcast';
BEGIN;
INSERT INTO t1 VALUES (2);
--send COMMIT

--echo
--echo ## 4.2 Wait until server_1 connection reaches the
--echo ## group_replication_before_message_broadcast debug sync point.
--let $rpl_connection_name= server1
--source include/rpl_connection.inc
--let $wait_condition=SELECT COUNT(*)=1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE State = 'debug sync point: now'
--source include/wait_condition.inc

--echo
--echo ## 4.3 Execute a non-conflicting transaction on server2, that will reach
--echo ##    first certification, since server_1 is blocked before broadcast.
--let $rpl_connection_name= server2
--source include/rpl_connection.inc
UPDATE t1 SET a=1 where a=10;
--let $sync_slave_connection= server1
--source include/sync_slave_sql_with_master.inc

--echo
--echo ## 4.4 Signal the waiting thread on server_1 to resume.
--let $rpl_connection_name= server1
--source include/rpl_connection.inc
SET DEBUG_SYNC='now SIGNAL waiting';
SET @@GLOBAL.DEBUG= @debug_save;

--echo
--echo ## 4.5 Transaction will be executed
--let $rpl_connection_name= server_1
--source include/rpl_connection.inc
--reap

--source include/rpl_sync.inc
--echo
--echo ## 5. Assert that number of certified transactions are the
--echo ##    expected ones.
--let $rpl_connection_name= server1
--source include/rpl_connection.inc

--let $assert_text= 'Table t1 will contain row with a=1'
--let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.a = 1, count, 1]" = "1"
--source include/assert.inc

--let $assert_text= 'Table t1 will contain row with a=2'
--let $assert_cond= "[SELECT COUNT(*) AS count FROM t1 WHERE t1.a = 2, count, 1]" = "1"
--source include/assert.inc

--let $assert_text= 'Table t1 will contain 2 rows after the above execution'
--let $assert_cond= "[SELECT COUNT(*) AS count FROM t1, count, 1]" = "2"
--source include/assert.inc

--let $assert_text= 'The value of Count_Transactions_Checked should be 7 after starting group replication'
--let $assert_cond= "[SELECT Count_Transactions_Checked from performance_schema.replication_group_member_stats where member_id in (SELECT @@server_uuid), Count_Transactions_Checked, 1]" = "7"
--source include/assert.inc

--let $assert_text= 'The value of Count_Conflicts_Detected should be 1 after starting group replication'
--let $assert_cond= "[SELECT Count_Conflicts_Detected from performance_schema.replication_group_member_stats where member_id in (SELECT @@server_uuid), Count_Conflicts_Detected, 1]" = "1"
--source include/assert.inc

# Check that t1 on Server1, Server2 has same data
--let $diff_tables= server1:test.t1, server2:test.t1
--source include/diff_tables.inc

--echo
--echo ## 6. Clean up.

# Restore original isolation levels
SET GLOBAL transaction_isolation= @transaction_isolation_global_orig;
SET SESSION transaction_isolation= @transaction_isolation_session_orig;

SET DEBUG_SYNC='RESET';

--let $rpl_connection_name= server2
--source include/rpl_connection.inc

SET GLOBAL transaction_isolation= @transaction_isolation_global_orig;
SET SESSION transaction_isolation= @transaction_isolation_session_orig;
# Drop table
DROP TABLE t1;

--source include/group_replication_end.inc