Add ability to extract values from the result set
Extract and action the @master_binlog_checksum value Store master's uuid for use in show slave status Support for MariaDB 5.5 masters
This commit is contained in:
@ -250,6 +250,8 @@ typedef struct router_instance {
|
|||||||
char *user; /*< User name to use with master */
|
char *user; /*< User name to use with master */
|
||||||
char *password; /*< Password to use with master */
|
char *password; /*< Password to use with master */
|
||||||
char *fileroot; /*< Root of binlog filename */
|
char *fileroot; /*< Root of binlog filename */
|
||||||
|
bool master_chksum;/*< Does the master provide checksums */
|
||||||
|
char *master_uuid; /*< UUID of the master */
|
||||||
DCB *master; /*< DCB for master connection */
|
DCB *master; /*< DCB for master connection */
|
||||||
DCB *client; /*< DCB for dummy client */
|
DCB *client; /*< DCB for dummy client */
|
||||||
SESSION *session; /*< Fake session for master connection */
|
SESSION *session; /*< Fake session for master connection */
|
||||||
|
|||||||
@ -181,6 +181,8 @@ unsigned char *defuuid;
|
|||||||
spinlock_init(&inst->binlog_lock);
|
spinlock_init(&inst->binlog_lock);
|
||||||
|
|
||||||
inst->binlog_fd = -1;
|
inst->binlog_fd = -1;
|
||||||
|
inst->master_chksum = true;
|
||||||
|
inst->master_uuid = NULL;
|
||||||
|
|
||||||
inst->low_water = DEF_LOW_WATER;
|
inst->low_water = DEF_LOW_WATER;
|
||||||
inst->high_water = DEF_HIGH_WATER;
|
inst->high_water = DEF_HIGH_WATER;
|
||||||
|
|||||||
@ -79,6 +79,8 @@ void blr_extract_header(uint8_t *pkt, REP_HEADER *hdr);
|
|||||||
inline uint32_t extract_field(uint8_t *src, int bits);
|
inline uint32_t extract_field(uint8_t *src, int bits);
|
||||||
static void blr_log_packet(logfile_id_t file, char *msg, uint8_t *ptr, int len);
|
static void blr_log_packet(logfile_id_t file, char *msg, uint8_t *ptr, int len);
|
||||||
static void blr_master_close(ROUTER_INSTANCE *);
|
static void blr_master_close(ROUTER_INSTANCE *);
|
||||||
|
static char *blr_extract_column(GWBUF *buf, int col);
|
||||||
|
|
||||||
static int keepalive = 1;
|
static int keepalive = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -384,6 +386,9 @@ char query[128];
|
|||||||
router->retry_backoff = 1;
|
router->retry_backoff = 1;
|
||||||
break;
|
break;
|
||||||
case BLRM_SERVERID:
|
case BLRM_SERVERID:
|
||||||
|
{
|
||||||
|
char *val = blr_extract_column(buf, 1);
|
||||||
|
|
||||||
// Response to fetch of master's server-id
|
// Response to fetch of master's server-id
|
||||||
if (router->saved_master.server_id)
|
if (router->saved_master.server_id)
|
||||||
GWBUF_CONSUME_ALL(router->saved_master.server_id);
|
GWBUF_CONSUME_ALL(router->saved_master.server_id);
|
||||||
@ -398,6 +403,7 @@ char query[128];
|
|||||||
router->master_state = BLRM_HBPERIOD;
|
router->master_state = BLRM_HBPERIOD;
|
||||||
router->master->func.write(router->master, buf);
|
router->master->func.write(router->master, buf);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case BLRM_HBPERIOD:
|
case BLRM_HBPERIOD:
|
||||||
// Response to set the heartbeat period
|
// Response to set the heartbeat period
|
||||||
if (router->saved_master.heartbeat)
|
if (router->saved_master.heartbeat)
|
||||||
@ -419,6 +425,15 @@ char query[128];
|
|||||||
router->master->func.write(router->master, buf);
|
router->master->func.write(router->master, buf);
|
||||||
break;
|
break;
|
||||||
case BLRM_CHKSUM2:
|
case BLRM_CHKSUM2:
|
||||||
|
{
|
||||||
|
char *val = blr_extract_column(buf, 1);
|
||||||
|
|
||||||
|
if (val && strncasecmp(val, "NONE", 4) == 0)
|
||||||
|
{
|
||||||
|
router->master_chksum = false;
|
||||||
|
}
|
||||||
|
if (val)
|
||||||
|
free(val);
|
||||||
// Response to the master_binlog_checksum, should be stored
|
// Response to the master_binlog_checksum, should be stored
|
||||||
if (router->saved_master.chksum2)
|
if (router->saved_master.chksum2)
|
||||||
GWBUF_CONSUME_ALL(router->saved_master.chksum2);
|
GWBUF_CONSUME_ALL(router->saved_master.chksum2);
|
||||||
@ -428,6 +443,7 @@ char query[128];
|
|||||||
router->master_state = BLRM_GTIDMODE;
|
router->master_state = BLRM_GTIDMODE;
|
||||||
router->master->func.write(router->master, buf);
|
router->master->func.write(router->master, buf);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case BLRM_GTIDMODE:
|
case BLRM_GTIDMODE:
|
||||||
// Response to the GTID_MODE, should be stored
|
// Response to the GTID_MODE, should be stored
|
||||||
if (router->saved_master.gtid_mode)
|
if (router->saved_master.gtid_mode)
|
||||||
@ -439,6 +455,10 @@ char query[128];
|
|||||||
router->master->func.write(router->master, buf);
|
router->master->func.write(router->master, buf);
|
||||||
break;
|
break;
|
||||||
case BLRM_MUUID:
|
case BLRM_MUUID:
|
||||||
|
{
|
||||||
|
char *val = blr_extract_column(buf, 1);
|
||||||
|
router->master_uuid = val;
|
||||||
|
|
||||||
// Response to the SERVER_UUID, should be stored
|
// Response to the SERVER_UUID, should be stored
|
||||||
if (router->saved_master.uuid)
|
if (router->saved_master.uuid)
|
||||||
GWBUF_CONSUME_ALL(router->saved_master.uuid);
|
GWBUF_CONSUME_ALL(router->saved_master.uuid);
|
||||||
@ -449,6 +469,7 @@ char query[128];
|
|||||||
router->master_state = BLRM_SUUID;
|
router->master_state = BLRM_SUUID;
|
||||||
router->master->func.write(router->master, buf);
|
router->master->func.write(router->master, buf);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case BLRM_SUUID:
|
case BLRM_SUUID:
|
||||||
// Response to the SET @server_uuid, should be stored
|
// Response to the SET @server_uuid, should be stored
|
||||||
if (router->saved_master.setslaveuuid)
|
if (router->saved_master.setslaveuuid)
|
||||||
@ -874,6 +895,8 @@ static REP_HEADER phdr;
|
|||||||
* First check that the checksum we calculate matches the
|
* First check that the checksum we calculate matches the
|
||||||
* checksum in the packet we received.
|
* checksum in the packet we received.
|
||||||
*/
|
*/
|
||||||
|
if (router->master_chksum)
|
||||||
|
{
|
||||||
uint32_t chksum, pktsum;
|
uint32_t chksum, pktsum;
|
||||||
|
|
||||||
chksum = crc32(0L, NULL, 0);
|
chksum = crc32(0L, NULL, 0);
|
||||||
@ -899,6 +922,7 @@ static REP_HEADER phdr;
|
|||||||
blr_master_delayed_connect(router);
|
blr_master_delayed_connect(router);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
router->stats.n_binlogs++;
|
router->stats.n_binlogs++;
|
||||||
router->lastEventReceived = hdr.event_type;
|
router->lastEventReceived = hdr.event_type;
|
||||||
|
|
||||||
@ -1398,3 +1422,59 @@ blr_master_connected(ROUTER_INSTANCE *router)
|
|||||||
{
|
{
|
||||||
return router->master_state == BLRM_BINLOGDUMP;
|
return router->master_state == BLRM_BINLOGDUMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a result value from the set of messages that make up a
|
||||||
|
* MySQL response packet.
|
||||||
|
*
|
||||||
|
* @param buf The GWBUF containing the response
|
||||||
|
* @param col The column number to return
|
||||||
|
* @return The result form the column or NULL. The caller must free the result
|
||||||
|
*/
|
||||||
|
static char *
|
||||||
|
blr_extract_column(GWBUF *buf, int col)
|
||||||
|
{
|
||||||
|
uint8_t *ptr;
|
||||||
|
int len, ncol, collen;
|
||||||
|
char *rval;
|
||||||
|
|
||||||
|
ptr = (uint8_t *)GWBUF_DATA(buf);
|
||||||
|
/* First packet should be the column count */
|
||||||
|
len = EXTRACT24(ptr);
|
||||||
|
ptr += 3;
|
||||||
|
if (*ptr != 1) // Check sequence number is 1
|
||||||
|
return NULL;
|
||||||
|
ptr++;
|
||||||
|
ncol = *ptr++;
|
||||||
|
if (ncol < col) // Not that many column in result
|
||||||
|
return NULL;
|
||||||
|
// Now ptr points at the column definition
|
||||||
|
while (ncol-- > 0)
|
||||||
|
{
|
||||||
|
len = EXTRACT24(ptr);
|
||||||
|
ptr += 4; // Skip to payload
|
||||||
|
ptr += len; // Skip over payload
|
||||||
|
}
|
||||||
|
// Now we should have an EOF packet
|
||||||
|
len = EXTRACT24(ptr);
|
||||||
|
ptr += 4; // Skip to payload
|
||||||
|
if (*ptr != 0xfe)
|
||||||
|
return NULL;
|
||||||
|
ptr += len;
|
||||||
|
|
||||||
|
// Finally we have reached the row
|
||||||
|
len = EXTRACT24(ptr);
|
||||||
|
ptr += 4;
|
||||||
|
while (--col > 0)
|
||||||
|
{
|
||||||
|
collen = *ptr++;
|
||||||
|
ptr += collen;
|
||||||
|
}
|
||||||
|
collen = *ptr++;
|
||||||
|
if ((rval = malloc(collen + 1)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
memcpy(rval, ptr, collen);
|
||||||
|
rval[collen] = 0; // NULL terminate
|
||||||
|
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|||||||
@ -859,7 +859,8 @@ int len, actual_len, col_len, seqno, ncols, i;
|
|||||||
|
|
||||||
*ptr++ = 0;
|
*ptr++ = 0;
|
||||||
|
|
||||||
sprintf(column, "%s", router->uuid);
|
sprintf(column, "%s", router->master_uuid ?
|
||||||
|
router->master_uuid : router->uuid);
|
||||||
col_len = strlen(column);
|
col_len = strlen(column);
|
||||||
*ptr++ = col_len; // Length of result string
|
*ptr++ = col_len; // Length of result string
|
||||||
strncpy((char *)ptr, column, col_len); // Result string
|
strncpy((char *)ptr, column, col_len); // Result string
|
||||||
|
|||||||
Reference in New Issue
Block a user