From 0deffbf2f2e18173fe99282b8da9dec4b7565b1d Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Thu, 28 Jan 2016 11:00:07 +0200 Subject: [PATCH] Ensure that slave->cstate contains meaningful value. In blr_slave_callback the bits of slave->cstate are reset and set as one transaction. Earlier they were reset in one and set in another, leading to a situation where slave->cstate did not contain a sensible value for a short period of time. Further, it is now explicitly checked in blr_distribute_binlog_record that slave->cstate indeed contains a meaningful value. --- server/modules/routing/binlog/blr_master.c | 5 +++++ server/modules/routing/binlog/blr_slave.c | 16 +++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index 574482507..423c43c4b 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -1602,6 +1602,11 @@ unsigned int cstate; /* Slave is in catchup mode */ action = 3; } + else + { + MXS_ERROR("slave->cstate does not contain a meaningful state %d", slave->cstate); + action = 0; + } slave->stats.n_actions[action-1]++; spinlock_release(&slave->catch_lock); diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 544239ac3..b5ecdc436 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -1965,6 +1965,7 @@ char read_errmsg[BINLOG_ERROR_MSG_LEN+1]; if (do_return) { spinlock_acquire(&slave->catch_lock); + slave->cstate &= ~CS_BUSY; slave->cstate |= CS_EXPECTCB; spinlock_release(&slave->catch_lock); poll_fake_write_event(slave->dcb); @@ -1972,15 +1973,6 @@ char read_errmsg[BINLOG_ERROR_MSG_LEN+1]; return 0; } - spinlock_acquire(&slave->catch_lock); - if (slave->cstate & CS_BUSY) - { - spinlock_release(&slave->catch_lock); - return 0; - } - slave->cstate |= CS_BUSY; - spinlock_release(&slave->catch_lock); - BLFILE *file; #ifdef BLFILE_IN_SLAVE file = slave->file; @@ -2369,8 +2361,14 @@ unsigned int cstate; if (slave->state == BLRS_DUMPING) { spinlock_acquire(&slave->catch_lock); + if (slave->cstate & CS_BUSY) + { + spinlock_release(&slave->catch_lock); + return 0; + } cstate = slave->cstate; slave->cstate &= ~(CS_UPTODATE|CS_EXPECTCB); + slave->cstate |= CS_BUSY; spinlock_release(&slave->catch_lock); if ((cstate & CS_UPTODATE) == CS_UPTODATE)