MXS-1075: MariaDB 10 GTID stored and shown only for transaction safety on

MariaDB 10 GTID is detected and stored only if transaction_safety
option is on.

SELECT @@gtid_current_pos and “maxadmin show service $service_name” can
return it
This commit is contained in:
MassimilianoPinto
2017-02-28 15:19:57 +01:00
parent 054ddcb3dd
commit 304b5ced29
2 changed files with 67 additions and 53 deletions

View File

@ -1357,10 +1357,17 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
spinlock_release(&router->binlog_lock); spinlock_release(&router->binlog_lock);
/** /**
* Detect transactions in events * Detect transactions in events if trx_safe is set:
* Only complete transactions should be sent to sleves * Only complete transactions should be sent to sleves
*
* Now looking for:
* - QUERY_EVENT: BEGIN | START TRANSACTION | COMMIT
* - MariadDB 10 GTID_EVENT
* - XID_EVENT for transactional storage engines
*/ */
if (router->trx_safe)
{
if (router->mariadb10_compat && if (router->mariadb10_compat &&
hdr.event_type == MARIADB10_GTID_EVENT) hdr.event_type == MARIADB10_GTID_EVENT)
{ {
@ -1368,7 +1375,6 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
* If MariaDB 10 compatibility: * If MariaDB 10 compatibility:
* check for MARIADB10_GTID_EVENT with flags: * check for MARIADB10_GTID_EVENT with flags:
* this is the TRASACTION START detection. * this is the TRASACTION START detection.
*
*/ */
uint64_t n_sequence; uint64_t n_sequence;
@ -1392,14 +1398,9 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
spinlock_acquire(&router->binlog_lock); spinlock_acquire(&router->binlog_lock);
/* Save GTID */
strcpy(router->mariadb_gtid, mariadb_gtid);
/** /**
* Now mark the new open transaction * Now mark the new open transaction
*/ */
if (router->trx_safe)
{
if (router->pending_transaction.state > BLRM_NO_TRANSACTION) if (router->pending_transaction.state > BLRM_NO_TRANSACTION)
{ {
MXS_ERROR("A MariaDB 10 transaction " MXS_ERROR("A MariaDB 10 transaction "
@ -1413,20 +1414,15 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
router->pending_transaction.state = BLRM_TRANSACTION_START; router->pending_transaction.state = BLRM_TRANSACTION_START;
/* Save the pending GTID details */
strcpy(router->pending_transaction.gtid, mariadb_gtid);
router->pending_transaction.start_pos = router->current_pos;
router->pending_transaction.end_pos = 0;
} }
spinlock_release(&router->binlog_lock); spinlock_release(&router->binlog_lock);
} }
}
/**
* If trx_safe is set then look for:
* - QUERY_EVENT: BEGIN | START TRANSACTION | COMMIT
* - XID_EVENT for transactional storage edngines
*/
if (router->trx_safe)
{
if (hdr.event_type == QUERY_EVENT) if (hdr.event_type == QUERY_EVENT)
{ {
char *statement_sql; char *statement_sql;
@ -1458,6 +1454,8 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
} }
router->pending_transaction.state = BLRM_TRANSACTION_START; router->pending_transaction.state = BLRM_TRANSACTION_START;
router->pending_transaction.start_pos = router->current_pos;
router->pending_transaction.end_pos = 0;
} }
/* Check for COMMIT in non transactional store engines */ /* Check for COMMIT in non transactional store engines */
@ -1465,7 +1463,6 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
{ {
router->pending_transaction.state = BLRM_COMMIT_SEEN; router->pending_transaction.state = BLRM_COMMIT_SEEN;
} }
spinlock_release(&router->binlog_lock); spinlock_release(&router->binlog_lock);
MXS_FREE(statement_sql); MXS_FREE(statement_sql);
@ -1625,18 +1622,31 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt)
* *
* 1) Notify clients events can be read * 1) Notify clients events can be read
* from router->binlog_position * from router->binlog_position
* 2) set router->binlog_position to * 2) Update last seen MariaDB 10 GTID
* 3) set router->binlog_position to
* router->current_pos * router->current_pos
*/ */
if (router->pending_transaction.state > BLRM_TRANSACTION_START) if (router->pending_transaction.state > BLRM_TRANSACTION_START)
{ {
/* Update last seen MariaDB GTID */
if (router->mariadb10_compat)
{
strcpy(router->mariadb_gtid, router->pending_transaction.gtid);
/* The transaction has been saved.
* this poins to end of binlog:
* i.e. the position of a new event
*/
router->pending_transaction.end_pos = router->current_pos;
}
spinlock_release(&router->binlog_lock); spinlock_release(&router->binlog_lock);
/* Notify clients events can be read */ /* Notify clients events can be read */
blr_notify_all_slaves(router); blr_notify_all_slaves(router);
/* update binlog_position and set pending to 0 */ /* update binlog_position and set pending to NO_TRX */
spinlock_acquire(&router->binlog_lock); spinlock_acquire(&router->binlog_lock);
router->binlog_position = router->current_pos; router->binlog_position = router->current_pos;

View File

@ -646,15 +646,19 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue)
} }
else if ((strcasecmp(word, "@@gtid_current_pos") == 0) || (strcasecmp(word, "@@global.gtid_current_pos") == 0)) else if ((strcasecmp(word, "@@gtid_current_pos") == 0) || (strcasecmp(word, "@@global.gtid_current_pos") == 0))
{ {
char heading[40]; /* to ensure we match the case in query and response */ char heading[40];
char mariadb_gtid[GTID_MAX_LEN + 1]; char mariadb_gtid[GTID_MAX_LEN + 1];
mariadb_gtid[0] = '\0';
strcpy(heading, word); strcpy(heading, word);
MXS_FREE(query_text); MXS_FREE(query_text);
/* Safely get router->mariadb_gtid */ if (router->mariadb10_compat)
{
spinlock_acquire(&router->binlog_lock); spinlock_acquire(&router->binlog_lock);
strcpy(mariadb_gtid, router->mariadb_gtid); strcpy(mariadb_gtid, router->mariadb_gtid);
spinlock_release(&router->binlog_lock); spinlock_release(&router->binlog_lock);
}
return blr_slave_send_var_value(router, slave, heading, mariadb_gtid, BLR_TYPE_STRING); return blr_slave_send_var_value(router, slave, heading, mariadb_gtid, BLR_TYPE_STRING);
} }