Commit ebb2db59 authored by Jan Lindström's avatar Jan Lindström

MDEV-20715 : Implement system variable to disallow local GTIDs in Galera

Added a new wsrep_mode feature DISALLOW_LOCAL_GTID for this.
Nodes can have GTIDs for local transactions in the following scenarios:

A DDL statement is executed with wsrep_OSU_method=RSU set.
A DML statement writes to a non-InnoDB table.
A DML statement writes to an InnoDB table with wsrep_on=OFF set.

If user has set wsrep_mode=DISALLOW_LOCAL_GTID these operations
produce a error ERROR HY000: Galera replication not supported
parent b47304eb
connection node_2;
connection node_1;
call mtr.add_suppression("WSREP: ALTER TABLE isolation failure");
connection node_1;
CREATE TABLE tab(a int not null primary key) engine=InnoDB;
CREATE TABLE tab1(a int not null primary key) engine=MyISAM;
CREATE TABLE tab2(a int not null primary key) engine=Aria;
CREATE TABLE tab3(a int not null primary key) engine=MEMORY;
SET GLOBAL wsrep_mode = DISALLOW_LOCAL_GTID;
SET SESSION wsrep_OSU_method='RSU';
ALTER TABLE tab FORCE;
ERROR HY000: Galera replication not supported
SET SESSiON sql_log_bin=0;
ALTER TABLE tab FORCE;
SET SESSION wsrep_OSU_method='TOI';
SET SESSION sql_log_bin=1;
SET SESSION wsrep_on=OFF;
INSERT INTO tab VALUES (1);
ERROR HY000: Galera replication not supported
SET SESSiON sql_log_bin=0;
INSERT INTO tab VALUES (1);
SET SESSiON sql_log_bin=1;
SET SESSION wsrep_on=ON;
INSERT INTO tab VALUES (2);
SELECT * FROM tab;
a
1
2
connection node_2;
SELECT * FROM tab;
a
2
connection node_1;
INSERT INTO tab1 VALUES(1);
ERROR HY000: Galera replication not supported
INSERT INTO tab2 VALUES(1);
ERROR HY000: Galera replication not supported
INSERT INTO tab3 VALUES(1);
ERROR HY000: Galera replication not supported
SET GLOBAL wsrep_mode = "DISALLOW_LOCAL_GTID,REPLICATE_MYISAM,REPLICATE_ARIA";
INSERT INTO tab1 VALUES(2);
INSERT INTO tab2 VALUES(2);
INSERT INTO tab3 VALUES(2);
ERROR HY000: Galera replication not supported
SET SESSiON sql_log_bin=0;
INSERT INTO tab1 VALUES(3);
INSERT INTO tab2 VALUES(3);
INSERT INTO tab3 VALUES(3);
SET SESSION sql_log_bin=1;
SET SESSION wsrep_on=OFF;
INSERT INTO tab1 VALUES(4);
ERROR HY000: Galera replication not supported
INSERT INTO tab2 VALUES(4);
ERROR HY000: Galera replication not supported
INSERT INTO tab3 VALUES(4);
ERROR HY000: Galera replication not supported
SET SESSiON sql_log_bin=0;
INSERT INTO tab1 VALUES(5);
INSERT INTO tab2 VALUES(5);
INSERT INTO tab3 VALUES(5);
SET SESSION wsrep_on=ON;
INSERT INTO tab1 VALUES(6);
INSERT INTO tab2 VALUES(6);
INSERT INTO tab3 VALUES(6);
SELECT * FROM tab1;
a
2
3
5
6
SELECT * FROM tab2;
a
2
3
5
6
SELECT * FROM tab3;
a
3
5
6
connection node_2;
SELECT * FROM tab1;
a
2
3
6
SELECT * FROM tab2;
a
2
3
6
SELECT * FROM tab3;
a
connection node_1;
DROP TABLE tab;
DROP TABLE tab1;
DROP TABLE tab2;
DROP TABLE tab3;
connection node_2;
connection node_1;
SELECT @@wsrep_mode;
@@wsrep_mode
SET GLOBAL wsrep_mode=DEFAULT;
SELECT @@wsrep_mode;
@@wsrep_mode
SET SESSION wsrep_mode=DEFAULT;
ERROR HY000: Variable 'wsrep_mode' is a GLOBAL variable and should be set with SET GLOBAL
SELECT @@global.wsrep_mode;
@@global.wsrep_mode
SELECT @@session.wsrep_mode;
ERROR HY000: Variable 'wsrep_mode' is a GLOBAL variable
SET GLOBAL wsrep_mode=A;
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of 'A'
SET GLOBAL wsrep_mode='A';
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of 'A'
SET GLOBAL wsrep_mode=NULL;
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of 'NULL'
SET GLOBAL wsrep_mode=64;
ERROR 42000: Variable 'wsrep_mode' can't be set to the value of '64'
SET GLOBAL wsrep_mode=REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
SET GLOBAL wsrep_mode=1;
SELECT @@wsrep_mode;
@@wsrep_mode
STRICT_REPLICATION
SET GLOBAL wsrep_mode=32;
SELECT @@wsrep_mode;
@@wsrep_mode
DISALLOW_LOCAL_GTID
SET GLOBAL wsrep_mode='';
SELECT @@wsrep_mode;
@@wsrep_mode
SET GLOBAL wsrep_mode=STRICT_REPLICATION;
SELECT @@wsrep_mode;
@@wsrep_mode
STRICT_REPLICATION
SET GLOBAL wsrep_mode=BINLOG_ROW_FORMAT_ONLY;
SELECT @@wsrep_mode;
@@wsrep_mode
BINLOG_ROW_FORMAT_ONLY
SET GLOBAL wsrep_mode=REQUIRED_PRIMARY_KEY;
SELECT @@wsrep_mode;
@@wsrep_mode
REQUIRED_PRIMARY_KEY
SET GLOBAL wsrep_mode=REPLICATE_MYISAM;
SELECT @@wsrep_mode;
@@wsrep_mode
REPLICATE_MYISAM
SET GLOBAL wsrep_mode=REPLICATE_ARIA;
SELECT @@wsrep_mode;
@@wsrep_mode
REPLICATE_ARIA
SET GLOBAL wsrep_mode=DISALLOW_LOCAL_GTID;
SELECT @@wsrep_mode;
@@wsrep_mode
DISALLOW_LOCAL_GTID
SET GLOBAL wsrep_mode='STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY';
SELECT @@wsrep_mode;
@@wsrep_mode
STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY
SET GLOBAL wsrep_mode='STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY,REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM,REPLICATE_ARIA,DISALLOW_LOCAL_GTID';
SELECT @@wsrep_mode;
@@wsrep_mode
STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY,REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM,REPLICATE_ARIA,DISALLOW_LOCAL_GTID
SET GLOBAL wsrep_mode='BINLOG_ROW_FORMAT_ONLY,STRICT_REPLICATION';
SELECT @@wsrep_mode;
@@wsrep_mode
STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY
SET GLOBAL wsrep_mode='STRICT_REPLICATION,REQUIRED_PRIMARY_KEY,REPLICATE_ARIA,DISALLOW_LOCAL_GTID';
SELECT @@wsrep_mode;
@@wsrep_mode
STRICT_REPLICATION,REQUIRED_PRIMARY_KEY,REPLICATE_ARIA,DISALLOW_LOCAL_GTID
SET GLOBAL wsrep_mode=DEFAULT;
--source include/galera_cluster.inc
--source include/have_aria.inc
#
# Nodes can have GTIDs for local transactions in the following scenarios:
#
# A DDL statement is executed with wsrep_OSU_method=RSU set.
# A DML statement writes to a non-InnoDB table.
# A DML statement writes to an InnoDB table with wsrep_on=OFF set.
#
call mtr.add_suppression("WSREP: ALTER TABLE isolation failure");
#
# A DDL statement is executed with wsrep_OSU_method=RSU set.
#
--connection node_1
CREATE TABLE tab(a int not null primary key) engine=InnoDB;
CREATE TABLE tab1(a int not null primary key) engine=MyISAM;
CREATE TABLE tab2(a int not null primary key) engine=Aria;
CREATE TABLE tab3(a int not null primary key) engine=MEMORY;
SET GLOBAL wsrep_mode = DISALLOW_LOCAL_GTID;
SET SESSION wsrep_OSU_method='RSU';
--error ER_GALERA_REPLICATION_NOT_SUPPORTED
ALTER TABLE tab FORCE;
SET SESSiON sql_log_bin=0;
ALTER TABLE tab FORCE;
SET SESSION wsrep_OSU_method='TOI';
#
# A DML statement writes to an InnoDB table with wsrep_on=OFF set.
#
SET SESSION sql_log_bin=1;
SET SESSION wsrep_on=OFF;
--error ER_GALERA_REPLICATION_NOT_SUPPORTED
INSERT INTO tab VALUES (1);
SET SESSiON sql_log_bin=0;
INSERT INTO tab VALUES (1);
SET SESSiON sql_log_bin=1;
SET SESSION wsrep_on=ON;
INSERT INTO tab VALUES (2);
SELECT * FROM tab;
--connection node_2
SELECT * FROM tab;
#
# A DML statement writes to a non-InnoDB table.
#
--connection node_1
--error ER_GALERA_REPLICATION_NOT_SUPPORTED
INSERT INTO tab1 VALUES(1);
--error ER_GALERA_REPLICATION_NOT_SUPPORTED
INSERT INTO tab2 VALUES(1);
--error ER_GALERA_REPLICATION_NOT_SUPPORTED
INSERT INTO tab3 VALUES(1);
#
# Set MyISAM and Aria replication on using TOI
#
SET GLOBAL wsrep_mode = "DISALLOW_LOCAL_GTID,REPLICATE_MYISAM,REPLICATE_ARIA";
INSERT INTO tab1 VALUES(2);
INSERT INTO tab2 VALUES(2);
--error ER_GALERA_REPLICATION_NOT_SUPPORTED
INSERT INTO tab3 VALUES(2);
SET SESSiON sql_log_bin=0;
INSERT INTO tab1 VALUES(3);
INSERT INTO tab2 VALUES(3);
INSERT INTO tab3 VALUES(3);
SET SESSION sql_log_bin=1;
SET SESSION wsrep_on=OFF;
--error ER_GALERA_REPLICATION_NOT_SUPPORTED
INSERT INTO tab1 VALUES(4);
--error ER_GALERA_REPLICATION_NOT_SUPPORTED
INSERT INTO tab2 VALUES(4);
--error ER_GALERA_REPLICATION_NOT_SUPPORTED
INSERT INTO tab3 VALUES(4);
SET SESSiON sql_log_bin=0;
INSERT INTO tab1 VALUES(5);
INSERT INTO tab2 VALUES(5);
INSERT INTO tab3 VALUES(5);
SET SESSION wsrep_on=ON;
INSERT INTO tab1 VALUES(6);
INSERT INTO tab2 VALUES(6);
INSERT INTO tab3 VALUES(6);
SELECT * FROM tab1;
SELECT * FROM tab2;
SELECT * FROM tab3;
--connection node_2
SELECT * FROM tab1;
SELECT * FROM tab2;
SELECT * FROM tab3;
--connection node_1
--disable_query_log
SET SESSION sql_log_bin=DEFAULT;
SET GLOBAL wsrep_mode=DEFAULT;
set GLOBAL wsrep_OSU_method=DEFAULT;
--enable_query_log
DROP TABLE tab;
DROP TABLE tab1;
DROP TABLE tab2;
DROP TABLE tab3;
--source include/galera_cluster.inc
# default
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=DEFAULT;
SELECT @@wsrep_mode;
--error ER_GLOBAL_VARIABLE
SET SESSION wsrep_mode=DEFAULT;
SELECT @@global.wsrep_mode;
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
SELECT @@session.wsrep_mode;
#
# Incorrect input
#
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL wsrep_mode=A;
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL wsrep_mode='A';
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL wsrep_mode=NULL;
--error ER_WRONG_VALUE_FOR_VAR
SET GLOBAL wsrep_mode=64;
--error ER_PARSE_ERROR
SET GLOBAL wsrep_mode=REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM;
#
# Correct input
#
SET GLOBAL wsrep_mode=1;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=32;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode='';
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=STRICT_REPLICATION;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=BINLOG_ROW_FORMAT_ONLY;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=REQUIRED_PRIMARY_KEY;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=REPLICATE_MYISAM;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=REPLICATE_ARIA;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode=DISALLOW_LOCAL_GTID;
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode='STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY';
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode='STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY,REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM,REPLICATE_ARIA,DISALLOW_LOCAL_GTID';
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode='BINLOG_ROW_FORMAT_ONLY,STRICT_REPLICATION';
SELECT @@wsrep_mode;
SET GLOBAL wsrep_mode='STRICT_REPLICATION,REQUIRED_PRIMARY_KEY,REPLICATE_ARIA,DISALLOW_LOCAL_GTID';
SELECT @@wsrep_mode;
# reset
SET GLOBAL wsrep_mode=DEFAULT;
......@@ -342,7 +342,7 @@ VARIABLE_COMMENT Set of WSREP features that are enabled.
NUMERIC_MIN_VALUE NULL
NUMERIC_MAX_VALUE NULL
NUMERIC_BLOCK_SIZE NULL
ENUM_VALUE_LIST STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY,REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM,REPLICATE_ARIA
ENUM_VALUE_LIST STRICT_REPLICATION,BINLOG_ROW_FORMAT_ONLY,REQUIRED_PRIMARY_KEY,REPLICATE_MYISAM,REPLICATE_ARIA,DISALLOW_LOCAL_GTID
READ_ONLY NO
COMMAND_LINE_ARGUMENT REQUIRED
GLOBAL_VALUE_PATH NULL
......
......@@ -4445,7 +4445,41 @@ bool open_tables(THD *thd, const DDL_options_st &options,
error= TRUE;
goto error;
}
#endif
/* If user has issued wsrep_on = OFF and wsrep was on before
we need to check is local gtid feature disabled */
if (thd->wsrep_was_on &&
thd->variables.sql_log_bin == 1 &&
!WSREP(thd) &&
wsrep_check_mode(WSREP_MODE_DISALLOW_LOCAL_GTID))
{
enum_sql_command sql_command= thd->lex->sql_command;
bool is_dml_stmt= thd->get_command() != COM_STMT_PREPARE &&
(sql_command == SQLCOM_INSERT ||
sql_command == SQLCOM_INSERT_SELECT ||
sql_command == SQLCOM_REPLACE ||
sql_command == SQLCOM_REPLACE_SELECT ||
sql_command == SQLCOM_UPDATE ||
sql_command == SQLCOM_UPDATE_MULTI ||
sql_command == SQLCOM_LOAD ||
sql_command == SQLCOM_DELETE);
if (is_dml_stmt && !is_temporary_table(tables))
{
/* wsrep_mode = WSREP_MODE_DISALLOW_LOCAL_GTID, treat as error */
my_error(ER_GALERA_REPLICATION_NOT_SUPPORTED, MYF(0));
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_OPTION_PREVENTS_STATEMENT,
"You can't execute statements that would generate local "
"GTIDs when wsrep_mode = DISALLOW_LOCAL_GTID is set. "
"Try disabling binary logging with SET sql_log_bin=0 "
"to execute this statement.");
error= TRUE;
goto error;
}
}
#endif /* WITH_WSREP */
}
error:
......
......@@ -713,6 +713,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
wsrep_current_gtid_seqno(0),
wsrep_affected_rows(0),
wsrep_has_ignored_error(false),
wsrep_was_on(false),
wsrep_ignore_table(false),
wsrep_aborter(0),
......
......@@ -5239,6 +5239,8 @@ class THD: public THD_count, /* this must be first */
uint64 wsrep_current_gtid_seqno;
ulong wsrep_affected_rows;
bool wsrep_has_ignored_error;
/* true if wsrep_on was ON in last wsrep_on_update */
bool wsrep_was_on;
/*
When enabled, do not replicate/binlog updates from the current table that's
......
......@@ -5933,6 +5933,7 @@ static const char *wsrep_mode_names[]=
"REQUIRED_PRIMARY_KEY",
"REPLICATE_MYISAM",
"REPLICATE_ARIA",
"DISALLOW_LOCAL_GTID",
NullS
};
static Sys_var_set Sys_wsrep_mode(
......
......@@ -1069,7 +1069,6 @@ void wsrep_recover()
{
WSREP_INFO("Recovered position: %s", oss.str().c_str());
}
}
......@@ -1424,9 +1423,23 @@ bool wsrep_check_mode_after_open_table (THD *thd,
/* InnoDB table doesn't have explicit primary-key defined. */
wsrep_push_warning(thd, WSREP_REQUIRE_PRIMARY_KEY, hton, tables);
}
if (db_type != DB_TYPE_INNODB &&
thd->variables.sql_log_bin == 1 &&
wsrep_check_mode(WSREP_MODE_DISALLOW_LOCAL_GTID))
{
/* Table is not an InnoDB table and local GTIDs are disallowed */
my_error(ER_GALERA_REPLICATION_NOT_SUPPORTED, MYF(0));
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_OPTION_PREVENTS_STATEMENT,
"You can't execute statements that would generate local "
"GTIDs when wsrep_mode = DISALLOW_LOCAL_GTID is set. "
"Try disabling binary logging with SET sql_log_bin=0 "
"to execute this statement.");
goto wsrep_error_label;
}
}
}
return true;
......@@ -2610,6 +2623,23 @@ static int wsrep_RSU_begin(THD *thd, const char *db_, const char *table_)
{
WSREP_DEBUG("RSU BEGIN: %lld, : %s", wsrep_thd_trx_seqno(thd),
wsrep_thd_query(thd));
if (thd->variables.wsrep_OSU_method == WSREP_OSU_RSU &&
thd->variables.sql_log_bin == 1 &&
wsrep_check_mode(WSREP_MODE_DISALLOW_LOCAL_GTID))
{
/* wsrep_mode = WSREP_MODE_DISALLOW_LOCAL_GTID, treat as error */
my_error(ER_GALERA_REPLICATION_NOT_SUPPORTED, MYF(0));
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_OPTION_PREVENTS_STATEMENT,
"You can't execute statements that would generate local "
"GTIDs when wsrep_mode = DISALLOW_LOCAL_GTID is set. "
"Try disabling binary logging with SET sql_log_bin=0 "
"to execute this statement.");
return -1;
}
if (thd->wsrep_cs().begin_rsu(5000))
{
WSREP_WARN("RSU begin failed");
......
......@@ -140,7 +140,8 @@ enum enum_wsrep_mode {
WSREP_MODE_BINLOG_ROW_FORMAT_ONLY= (1ULL << 1),
WSREP_MODE_REQUIRED_PRIMARY_KEY= (1ULL << 2),
WSREP_MODE_REPLICATE_MYISAM= (1ULL << 3),
WSREP_MODE_REPLICATE_ARIA= (1ULL << 4)
WSREP_MODE_REPLICATE_ARIA= (1ULL << 4),
WSREP_MODE_DISALLOW_LOCAL_GTID= (1ULL << 5)
};
// Streaming Replication
......
......@@ -91,8 +91,10 @@ static bool refresh_provider_options()
}
}
static void wsrep_set_wsrep_on()
static void wsrep_set_wsrep_on(THD* thd)
{
if (thd)
thd->wsrep_was_on= WSREP_ON_;
WSREP_ON_= global_system_variables.wsrep_on && wsrep_provider &&
strcmp(wsrep_provider, WSREP_NONE);
}
......@@ -125,7 +127,7 @@ bool wsrep_on_update (sys_var *self, THD* thd, enum_var_type var_type)
thd->variables.wsrep_on= global_system_variables.wsrep_on= saved_wsrep_on;
}
wsrep_set_wsrep_on();
wsrep_set_wsrep_on(thd);
return false;
}
......@@ -445,7 +447,7 @@ bool wsrep_provider_update (sys_var *self, THD* thd, enum_var_type type)
if (!rcode)
refresh_provider_options();
wsrep_set_wsrep_on();
wsrep_set_wsrep_on(thd);
mysql_mutex_lock(&LOCK_global_system_variables);
return rcode;
......@@ -465,7 +467,7 @@ void wsrep_provider_init (const char* value)
if (wsrep_provider) my_free((void *)wsrep_provider);
wsrep_provider= my_strdup(PSI_INSTRUMENT_MEM, value, MYF(0));
wsrep_set_wsrep_on();
wsrep_set_wsrep_on(NULL);
}
bool wsrep_provider_options_check(sys_var *self, THD* thd, set_var* var)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment