MXS-1075: MariaDB 10 Slave registration with GTID
New SQL commands are handled for MariaDB 10 slave registration with GTID
This commit is contained in:
@ -1041,6 +1041,7 @@ newSession(MXS_ROUTER *instance, MXS_SESSION *session)
|
||||
slave->heartbeat = 0;
|
||||
slave->lastEventReceived = 0;
|
||||
slave->encryption_ctx = NULL;
|
||||
slave->mariadb_gtid = NULL;
|
||||
|
||||
/**
|
||||
* Add this session to the list of active sessions.
|
||||
@ -1124,6 +1125,10 @@ static void freeSession(MXS_ROUTER* router_instance,
|
||||
{
|
||||
MXS_FREE(slave->encryption_ctx);
|
||||
}
|
||||
if (slave->mariadb_gtid)
|
||||
{
|
||||
MXS_FREE(slave->mariadb_gtid);
|
||||
}
|
||||
MXS_FREE(slave);
|
||||
}
|
||||
|
||||
|
@ -449,6 +449,8 @@ typedef struct router_slave
|
||||
char lsi_binlog_name[BINLOG_FNAMELEN + 1]; /*< Which binlog file */
|
||||
uint32_t lsi_binlog_pos; /*< What position */
|
||||
void *encryption_ctx; /*< Encryption context */
|
||||
bool gtid_strict_mode;/*< MariaDB 10 Slave sets gtid_strict_mode */
|
||||
char *mariadb_gtid; /*< MariaDB 10 Slave connects with GTID */
|
||||
#if defined(SS_DEBUG)
|
||||
skygw_chk_t rses_chk_tail;
|
||||
#endif
|
||||
|
@ -172,7 +172,7 @@ static void blr_format_event_size(double *event_size, char *label);
|
||||
extern int MaxScaleUptime();
|
||||
extern void encode_value(unsigned char *data, unsigned int value, int len);
|
||||
extern void blr_extract_header(register uint8_t *ptr, register REP_HEADER *hdr);
|
||||
int blr_save_mariadb_gtid(ROUTER_INSTANCE *inst);
|
||||
bool blr_save_mariadb_gtid(ROUTER_INSTANCE *inst);
|
||||
|
||||
typedef struct binlog_event_desc
|
||||
{
|
||||
@ -3303,9 +3303,9 @@ static void blr_report_checksum(REP_HEADER hdr, const uint8_t *buffer, char *out
|
||||
* Save MariaDB GTID found in complete transaction
|
||||
*
|
||||
* @param inst The router instance
|
||||
* @return 1 on success, 0 otherwise
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
int blr_save_mariadb_gtid(ROUTER_INSTANCE *inst)
|
||||
bool blr_save_mariadb_gtid(ROUTER_INSTANCE *inst)
|
||||
{
|
||||
MARIADB_GTID_INFO gtid_info;
|
||||
|
||||
@ -3321,7 +3321,7 @@ int blr_save_mariadb_gtid(ROUTER_INSTANCE *inst)
|
||||
MXS_ERROR("Service %s: error saving mariadb GTID %s into repo",
|
||||
inst->service->name,
|
||||
inst->pending_transaction.gtid);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
MXS_DEBUG("Saved MariaDB GTID '%s', %s:%lu:%lu",
|
||||
@ -3330,5 +3330,5 @@ int blr_save_mariadb_gtid(ROUTER_INSTANCE *inst)
|
||||
gtid_info.start,
|
||||
gtid_info.end);
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ static int blr_get_master_semisync(GWBUF *buf);
|
||||
static void blr_terminate_master_replication(ROUTER_INSTANCE *router, uint8_t* ptr, int len);
|
||||
void blr_notify_all_slaves(ROUTER_INSTANCE *router);
|
||||
extern bool blr_notify_waiting_slave(ROUTER_SLAVE *slave);
|
||||
extern int blr_save_mariadb_gtid(ROUTER_INSTANCE *inst);
|
||||
extern bool blr_save_mariadb_gtid(ROUTER_INSTANCE *inst);
|
||||
|
||||
static int keepalive = 1;
|
||||
|
||||
|
@ -333,7 +333,7 @@ blr_skip_leading_sql_comments(const char *sql_query)
|
||||
* order to support some commands that are useful for monitoring the binlog
|
||||
* router.
|
||||
*
|
||||
* Thirteen select statements are currently supported:
|
||||
* 15 select statements are currently supported:
|
||||
* SELECT UNIX_TIMESTAMP();
|
||||
* SELECT @master_binlog_checksum
|
||||
* SELECT @@GLOBAL.GTID_MODE
|
||||
@ -347,8 +347,10 @@ blr_skip_leading_sql_comments(const char *sql_query)
|
||||
* SELECT @@version
|
||||
* SELECT @@[GLOBAL.]server_uuid
|
||||
* SELECT USER()
|
||||
* SELECT @@GLOBAL.gtid_domain_id
|
||||
* SELECT @@[GLOBAL].gtid_current_pos
|
||||
*
|
||||
* Eight show commands are supported:
|
||||
* 8 show commands are supported:
|
||||
* SHOW [GLOBAL] VARIABLES LIKE 'SERVER_ID'
|
||||
* SHOW [GLOBAL] VARIABLES LIKE 'SERVER_UUID'
|
||||
* SHOW [GLOBAL] VARIABLES LIKE 'MAXSCALE%'
|
||||
@ -358,7 +360,7 @@ blr_skip_leading_sql_comments(const char *sql_query)
|
||||
* SHOW WARNINGS
|
||||
* SHOW [GLOBAL] STATUS LIKE 'Uptime'
|
||||
*
|
||||
* Nine set commands are supported:
|
||||
* 12 set commands are supported:
|
||||
* SET @master_binlog_checksum = @@global.binlog_checksum
|
||||
* SET @master_heartbeat_period=...
|
||||
* SET @slave_slave_uuid=...
|
||||
@ -368,8 +370,11 @@ blr_skip_leading_sql_comments(const char *sql_query)
|
||||
* SET mariadb_slave_capability=...
|
||||
* SET autocommit=
|
||||
* SET @@session.autocommit=
|
||||
* SET @slave_connect_state=
|
||||
* SET @slave_gtid_strict_mode=
|
||||
* SET @slave_gtid_ignore_duplicates=
|
||||
*
|
||||
* Four administrative commands are supported:
|
||||
* 4 administrative commands are supported:
|
||||
* STOP SLAVE
|
||||
* START SLAVE
|
||||
* CHANGE MASTER TO
|
||||
@ -663,6 +668,21 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue)
|
||||
|
||||
return blr_slave_send_var_value(router, slave, heading, mariadb_gtid, BLR_TYPE_STRING);
|
||||
}
|
||||
else if (strcasecmp(word, "@@GLOBAL.gtid_domain_id") == 0)
|
||||
{
|
||||
/* If not mariadb an error message will be returned */
|
||||
if (slave->mariadb10_compat && router->mariadb_gtid)
|
||||
{
|
||||
char heading[40];
|
||||
strcpy(heading, word);
|
||||
MXS_FREE(query_text);
|
||||
return blr_slave_send_var_value(router,
|
||||
slave,
|
||||
heading,
|
||||
"0",
|
||||
BLR_TYPE_STRING);
|
||||
}
|
||||
}
|
||||
else if (strcasestr(word, "binlog_gtid_pos"))
|
||||
{
|
||||
unexpected = false;
|
||||
@ -935,6 +955,57 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue)
|
||||
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)
|
||||
|
Reference in New Issue
Block a user