Skip to content

Commit eb4123e

Browse files
Daniele SciasciaJan Lindström
authored andcommitted
More fixes to variable wsrep_on
* Disallow setting wsrep_on = 1 if wsrep_provider is unset. Also, move wsrep_on_basic from sys_vars to wsrep suite: this test now requires to run with wsrep_provider set * Disallow setting @@session.wsrep_on = 1 when @@global.wsrep_on = 0 * Handle the case where a new connection turns @@global.wsrep_on from off to on. In this case we would miss a call to wsrep_open, causing unexpected states in wsrep::client_state (causing assertions). * Disable wsrep.MDEV-22443 because it is no longer possible to enable wsrep_on, if server is started with wsrep_provider='none' Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
1 parent 57caff2 commit eb4123e

11 files changed

+237
-16
lines changed

mysql-test/suite/galera/r/galera_var_wsrep_on_off.result

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ SELECT COUNT(*) = 1 FROM t1 WHERE f1 = 3;
2222
COUNT(*) = 1
2323
1
2424
DROP TABLE t1;
25+
connection node_1;
2526
START TRANSACTION;
2627
SET SESSION wsrep_on=OFF;
2728
ERROR 25000: You are not allowed to execute this command in a transaction
2829
SET GLOBAL wsrep_on=OFF;
2930
ERROR 25000: You are not allowed to execute this command in a transaction
3031
COMMIT;
32+
connection node_1;
3133
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
3234
START TRANSACTION;
3335
INSERT INTO t1 VALUES (1);
@@ -68,3 +70,58 @@ SET GLOBAL wsrep_on = ON;
6870
SHOW SESSION VARIABLES LIKE 'wsrep_on';
6971
Variable_name Value
7072
wsrep_on ON
73+
disconnect node_1b;
74+
connection node_1;
75+
SET GLOBAL wsrep_on = OFF;
76+
SET SESSION wsrep_on = ON;
77+
ERROR HY000: Can't enable @@session.wsrep_on, while @@global.wsrep_on is disabled
78+
SET GLOBAL wsrep_on = ON;
79+
SET SESSION wsrep_on = ON;
80+
connection node_1;
81+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
82+
SET GLOBAL wsrep_on = OFF;
83+
connect node_1b, 127.0.0.1, root, , test, $NODE_MYPORT_1;;
84+
connection node_1b;
85+
SHOW SESSION VARIABLES LIKE 'wsrep_on';
86+
Variable_name Value
87+
wsrep_on OFF
88+
SHOW GLOBAL VARIABLES LIKE 'wsrep_on';
89+
Variable_name Value
90+
wsrep_on OFF
91+
SET GLOBAL wsrep_on = ON;
92+
START TRANSACTION;
93+
INSERT INTO t1 VALUES(1);
94+
COMMIT;
95+
SELECT * FROM t1;
96+
f1
97+
1
98+
connection node_2;
99+
SELECT * FROM t1;
100+
f1
101+
1
102+
DROP TABLE t1;
103+
connection node_1;
104+
SET SESSION wsrep_on = OFF;
105+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
106+
INSERT INTO t1 VALUES (1);
107+
START TRANSACTION;
108+
INSERT INTO t1 VALUES (2);
109+
COMMIT;
110+
DROP TABLE t1;
111+
connection node_2;
112+
SHOW TABLES;
113+
Tables_in_test
114+
connection node_1;
115+
SET SESSION wsrep_on = ON;
116+
SET GLOBAL wsrep_on = OFF;
117+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
118+
INSERT INTO t1 VALUES (1);
119+
START TRANSACTION;
120+
INSERT INTO t1 VALUES (2);
121+
COMMIT;
122+
connection node_2;
123+
SHOW TABLES;
124+
Tables_in_test
125+
connection node_1;
126+
DROP TABLE t1;
127+
SET GLOBAL wsrep_on = ON;

mysql-test/suite/galera/t/galera_var_wsrep_on_off.test

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ DROP TABLE t1;
3636
# active transaction.
3737
#
3838

39+
--connection node_1
3940
START TRANSACTION;
4041
--error ER_CANT_DO_THIS_DURING_AN_TRANSACTION
4142
SET SESSION wsrep_on=OFF;
@@ -49,6 +50,7 @@ COMMIT;
4950
# @@session.wsrep_on of current sessions
5051
#
5152

53+
--connection node_1
5254
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
5355
START TRANSACTION;
5456
INSERT INTO t1 VALUES (1);
@@ -75,6 +77,7 @@ DROP TABLE t1;
7577
#
7678
# New connections inherit @@session.wsrep_on from @@global.wsrep_on
7779
#
80+
7881
--connection node_1
7982
SET GLOBAL wsrep_on = OFF;
8083

@@ -87,3 +90,78 @@ DROP TABLE t2;
8790

