Skip to content

Commit df96eb5

Browse files
sjaakolaNirbhay Choubey
authored andcommitted
Refs: MW-248
- test cases from PXC for reproducing the issue - initial fix
1 parent a53ac77 commit df96eb5

File tree

7 files changed

+341
-12
lines changed

7 files changed

+341
-12
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
START SLAVE USER='root';
2+
Warnings:
3+
Note 1759 Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
SET SESSION binlog_format='STATEMENT';
5+
CREATE TABLE t1 (
6+
i int(11) NOT NULL AUTO_INCREMENT,
7+
c char(32) DEFAULT 'dummy_text',
8+
PRIMARY KEY (i)
9+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
10+
insert into t1(i) values(null);
11+
select * from t1;
12+
i c
13+
1 dummy_text
14+
insert into t1(i) values(null), (null), (null);
15+
select * from t1;
16+
i c
17+
1 dummy_text
18+
2 dummy_text
19+
3 dummy_text
20+
4 dummy_text
21+
show variables like 'binlog_format';
22+
Variable_name Value
23+
binlog_format STATEMENT
24+
show variables like '%auto_increment%';
25+
Variable_name Value
26+
auto_increment_increment 1
27+
auto_increment_offset 1
28+
wsrep_auto_increment_control ON
29+
select * from t1;
30+
i c
31+
1 dummy_text
32+
2 dummy_text
33+
3 dummy_text
34+
4 dummy_text
35+
show variables like 'binlog_format';
36+
Variable_name Value
37+
binlog_format ROW
38+
show variables like '%auto_increment%';
39+
Variable_name Value
40+
auto_increment_increment 2
41+
auto_increment_offset 1
42+
wsrep_auto_increment_control ON
43+
select * from t1;
44+
i c
45+
1 dummy_text
46+
2 dummy_text
47+
3 dummy_text
48+
4 dummy_text
49+
show variables like 'binlog_format';
50+
Variable_name Value
51+
binlog_format ROW
52+
show variables like '%auto_increment%';
53+
Variable_name Value
54+
auto_increment_increment 2
55+
auto_increment_offset 2
56+
wsrep_auto_increment_control ON
57+
DROP TABLE t1;
58+
STOP SLAVE;
59+
RESET SLAVE ALL;
60+
SET GLOBAL binlog_format='ROW';
61+
RESET MASTER;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
SET GLOBAL wsrep_forced_binlog_format='STATEMENT';
2+
SET GLOBAL wsrep_forced_binlog_format='STATEMENT';
3+
CREATE TABLE t1 (
4+
i int(11) NOT NULL AUTO_INCREMENT,
5+
c char(32) DEFAULT 'dummy_text',
6+
PRIMARY KEY (i)
7+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
8+
insert into t1(i) values(null);
9+
select * from t1;
10+
i c
11+
1 dummy_text
12+
insert into t1(i) values(null), (null), (null);
13+
select * from t1;
14+
i c
15+
1 dummy_text
16+
3 dummy_text
17+
5 dummy_text
18+
7 dummy_text
19+
select * from t1;
20+
i c
21+
1 dummy_text
22+
3 dummy_text
23+
5 dummy_text
24+
7 dummy_text
25+
SET GLOBAL wsrep_forced_binlog_format='none';
26+
SET GLOBAL wsrep_forced_binlog_format='none';
27+
drop table t1;
28+
SET SESSION binlog_format='STATEMENT';
29+
show variables like 'binlog_format';
30+
Variable_name Value
31+
binlog_format STATEMENT
32+
SET GLOBAL wsrep_auto_increment_control='OFF';
33+
SET SESSION auto_increment_increment = 3;
34+
SET SESSION auto_increment_offset = 1;
35+
CREATE TABLE t1 (
36+
i int(11) NOT NULL AUTO_INCREMENT,
37+
c char(32) DEFAULT 'dummy_text',
38+
PRIMARY KEY (i)
39+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
40+
insert into t1(i) values(null);
41+
select * from t1;
42+
i c
43+
1 dummy_text
44+
insert into t1(i) values(null), (null), (null);
45+
select * from t1;
46+
i c
47+
1 dummy_text
48+
4 dummy_text
49+
7 dummy_text
50+
10 dummy_text
51+
select * from t1;
52+
i c
53+
1 dummy_text
54+
4 dummy_text
55+
7 dummy_text
56+
10 dummy_text
57+
SET GLOBAL wsrep_auto_increment_control='ON';
58+
SET SESSION binlog_format='ROW';
59+
show variables like 'binlog_format';
60+
Variable_name Value
61+
binlog_format ROW
62+
show variables like '%auto_increment%';
63+
Variable_name Value
64+
auto_increment_increment 2
65+
auto_increment_offset 1
66+
wsrep_auto_increment_control ON
67+
SET GLOBAL wsrep_auto_increment_control='OFF';
68+
show variables like '%auto_increment%';
69+
Variable_name Value
70+
auto_increment_increment 3
71+
auto_increment_offset 1
72+
wsrep_auto_increment_control OFF
73+
SET GLOBAL wsrep_auto_increment_control='ON';
74+
drop table t1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!include ../galera_2nodes_as_slave.cnf
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#
2+
# Test Galera as a slave to a MySQL master
3+
#
4+
# The galera/galera_2node_slave.cnf describes the setup of the nodes
5+
#
6+
7+
--source include/have_innodb.inc
8+
--source include/have_log_bin.inc
9+
10+
# As node #1 is not a Galera node, we connect to node #2 in order to run include/galera_cluster.inc
11+
--connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2
12+
--source include/galera_cluster.inc
13+
14+
--connection node_2
15+
--disable_query_log
16+
--eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$NODE_MYPORT_1;
17+
--enable_query_log
18+
START SLAVE USER='root';
19+
20+
--connection node_1
21+
22+
##
23+
## Verify the correct operation of the auto-increment when
24+
## the binlog format set to the 'STATEMENT' on the master node:
25+
##
26+
27+
SET SESSION binlog_format='STATEMENT';
28+
29+
CREATE TABLE t1 (
30+
i int(11) NOT NULL AUTO_INCREMENT,
31+
c char(32) DEFAULT 'dummy_text',
32+
PRIMARY KEY (i)
33+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
34+
35+
insert into t1(i) values(null);
36+
37+
select * from t1;
38+
39+
insert into t1(i) values(null), (null), (null);
40+
41+
select * from t1;
42+
43+
show variables like 'binlog_format';
44+
show variables like '%auto_increment%';
45+
46+
--connection node_2
47+
--let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
48+
--source include/wait_condition.inc
49+
50+
--let $wait_condition = SELECT COUNT(*) = 4 FROM t1;
51+
--source include/wait_condition.inc
52+
53+
select * from t1;
54+
55+
show variables like 'binlog_format';
56+
show variables like '%auto_increment%';
57+
58+
--connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3
59+
60+
select * from t1;
61+
62+
show variables like 'binlog_format';
63+
show variables like '%auto_increment%';
64+
65+
--connection node_1
66+
DROP TABLE t1;
67+
68+
--connection node_2
69+
--let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
70+
--source include/wait_condition.inc
71+
72+
STOP SLAVE;
73+
RESET SLAVE ALL;
74+
75+
--connection node_1
76+
77+
SET GLOBAL binlog_format='ROW';
78+
79+
RESET MASTER;
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
##
2+
## Tests the auto-increment with binlog in STATEMENT mode.
3+
##
4+
5+
--source include/galera_cluster.inc
6+
--source include/have_innodb.inc
7+
8+
##
9+
## Verify the correct operation of the auto-increment when the binlog
10+
## format artificially set to the 'STATEMENT' (although this mode is
11+
## not recommended in the current version):
12+
##
13+
14+
--connection node_2
15+
SET GLOBAL wsrep_forced_binlog_format='STATEMENT';
16+
17+
--connection node_1
18+
SET GLOBAL wsrep_forced_binlog_format='STATEMENT';
19+
20+
CREATE TABLE t1 (
21+
i int(11) NOT NULL AUTO_INCREMENT,
22+
c char(32) DEFAULT 'dummy_text',
23+
PRIMARY KEY (i)
24+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
25+
26+
insert into t1(i) values(null);
27+
28+
select * from t1;
29+
30+
insert into t1(i) values(null), (null), (null);
31+
32+
select * from t1;
33+
34+
--connection node_2
35+
36+
select * from t1;
37+
38+
SET GLOBAL wsrep_forced_binlog_format='none';
39+
40+
--connection node_1
41+
42+
SET GLOBAL wsrep_forced_binlog_format='none';
43+
44+
drop table t1;
45+
46+
##
47+
## Check the operation when the automatic control over the auto-increment
48+
## settings is switched off, that is, when we use the increment step and
49+
## the offset specified by the user. In the current session, the binlog
50+
## format is set to 'STATEMENT'. It is important that the values of the
51+
## auto-increment options does not changed on other node - it allows us
52+
## to check the correct transmission of the auto-increment options to
53+
## other nodes:
54+
##
55+
56+
--disable_warnings
57+
SET SESSION binlog_format='STATEMENT';
58+
--enable_warnings
59+
60+
show variables like 'binlog_format';
61+
62+
SET GLOBAL wsrep_auto_increment_control='OFF';
63+
64+
SET SESSION auto_increment_increment = 3;
65+
SET SESSION auto_increment_offset = 1;
66+
67+
CREATE TABLE t1 (
68+
i int(11) NOT NULL AUTO_INCREMENT,
69+
c char(32) DEFAULT 'dummy_text',
70+
PRIMARY KEY (i)
71+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
72+
73+
insert into t1(i) values(null);
74+
75+
select * from t1;
76+
77+
insert into t1(i) values(null), (null), (null);
78+
79+
select * from t1;
80+
81+
--connection node_2
82+
83+
select * from t1;
84+
85+
--connection node_1
86+
87+
##
88+
## Verify the return to automatic calculation of the step
89+
## and offset of the auto-increment:
90+
##
91+
92+
SET GLOBAL wsrep_auto_increment_control='ON';
93+
94+
SET SESSION binlog_format='ROW';
95+
96+
show variables like 'binlog_format';
97+
show variables like '%auto_increment%';
98+
99+
##
100+
## Verify the recovery of original user-defined values after
101+
## stopping the automatic control over auto-increment:
102+
##
103+
104+
SET GLOBAL wsrep_auto_increment_control='OFF';
105+
106+
show variables like '%auto_increment%';
107+
108+
##
109+
## Restore original options and drop test table:
110+
##
111+
112+
SET GLOBAL wsrep_auto_increment_control='ON';
113+
114+
drop table t1;

sql/sql_class.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ typedef struct system_variables
660660
uint wsrep_sync_wait;
661661
ulong wsrep_retry_autocommit;
662662
ulong wsrep_OSU_method;
663+
ulong wsrep_auto_increment_control;
663664
#endif
664665
double long_query_time_double;
665666

sql/sql_parse.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6805,18 +6805,17 @@ void THD::reset_for_next_command()
68056805
transactions. Appliers and replayers are either processing ROW
68066806
events or get autoinc variable values from Query_log_event.
68076807
*/
6808-
if (WSREP(thd) && thd->wsrep_exec_mode == LOCAL_STATE) {
6809-
if (wsrep_auto_increment_control)
6810-
{
6811-
if (thd->variables.auto_increment_offset !=
6812-
global_system_variables.auto_increment_offset)
6813-
thd->variables.auto_increment_offset=
6814-
global_system_variables.auto_increment_offset;
6815-
if (thd->variables.auto_increment_increment !=
6816-
global_system_variables.auto_increment_increment)
6817-
thd->variables.auto_increment_increment=
6818-
global_system_variables.auto_increment_increment;
6819-
}
6808+
if (WSREP(thd) && thd->wsrep_exec_mode == LOCAL_STATE &&
6809+
!thd->slave_thread && wsrep_auto_increment_control)
6810+
{
6811+
if (thd->variables.auto_increment_offset !=
6812+
global_system_variables.auto_increment_offset)
6813+
thd->variables.auto_increment_offset=
6814+
global_system_variables.auto_increment_offset;
6815+
if (thd->variables.auto_increment_increment !=
6816+
global_system_variables.auto_increment_increment)
6817+
thd->variables.auto_increment_increment=
6818+
global_system_variables.auto_increment_increment;
68206819
}
68216820
#endif /* WITH_WSREP */
68226821
thd->query_start_used= 0;

0 commit comments

Comments
 (0)