Added MariaDB 10 transaction detection

Added MariaDB 10 transaction detection
This commit is contained in:
MassimilianoPinto
2015-08-26 17:32:45 +02:00
parent a698470ae0
commit f60254f626
3 changed files with 94 additions and 5 deletions

View File

@ -33,6 +33,10 @@
* Cache directory is now 'cache' under router->binlogdir
* 05/08/2015 Massimiliano Pinto Initial implementation of transaction safety
* 24/08/2015 Massimiliano Pinto Added strerror_r
* 26/08/2015 Massimiliano Pinto Added MariaDB 10 GTID event check with flags = 0
* This is the current supported condition for detecting
* MariaDB 10 transaction start point.
* It's no longer using QUERY_EVENT with BEGIN
*
* @endverbatim
*/
@ -1297,8 +1301,52 @@ int event_error = 0;
pos, file, new_pos)));
}
/* If MariaDB 10 compatibility:
* check for MARIADB10_GTID_EVENT with flags = 0
* This marks the transaction starts instead of
* QUERY_EVENT with "BEGIN"
*/
if (router->mariadb10_compat) {
if (hdr.event_type == MARIADB10_GTID_EVENT) {
uint64_t n_sequence; /* 8 bytes */
uint32_t domainid; /* 4 bytes */
unsigned int flags; /* 1 byte */
n_sequence = extract_field(ptr, 64);
domainid = extract_field(ptr + 8, 32);
flags = *(ptr + 8 + 4);
if (flags == 0) {
if (pending_transaction > 0) {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"ERROR: Transaction cannot be @ pos %llu: "
"Another MariaDB 10 transaction (GTID %lu-%lu-%llu)"
" was opened at %llu",
pos, domainid, hdr.serverid, n_sequence, last_known_commit)));
gwbuf_free(result);
break;
} else {
pending_transaction = 1;
if (debug)
LOGIF(LD, (skygw_log_write_flush(LOGFILE_DEBUG,
"> MariaDB 10 Transaction (GTID %lu-%lu-%llu)"
" starts @ pos %llu",
domainid, hdr.serverid, n_sequence, pos)));
}
}
}
}
/**
* Check QUERY_EVENT
*
* Check for BEGIN ( ONLY for mysql 5.6, mariadb 5.5 )
* Check for COMMIT (not transactional engines)
*/
/* Check QUERY_EVENT */
if(hdr.event_type == QUERY_EVENT) {
char *statement_sql;
db_name_len = ptr[4 + 4];

View File

@ -42,6 +42,10 @@
* 03/08/2015 Massimiliano Pinto Initial implementation of transaction safety
* 13/08/2015 Massimiliano Pinto Addition of heartbeat check
* 23/08/2015 Massimiliano Pinto Added strerror_r
* 26/08/2015 Massimiliano Pinto Added MariaDB 10 GTID event check with flags = 0
* This is the current supported condition for detecting
* MariaDB 10 transaction start point.
* It's no longer using QUERY_EVENT with BEGIN
*
* @endverbatim
*/
@ -1060,7 +1064,44 @@ int n_bufs = -1, pn_bufs = -1;
* Only complete transactions should be sent to sleves
*/
/* If MariaDB 10 compatibility:
* check for MARIADB10_GTID_EVENT with flags = 0
* This marks the transaction starts instead of
* QUERY_EVENT with "BEGIN"
*/
if (router->trx_safe) {
if (router->mariadb10_compat) {
if (hdr.event_type == MARIADB10_GTID_EVENT) {
uint64_t n_sequence;
uint32_t domainid;
unsigned int flags;
n_sequence = extract_field(ptr+4+20, 64);
domainid = extract_field(ptr+4+20 + 8, 32);
flags = *(ptr+4+20 + 8 + 4);
if (flags == 0) {
if (router->pending_transaction > 0) {
LOGIF(LE,(skygw_log_write_flush(LOGFILE_ERROR,
"Error: a MariaDB 10 transaction "
"is already open "
"@ %lu (GTID %lu-%lu-%llu) and "
"a new one starts @ %lu",
router->binlog_position,
domainid, hdr.serverid, n_sequence,
router->current_pos)));
// An action should be taken here
}
spinlock_acquire(&router->lock);
router->pending_transaction = 1;
spinlock_release(&router->lock);
}
}
}
/**
* look for QUERY_EVENT [BEGIN / COMMIT] and XID_EVENT
*/
@ -1253,7 +1294,7 @@ int n_bufs = -1, pn_bufs = -1;
*/
if (router->pending_transaction > 1) {
unsigned long pos;
unsigned long long pos;
GWBUF *record;
uint8_t *raw_data;
REP_HEADER new_hdr;

View File

@ -20,9 +20,6 @@
* This utility checks a MySQL 5.6 and MariaDB 10.0.X binlog file and reports
* any found error or an incomplete transaction.
* It suggests the pos the file should be trucatetd at.
* MariaDB 10 compatibility must be activated with --mariadb | -M option
*
* Note: transactions are not currently checked for MariaDB 10
*
* @verbatim
* Revision History
@ -31,6 +28,9 @@
* 24/07/2015 Massimiliano Pinto Initial implementation
* 26/08/2015 Massimiliano Pinto Added mariadb10 option
* for MariaDB 10 binlog compatibility
* Currently MariadDB 10 starting transactions
* are detected checking GTID event
* with flags = 0
*
* @endverbatim
*/