Skip to content
/ server Public

Commit 48f04bb

Browse files
MDEV-38073: Always use tx_read_only=false for Wsrep system threads
Apparently, there was a separate issue with applier thread variables: wsrep_plugins_post_init() would overwrite thd->variables for every applier thread and forget to restore proper read only context. Then, upon every server transaction termination, trans_reset_one_shot_statistics() would set thread's read only context to the one stored in thd->variables, thus spoiling the read only context value for appliers.
1 parent 23bfe99 commit 48f04bb

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
connection node_2;
2+
connection node_1;
3+
connection node_2;
4+
connection node_1;
5+
CREATE TABLE t1 (id INT PRIMARY KEY) ENGINE=InnoDB;
6+
SET SESSION wsrep_trx_fragment_size=1;
7+
START TRANSACTION;
8+
INSERT INTO t1 VALUES (1);
9+
INSERT INTO t1 VALUES (2);
10+
COMMIT;
11+
connection node_2;
12+
SELECT COUNT(*) = 2 FROM t1;
13+
COUNT(*) = 2
14+
1
15+
connection node_2;
16+
connection node_1;
17+
DROP TABLE t1;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# Ensure that the transaction_read_only option does not apply to Wsrep system
3+
# threads (schema and appliers) and that the cluster keeps functioning.
4+
#
5+
6+
--source include/galera_cluster.inc
7+
--source include/have_innodb.inc
8+
--source include/big_test.inc
9+
10+
# Restart the node 2 in transaction_read_only mode.
11+
--connection node_2
12+
--source include/shutdown_mysqld.inc
13+
--let $start_mysqld_params=--transaction_read_only=TRUE
14+
--source include/start_mysqld.inc
15+
16+
--connection node_1
17+
CREATE TABLE t1 (id INT PRIMARY KEY) ENGINE=InnoDB;
18+
19+
# Note: this is not obligatory, but we want to test
20+
# SR transactions as well.
21+
SET SESSION wsrep_trx_fragment_size=1;
22+
23+
START TRANSACTION;
24+
INSERT INTO t1 VALUES (1);
25+
INSERT INTO t1 VALUES (2);
26+
COMMIT;
27+
28+
--connection node_2
29+
SELECT COUNT(*) = 2 FROM t1;
30+
31+
# Restart the node 2 in normal mode.
32+
--connection node_2
33+
--source include/shutdown_mysqld.inc
34+
--let $start_mysqld_params=
35+
--source include/start_mysqld.inc
36+
37+
# Cleanup
38+
--connection node_1
39+
DROP TABLE t1;

sql/sql_plugin.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4543,6 +4543,8 @@ my_bool post_init_callback(THD *thd, void *)
45434543
set_current_thd(thd);
45444544
plugin_thdvar_init(thd);
45454545

4546+
// Restore proper transaction read-only context
4547+
thd->variables.tx_read_only= false;
45464548
// Restore option_bits
45474549
thd->variables.option_bits= option_bits_saved;
45484550
}

sql/wsrep_high_priority_service.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ Wsrep_high_priority_service::Wsrep_high_priority_service(THD* thd)
168168
*/
169169
thd->variables.option_bits|= OPTION_BIN_LOG;
170170

171+
/* Allow applying in a transaction read-only context */
172+
thd->tx_read_only= false;
173+
thd->variables.tx_read_only= false;
174+
171175
thd->net.vio= 0;
172176
thd->reset_db(&db_str);
173177
thd->clear_error();

sql/wsrep_schema.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ static void wsrep_init_thd_variables(THD *thd)
719719
{
720720
/* No Galera replication */
721721
thd->variables.wsrep_on= 0;
722+
/* Allow modifications in a transaction read-only context */
723+
thd->tx_read_only= false;
724+
thd->variables.tx_read_only= false;
722725
/* No binlogging */
723726
thd->variables.sql_log_bin= 0;
724727
thd->variables.option_bits&= ~OPTION_BIN_LOG;

sql/wsrep_storage_service.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Wsrep_storage_service::Wsrep_storage_service(THD* thd)
5555

5656
/* No binlogging */
5757

58+
/* Allow modifications in a transaction read-only context */
59+
thd->tx_read_only= false;
60+
thd->variables.tx_read_only= false;
61+
5862
/* No general log */
5963
thd->variables.option_bits |= OPTION_LOG_OFF;
6064

0 commit comments

Comments
 (0)