1#
2# #MW-329 Fix incorrect affected rows count after replay
3#
4
5--source include/galera_cluster.inc
6--source include/have_innodb.inc
7
8CALL mtr.add_suppression("WSREP: .*conflict state . after post commit .*");
9CREATE TABLE t1 (f1 INTEGER, f2 CHAR(20) DEFAULT 'abc') ENGINE=InnoDB;
10
11# We start with a populated table
12INSERT INTO t1 (f1) VALUES (1),(65535);
13
14#
15# Run concurrent INSERTs
16#
17
18DELIMITER |;
19CREATE PROCEDURE proc_insert ()
20BEGIN
21        DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END;
22        SET SESSION wsrep_sync_wait = 0;
23        WHILE 1 DO
24		INSERT INTO t1 (f1) VALUES (FLOOR( 1 + RAND( ) * 65535 ));
25		SELECT SLEEP(0.1);
26        END WHILE;
27END|
28DELIMITER ;|
29
30--connect node_1b, 127.0.0.1, root, , test, $NODE_MYPORT_1
31--connection node_1b
32--let $connection_id = `SELECT CONNECTION_ID()`
33--disable_query_log
34--disable_result_log
35--send CALL proc_insert();
36
37#
38# Run concurrent UPDATEs. We expect that each UPDATE will report that
39# some rows were matched and updated
40#
41
42--connection node_2
43--let $count = 10
44--let $wsrep_local_replays_old = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'`
45
46while ($count)
47{
48	--let $signature = `SELECT LEFT(MD5(RAND()), 10)`
49	--disable_query_log
50	--error 0,ER_LOCK_DEADLOCK
51	--eval UPDATE t1 SET f2 = '$signature'
52	--enable_query_log
53	--let $row_count = `SELECT ROW_COUNT()`
54	if (`SELECT @@error_count = 0`) {
55		if (`SELECT $row_count = 0`) {
56			--die ROW_COUNT() = 0
57		}
58	}
59
60        #
61        # Ensure at least one replay happens
62        #
63
64        --let $wsrep_replays = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'`
65        --disable_query_log
66        if (`SELECT $wsrep_replays - $wsrep_local_replays_old > 0`) {
67                --dec $count
68        }
69        --enable_query_log
70}
71
72#
73# Confirm that some transaction replays occurred
74#
75
76--let $wsrep_local_replays_new = `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_local_replays'`
77--disable_query_log
78--eval SELECT $wsrep_local_replays_new - $wsrep_local_replays_old > 0 AS wsrep_local_replays;
79--enable_query_log
80
81
82#
83# Terminate the stored procedure
84#
85
86--connection node_1
87--disable_query_log
88--eval KILL CONNECTION $connection_id
89--enable_query_log
90
91--connection node_1b
92--error 0,2013,1317
93--reap
94--enable_query_log
95--enable_result_log
96
97--connection node_1
98DROP PROCEDURE proc_insert;
99DROP TABLE t1;
100
101# Due to MW-330, Multiple "conflict state 3 after post commit" warnings if table is dropped while SP is running
102CALL mtr.add_suppression("conflict state 3 after post commit");
103
104set global innodb_status_output=Default;