8891
SET GLOBAL wsrep_on = ON;
8992
SHOW SESSION VARIABLES LIKE 'wsrep_on';
93+
94+
--disconnect node_1b
95+
96+
97+
#
98+
# Can't set @@session.wsrep_on = ON, while @@global.wsrep_on = OFF
99+
#
100+
101+
--connection node_1
102+
SET GLOBAL wsrep_on = OFF;
103+
--error ER_WRONG_ARGUMENTS
104+
SET SESSION wsrep_on = ON;
105+
106+
SET GLOBAL wsrep_on = ON;
107+
SET SESSION wsrep_on = ON;
108+
109+
110+
#
111+
# @@global.wsrep_on = OFF followed by @@global.wsrep_on = ON
112+
# in a new connection
113+
#
114+
115+
--connection node_1
116+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
117+
SET GLOBAL wsrep_on = OFF;
118+
--connect node_1b, 127.0.0.1, root, , test, $NODE_MYPORT_1;
119+
--connection node_1b
120+
SHOW SESSION VARIABLES LIKE 'wsrep_on';
121+
SHOW GLOBAL VARIABLES LIKE 'wsrep_on';
122+
SET GLOBAL wsrep_on = ON;
123+
START TRANSACTION;
124+
INSERT INTO t1 VALUES(1);
125+
COMMIT;
126+
127+
SELECT * FROM t1;
128+
129+
--connection node_2
130+
SELECT * FROM t1;
131+
132+
DROP TABLE t1;
133+
134+
135+
#
136+
# Test single statement, multi statement, and
137+
# TOI tansactions while @@session.wsrep_on = OFF
138+
# and then same @@global.wsrep_on = OFF.
139+
# Notice, the combination @@global.wsrep_on = OFF
140+
# and @@session.wsrep_on = ON is not not possible,
141+
# (as tested above in this test case)
142+
#
143+
144+
--connection node_1
145+
SET SESSION wsrep_on = OFF;
146+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
147+
INSERT INTO t1 VALUES (1);
148+
START TRANSACTION;
149+
INSERT INTO t1 VALUES (2);
150+
COMMIT;
151+
DROP TABLE t1;
152+
--connection node_2
153+
SHOW TABLES;
154+
--connection node_1
155+
SET SESSION wsrep_on = ON;
156+
157+
SET GLOBAL wsrep_on = OFF;
158+
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY);
159+
INSERT INTO t1 VALUES (1);
160+
START TRANSACTION;
161+
INSERT INTO t1 VALUES (2);
162+
COMMIT;
163+
--connection node_2
164+
SHOW TABLES;
165+
--connection node_1
166+
DROP TABLE t1;
167+
SET GLOBAL wsrep_on = ON;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SET GLOBAL wsrep_on=ON;
2+
ERROR HY000: WSREP (galera) can't be enabled if the wsrep_provider is unset or set to 'none'
3+
SELECT @@global.wsrep_on;
4+
@@global.wsrep_on
5+
0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--source include/not_embedded.inc
2+
3+
#
4+
# @@global.wsrep_on is not allowed if there
5+
# is no wsrep_provider
6+
#
7+
--error ER_WRONG_ARGUMENTS
8+
SET GLOBAL wsrep_on=ON;
9+
SELECT @@global.wsrep_on;

mysql-test/suite/wsrep/disabled.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
mdev_6832: wsrep_provider is read-only for security reasons
1515
MDEV-23092: wsrep_provider is read-only for security reasons
1616
wsrep_variables_no_provider: wsrep_provider is read-only for security reasons
17+
MDEV-22443: it is no longer allowed enable wsrep_on if wsrep_provider is 'none'

mysql-test/suite/sys_vars/r/wsrep_on_basic.result renamed to mysql-test/suite/wsrep/r/wsrep_on_basic.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ SET @wsrep_on_session_saved = @@session.wsrep_on;
77
# default
88
SELECT @@global.wsrep_on;
99
@@global.wsrep_on
10-
0
10+
1
1111
SELECT @@session.wsrep_on;
1212
@@session.wsrep_on
13-
0
13+
1
1414

1515
# scope and valid values
1616
SET @@global.wsrep_on=OFF;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--wsrep-provider=$WSREP_PROVIDER --binlog_format=ROW --wsrep-cluster-address=gcomm://

mysql-test/suite/sys_vars/t/wsrep_on_basic.test renamed to mysql-test/suite/wsrep/t/wsrep_on_basic.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
--source include/have_wsrep.inc
2+
--source include/have_wsrep_provider.inc
3+
--source include/have_innodb.inc
24

35
--echo #
46
--echo # wsrep_on

sql/service_wsrep.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,23 @@ extern "C" my_bool wsrep_get_debug()
120120
return wsrep_debug;
121121
}
122122

123+
/*
124+
Test if this connection is a true local (user) connection and not
125+
a replication or wsrep applier thread.
126+
127+
Note that this is only usable for galera (as there are other kinds
128+
of system threads, and only if WSREP_NNULL() is tested by the caller.
129+
*/
123130
extern "C" my_bool wsrep_thd_is_local(const THD *thd)
124131
{
125132
/*
126-
async replication IO and background threads have nothing to replicate in the cluster,
127-
marking them as non-local here to prevent write set population and replication
133+
async replication IO and background threads have nothing to
134+
replicate in the cluster, marking them as non-local here to
135+
prevent write set population and replication
128136
129-
async replication SQL thread, applies client transactions from mariadb master
130-
and will be replicated into cluster
131-
*/
137+
async replication SQL thread, applies client transactions from
138+
mariadb master and will be replicated into cluster
139+
*/
132140
return (
133141
thd->system_thread != SYSTEM_THREAD_SLAVE_BACKGROUND &&
134142
thd->system_thread != SYSTEM_THREAD_SLAVE_IO &&

sql/wsrep_trans_observer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,16 @@ static inline void wsrep_close(THD* thd)
433433
DBUG_VOID_RETURN;
434434
}
435435

436+
static inline void wsrep_cleanup(THD* thd)
437+
{
438+
DBUG_ENTER("wsrep_cleanup");
439+
if (thd->wsrep_cs().state() != wsrep::client_state::s_none)
440+
{
441+
thd->wsrep_cs().cleanup();
442+
}
443+
DBUG_VOID_RETURN;
444+
}
445+
436446
static inline void
437447
wsrep_wait_rollback_complete_and_acquire_ownership(THD *thd)
438448
{

0 commit comments

Comments
 (0)