Skip to content

Instantly share code, notes, and snippets.

@nirbhayc
Created December 14, 2016 02:29
Show Gist options
  • Save nirbhayc/edd27c6d5b5861dcf1fc99a0f2f762d0 to your computer and use it in GitHub Desktop.
Save nirbhayc/edd27c6d5b5861dcf1fc99a0f2f762d0 to your computer and use it in GitHub Desktop.
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 5169b7c..b214a17 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2649,13 +2649,16 @@ mysql_execute_command(THD *thd)
}
/*
- Bail out if DB snapshot has not been installed. We however, allow SET,
- SHOW and SELECT queries (only if wsrep_dirty_reads is set).
+ Bail out if DB snapshot has not been installed. SET and SHOW commands,
+ however, are always allowed.
+
+ We additionally allow all other commands that do not change data in
+ case wsrep_dirty_reads is enabled.
*/
if (lex->sql_command != SQLCOM_SET_OPTION &&
!wsrep_is_show_query(lex->sql_command) &&
!(thd->variables.wsrep_dirty_reads &&
- lex->sql_command == SQLCOM_SELECT) &&
+ !is_update_query(lex->sql_command)) &&
!wsrep_node_is_ready(thd))
goto error;
}
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index 0518e43..bb349e7 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -4976,8 +4976,9 @@ static Sys_var_mybool Sys_wsrep_restart_slave(
GLOBAL_VAR(wsrep_restart_slave), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
static Sys_var_mybool Sys_wsrep_dirty_reads(
- "wsrep_dirty_reads", "Do not reject SELECT queries even when the node "
- "is not ready.", SESSION_ONLY(wsrep_dirty_reads), NO_CMD_LINE,
+ "wsrep_dirty_reads",
+ "Allow reads even when the node is not in the primary component.",
+ SESSION_VAR(wsrep_dirty_reads), CMD_LINE(OPT_ARG),
DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG);
static Sys_var_uint Sys_wsrep_gtid_domain_id(
diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc
index 0deb19d..62d7b7e 100644
--- a/sql/wsrep_mysqld.cc
+++ b/sql/wsrep_mysqld.cc
@@ -96,6 +96,8 @@ bool wsrep_new_cluster = false; // Bootstrap the cluster ?
bool wsrep_gtid_mode = 0;
// gtid_domain_id for galera transactions.
uint32 wsrep_gtid_domain_id = 0;
+// Allow reads even if the node is not in the primary component.
+bool wsrep_dirty_reads = false;
/*
* End configuration options
@@ -958,6 +960,8 @@ bool wsrep_must_sync_wait (THD* thd, uint mask)
{
return (thd->variables.wsrep_sync_wait & mask) &&
thd->variables.wsrep_on &&
+ !(thd->variables.wsrep_dirty_reads &&
+ !is_update_query(thd->lex->sql_command)) &&
!thd->in_active_multi_stmt_transaction() &&
thd->wsrep_conflict_state != REPLAYING &&
thd->wsrep_sync_wait_gtid.seqno == WSREP_SEQNO_UNDEFINED;
diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h
index 04ccc1a..cf549ff 100644
--- a/sql/wsrep_mysqld.h
+++ b/sql/wsrep_mysqld.h
@@ -89,6 +89,7 @@ extern ulong wsrep_running_threads;
extern bool wsrep_new_cluster;
extern bool wsrep_gtid_mode;
extern uint32 wsrep_gtid_domain_id;
+extern bool wsrep_dirty_reads;
enum enum_wsrep_OSU_method {
WSREP_OSU_TOI,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment