MXS-1209: blr_slave_query cleanup

New routine: blr_handle_set_stmt is in use
This commit is contained in:
MassimilianoPinto
2017-04-19 18:04:41 +02:00
parent c3cfc86a7b
commit e4941044aa

View File

@ -615,169 +615,13 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue)
}
else if (strcasecmp(query_text, "SET") == 0)
{
if ((word = strtok_r(NULL, sep, &brkb)) == NULL)
/* Handle SET */
if (blr_handle_set_stmt(router,
slave,
brkb))
{
MXS_ERROR("%s: Incomplete set command.", router->service->name);
}
else if ((strcasecmp(word, "autocommit") == 0) || (strcasecmp(word, "@@session.autocommit") == 0))
{
/* return OK */
MXS_FREE(query_text);
return blr_slave_send_ok(router, slave);
}
else if (strcasecmp(word, "@master_heartbeat_period") == 0)
{
int v_len = 0;
word = strtok_r(NULL, sep, &brkb);
if (word)
{
char *new_val;
v_len = strlen(word);
if (v_len > 6)
{
new_val = strndup(word, v_len - 6);
slave->heartbeat = atoi(new_val) / 1000;
}
else
{
new_val = strndup(word, v_len);
slave->heartbeat = atoi(new_val) / 1000000;
}
MXS_FREE(new_val);
}
MXS_FREE(query_text);
return blr_slave_replay(router, slave, router->saved_master.heartbeat);
}
else if (strcasecmp(word, "@mariadb_slave_capability") == 0)
{
/* mariadb10 compatibility is set for the slave */
slave->mariadb10_compat = true;
MXS_FREE(query_text);
if (router->mariadb10_compat)
{
return blr_slave_replay(router, slave, router->saved_master.mariadb10);
}
else
{
return blr_slave_send_ok(router, slave);
}
}
else if (strcasecmp(word, "@master_binlog_checksum") == 0)
{
word = strtok_r(NULL, sep, &brkb);
if (word && (strcasecmp(word, "'none'") == 0))
{
slave->nocrc = 1;
}
else if (word && (strcasecmp(word, "@@global.binlog_checksum") == 0))
{
slave->nocrc = !router->master_chksum;
}
else
{
slave->nocrc = 0;
}
MXS_FREE(query_text);
return blr_slave_replay(router, slave, router->saved_master.chksum1);
}
else if (strcasecmp(word, "@slave_uuid") == 0)
{
if ((word = strtok_r(NULL, sep, &brkb)) != NULL)
{
int len = strlen(word);
char *word_ptr = word;
if (len)
{
if (word[len - 1] == '\'')
{
word[len - 1] = '\0';
}
if (word[0] == '\'')
{
word[0] = '\0';
word_ptr++;
}
}
slave->uuid = MXS_STRDUP_A(word_ptr);
}
MXS_FREE(query_text);
return blr_slave_replay(router, slave, router->saved_master.setslaveuuid);
}
else if (strstr(word, "@slave_connect_state") != NULL)
{
/* If not mariadb an error message will be returned */
if (slave->mariadb10_compat &&
router->mariadb_gtid &&
(word = strtok_r(NULL, sep, &brkb)) != NULL)
{
char heading[GTID_MAX_LEN + 1];
MXS_DEBUG("Received GTID request '%s' from slave %u",
word,
slave->serverid);
// TOTO: gtid_strip_chars routine for this
strcpy(heading, word + 1);
heading[strlen(heading) - 1] = '\0';
/**
* Set the GTID string, it could be an empty
* in case of a fresh new setup.
*/
MXS_FREE(slave->mariadb_gtid);
slave->mariadb_gtid = MXS_STRDUP(heading);
MXS_FREE(query_text);
return blr_slave_send_ok(router, slave);
}
}
else if (strcasecmp(word, "@slave_gtid_strict_mode") == 0)
{
/* If not mariadb an error message will be returned */
if (slave->mariadb10_compat &&
router->mariadb_gtid &&
(word = strtok_r(NULL, sep, &brkb)) != NULL)
{
/* Set strict mode */
slave->gtid_strict_mode = atoi(word);
MXS_FREE(query_text);
return blr_slave_send_ok(router, slave);
}
}
else if (strcasecmp(word, "@slave_gtid_ignore_duplicates") == 0)
{
/* If not mariadb an error message will be returned */
if (slave->mariadb10_compat &&
router->mariadb_gtid)
{
MXS_FREE(query_text);
return blr_slave_send_ok(router, slave);
}
}
else if (strcasecmp(word, "NAMES") == 0)
{
if ((word = strtok_r(NULL, sep, &brkb)) == NULL)
{
MXS_ERROR("%s: Truncated SET NAMES command.", router->service->name);
}
else if (strcasecmp(word, "latin1") == 0)
{
MXS_FREE(query_text);
return blr_slave_replay(router, slave, router->saved_master.setnames);
}
else if (strcasecmp(word, "utf8") == 0)
{
MXS_FREE(query_text);
return blr_slave_replay(router, slave, router->saved_master.utf8);
}
else
{
MXS_FREE(query_text);
return blr_slave_send_ok(router, slave);
}
return 1;
}
} /* RESET current configured master */
else if (strcasecmp(query_text, "RESET") == 0)