Only add tasks once in binlogrouter

Adding the same task twice isn't allowed. The API of the housekeeper tasks
might have to be changed in a way that makes it possible for the caller to
know whether a task has been added.
This commit is contained in:
Markus Mäkelä
2019-03-26 09:13:44 +02:00
parent 0915487329
commit f8bc6b18fc
3 changed files with 16 additions and 10 deletions

View File

@ -353,6 +353,7 @@ static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params
inst->maxwell_compat = params->get_bool("maxwell-compatibility"); inst->maxwell_compat = params->get_bool("maxwell-compatibility");
inst->trx_safe = params->get_bool("transaction_safety"); inst->trx_safe = params->get_bool("transaction_safety");
inst->fileroot = params->get_c_str_copy("filestem"); inst->fileroot = params->get_c_str_copy("filestem");
inst->heartbeat_task_active = false;
/* Server id */ /* Server id */
inst->serverid = params->get_integer("server_id"); inst->serverid = params->get_integer("server_id");

View File

@ -799,6 +799,7 @@ struct ROUTER_INSTANCE : public MXS_ROUTER
unsigned int long_burst; /*< Long burst for slave catchup */ unsigned int long_burst; /*< Long burst for slave catchup */
unsigned long burst_size; /*< Maximum size of burst to send */ unsigned long burst_size; /*< Maximum size of burst to send */
unsigned long heartbeat; /*< Configured heartbeat value */ unsigned long heartbeat; /*< Configured heartbeat value */
bool heartbeat_task_active;
ROUTER_STATS stats; /*< Statistics for this router */ ROUTER_STATS stats; /*< Statistics for this router */
int active_logs; int active_logs;
int reconnect_pending; int reconnect_pending;

View File

@ -1460,15 +1460,18 @@ static bool blr_check_last_master_event(void* inst)
if ((!master_check) || (master_state != BLRM_BINLOGDUMP)) if ((!master_check) || (master_state != BLRM_BINLOGDUMP))
{ {
/* if (router->heartbeat_task_active)
* Remove the task, it will be added again {
* when master state is back to BLRM_BINLOGDUMP // Remove the task, it will be added again when master state is back to BLRM_BINLOGDUMP by
* by blr_master_response() // blr_master_response()
*/ snprintf(task_name,
snprintf(task_name, BLRM_TASK_NAME_LEN,
BLRM_TASK_NAME_LEN, "%s heartbeat",
"%s heartbeat", router->service->name());
router->service->name());
hktask_remove(task_name);
router->heartbeat_task_active = false;
}
rval = false; rval = false;
} }
@ -2842,8 +2845,9 @@ static void blr_start_master_registration(ROUTER_INSTANCE* router, GWBUF* buf)
/** /**
* Set heartbeat check task * Set heartbeat check task
*/ */
if (router->heartbeat > 0) if (router->heartbeat > 0 && !router->heartbeat_task_active)
{ {
router->heartbeat_task_active = true;
char task_name[BLRM_TASK_NAME_LEN + 1] = ""; char task_name[BLRM_TASK_NAME_LEN + 1] = "";
snprintf(task_name, snprintf(task_name,
BLRM_TASK_NAME_LEN, BLRM_TASK_NAME_LEN,