Skip to content

Commit

Permalink
refs #181
Browse files Browse the repository at this point in the history
- Galera related errors in mysql slave applying will now cause slave to abort
  • Loading branch information
sjaakola committed Sep 6, 2015
1 parent 3b80cdd commit a35c12f
Showing 1 changed file with 47 additions and 18 deletions.
65 changes: 47 additions & 18 deletions sql/rpl_slave.cc
Expand Up @@ -3858,6 +3858,14 @@ apply_event_and_update_pos(Log_event** ptr_ev, THD* thd, Relay_log_info* rli)
DBUG_RETURN(SLAVE_APPLY_EVENT_AND_UPDATE_POS_OK);

exec_res= ev->apply_event(rli);
#ifdef WITH_WSREP
if (exec_res && thd->wsrep_conflict_state != NO_CONFLICT)
{
WSREP_DEBUG("SQL apply failed, res %d conflict state: %d",
exec_res, thd->wsrep_conflict_state);
rli->abort_slave = 1;
}
#endif

if (!exec_res && (ev->worker != rli))
{
Expand Down Expand Up @@ -4365,6 +4373,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli)
Hence deferred events wont be deleted here.
They will be deleted in Deferred_log_events::rewind() funciton.
*/
WSREP_DEBUG("apply_event_and_update_pos result: %d", exec_res);
if (*ptr_ev)
{
DBUG_ASSERT(*ptr_ev == ev); // event remains to belong to Coordinator
Expand Down Expand Up @@ -4408,6 +4417,12 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli)
DBUG_RETURN(1);
}

#ifdef WITH_WSREP
mysql_mutex_lock(&thd->LOCK_wsrep_thd);
if (thd->wsrep_conflict_state == NO_CONFLICT)
{
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
#endif /* WITH_WSREP */
if (slave_trans_retries)
{
int UNINIT_VAR(temp_err);
Expand Down Expand Up @@ -4486,6 +4501,10 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli)
rli->trans_retries));
}
}
#ifdef WITH_WSREP
} else mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
#endif /* WITH_WSREP */

if (exec_res)
delete ev;
DBUG_RETURN(exec_res);
Expand Down Expand Up @@ -6218,6 +6237,13 @@ log '%s' at position %s, relay log '%s' position: %s", rli->get_rpl_log_name(),

if (exec_relay_log_event(thd,rli))
{
#ifdef WITH_WSREP
if (thd->wsrep_conflict_state != NO_CONFLICT)
{
wsrep_node_dropped = 1;
rli->abort_slave = 1;
}
#endif /* WITH_WSREP */
DBUG_PRINT("info", ("exec_relay_log_event() failed"));
// do not scare the user if SQL thread was simply killed or stopped
if (!sql_slave_killed(thd,rli))
Expand Down Expand Up @@ -6289,8 +6315,8 @@ llstr(rli->get_group_master_log_pos(), llbuff));
#ifdef WITH_WSREP
if (WSREP_ON && last_errno == ER_UNKNOWN_COM_ERROR)
{
wsrep_node_dropped= TRUE;
}
wsrep_node_dropped= TRUE;
}
#endif /* WITH_WSREP */
}
goto err;
Expand Down Expand Up @@ -6379,22 +6405,25 @@ llstr(rli->get_group_master_log_pos(), llbuff));
/* if slave stopped due to node going non primary, we set global flag to
trigger automatic restart of slave when node joins back to cluster
*/
if (wsrep_node_dropped && wsrep_restart_slave)
{
if (wsrep_ready)
{
WSREP_INFO("Slave error due to node temporarily non-primary"
"SQL slave will continue");
wsrep_node_dropped= FALSE;
mysql_mutex_unlock(&rli->run_lock);
goto wsrep_restart_point;
} else {
WSREP_INFO("Slave error due to node going non-primary");
WSREP_INFO("wsrep_restart_slave was set and therefore slave will be "
"automatically restarted when node joins back to cluster");
wsrep_restart_slave_activated= TRUE;
}
}
if (wsrep_node_dropped && wsrep_restart_slave)
{
if (wsrep_ready)
{
WSREP_INFO("Slave error due to node temporarily non-primary"
"SQL slave will continue");
wsrep_node_dropped= FALSE;
mysql_mutex_unlock(&rli->run_lock);
WSREP_DEBUG("wsrep_conflict_state now: %d", thd->wsrep_conflict_state);
WSREP_INFO("slave restart: %d", thd->wsrep_conflict_state);
thd->wsrep_conflict_state = NO_CONFLICT;
goto wsrep_restart_point;
} else {
WSREP_INFO("Slave error due to node going non-primary");
WSREP_INFO("wsrep_restart_slave was set and therefore slave will be "
"automatically restarted when node joins back to cluster");
wsrep_restart_slave_activated= TRUE;
}
}
#endif /* WITH_WSREP */
/*
Note: the order of the broadcast and unlock calls below (first broadcast, then unlock)
Expand Down

0 comments on commit a35c12f

Please sign in to comment.