From 5c7b2a68e55d57f18bfd3c1fc824f636e7526f51 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Wed, 6 May 2015 12:19:18 +0200 Subject: [PATCH 01/14] mariadb10 compatibility test without GTID First implementation of mariadb10 compatibility test without GTID State machine to be modified for mysql5.6/mariadb10 compatibility router options for mariadb10 slave registration still missing --- server/modules/include/blr.h | 2 +- server/modules/routing/binlog/blr_master.c | 3 ++- server/modules/routing/binlog/blr_slave.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/modules/include/blr.h b/server/modules/include/blr.h index 62cda59a3..5c9c70181 100644 --- a/server/modules/include/blr.h +++ b/server/modules/include/blr.h @@ -395,7 +395,7 @@ static char *blrs_states[] = { "Created", "Unregistered", "Registered", #define ANONYMOUS_GTID_EVENT 0x22 #define PREVIOUS_GTIDS_EVENT 0x23 -#define MAX_EVENT_TYPE 0x23 +#define MAX_EVENT_TYPE 0xa3 /** * Binlog event flags diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index 2b164c349..70cd78686 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -448,7 +448,8 @@ char query[128]; GWBUF_CONSUME_ALL(router->saved_master.chksum2); router->saved_master.chksum2 = buf; blr_cache_response(router, "chksum2", buf); - buf = blr_make_query("SELECT @@GLOBAL.GTID_MODE"); + //buf = blr_make_query("SELECT @@GLOBAL.GTID_MODE"); + buf = blr_make_query("SET @mariadb_slave_capability=4); router->master_state = BLRM_GTIDMODE; router->master->func.write(router->master, buf); break; diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 4de69b8d7..8a008e35f 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -369,7 +369,8 @@ int query_len; else if (strcasecmp(word, "@mariadb_slave_capability") == 0) { free(query_text); - return blr_slave_send_ok(router, slave); + return blr_slave_replay(router, slave, router->saved_master.gtid_mode); + //return blr_slave_send_ok(router, slave); } else if (strcasecmp(word, "@master_binlog_checksum") == 0) { From bc7cc2a4666a9ab8946b7134da072bf2703c002d Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 7 May 2015 12:56:58 +0300 Subject: [PATCH 02/14] Added variables for MariaDB 10 compatibility. --- server/modules/include/blr.h | 7 +++++-- server/modules/routing/binlog/blr.c | 5 +++++ server/modules/routing/binlog/blr_master.c | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/modules/include/blr.h b/server/modules/include/blr.h index 5c9c70181..48c48a194 100644 --- a/server/modules/include/blr.h +++ b/server/modules/include/blr.h @@ -233,6 +233,7 @@ typedef struct { GWBUF *selectvercom; /*< select @@version_comment */ GWBUF *selecthostname;/*< select @@hostname */ GWBUF *map; /*< select @@max_allowed_packet */ + GWBUF *mariadb10; /*< set @mariadb_slave_capability=4 */ uint8_t *fde_event; /*< Format Description Event */ int fde_len; /*< Length of fde_event */ } MASTER_RESPONSES; @@ -252,6 +253,7 @@ typedef struct router_instance { char *password; /*< Password to use with master */ char *fileroot; /*< Root of binlog filename */ bool master_chksum;/*< Does the master provide checksums */ + bool mariadb10_compat; /*< MariaDB 10.0 compatibility */ char *master_uuid; /*< UUID of the master */ DCB *master; /*< DCB for master connection */ DCB *client; /*< DCB for dummy client */ @@ -314,15 +316,16 @@ typedef struct router_instance { #define BLRM_MAP 0x0011 #define BLRM_REGISTER 0x0012 #define BLRM_BINLOGDUMP 0x0013 - +#define BLRM_MARIADB10 0x0014 #define BLRM_MAXSTATE 0x0013 +#define BLRM_MAXSTATE_MARIADB10 0x0014 static char *blrm_states[] = { "Unconnected", "Connecting", "Authenticated", "Timestamp retrieval", "Server ID retrieval", "HeartBeat Period setup", "binlog checksum config", "binlog checksum rerieval", "GTID Mode retrieval", "Master UUID retrieval", "Set Slave UUID", "Set Names latin1", "Set Names utf8", "select 1", "select version()", "select @@version_comment", "select @@hostname", - "select @@mx_allowed_packet", "Register slave", "Binlog Dump" }; + "select @@mx_allowed_packet", "Register slave", "Binlog Dump","Set MariaDB slave capability" }; #define BLRS_CREATED 0x0000 #define BLRS_UNREGISTERED 0x0001 diff --git a/server/modules/routing/binlog/blr.c b/server/modules/routing/binlog/blr.c index 2ba89689f..2f5a38bee 100644 --- a/server/modules/routing/binlog/blr.c +++ b/server/modules/routing/binlog/blr.c @@ -195,6 +195,7 @@ unsigned char *defuuid; inst->retry_backoff = 1; inst->binlogdir = NULL; inst->heartbeat = 300; // Default is every 5 minutes + inst->mariadb10_compat = false; inst->user = strdup(service->credentials.name); inst->password = strdup(service->credentials.authdata); @@ -282,6 +283,10 @@ unsigned char *defuuid; { inst->masterid = atoi(value); } + else if (strcmp(options[i], "mariadb10-compatibility") == 0) + { + inst->mariadb10_compat = config_truth_value(value); + } else if (strcmp(options[i], "filestem") == 0) { inst->fileroot = strdup(value); diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index 70cd78686..bc1e676d0 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -449,7 +449,7 @@ char query[128]; router->saved_master.chksum2 = buf; blr_cache_response(router, "chksum2", buf); //buf = blr_make_query("SELECT @@GLOBAL.GTID_MODE"); - buf = blr_make_query("SET @mariadb_slave_capability=4); + buf = blr_make_query("SET @mariadb_slave_capability=4"); router->master_state = BLRM_GTIDMODE; router->master->func.write(router->master, buf); break; From 8afa46b8b2436dd9bb3680b5642b1c0d3cec7f32 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 7 May 2015 13:00:34 +0300 Subject: [PATCH 03/14] Removed BLRM_MAXSTATE_MARIADB10 and set BLRM_MAXSTATE to 0x014 --- server/modules/include/blr.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/modules/include/blr.h b/server/modules/include/blr.h index 48c48a194..fa377c7e5 100644 --- a/server/modules/include/blr.h +++ b/server/modules/include/blr.h @@ -317,8 +317,7 @@ typedef struct router_instance { #define BLRM_REGISTER 0x0012 #define BLRM_BINLOGDUMP 0x0013 #define BLRM_MARIADB10 0x0014 -#define BLRM_MAXSTATE 0x0013 -#define BLRM_MAXSTATE_MARIADB10 0x0014 +#define BLRM_MAXSTATE 0x0014 static char *blrm_states[] = { "Unconnected", "Connecting", "Authenticated", "Timestamp retrieval", "Server ID retrieval", "HeartBeat Period setup", "binlog checksum config", From e9391ef48639c6607bfcd5472d8996cb74c41614 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Thu, 7 May 2015 15:16:37 +0200 Subject: [PATCH 04/14] MariaDB 10 optional compatibility MariaDB 10 optional compatibility with mariadb10-compatibility=1 --- server/modules/include/blr.h | 94 +++++++++++----------- server/modules/routing/binlog/blr_master.c | 21 ++++- server/modules/routing/binlog/blr_slave.c | 6 +- 3 files changed, 68 insertions(+), 53 deletions(-) diff --git a/server/modules/include/blr.h b/server/modules/include/blr.h index fa377c7e5..8aecd83f0 100644 --- a/server/modules/include/blr.h +++ b/server/modules/include/blr.h @@ -233,7 +233,7 @@ typedef struct { GWBUF *selectvercom; /*< select @@version_comment */ GWBUF *selecthostname;/*< select @@hostname */ GWBUF *map; /*< select @@max_allowed_packet */ - GWBUF *mariadb10; /*< set @mariadb_slave_capability=4 */ + GWBUF *mariadb10; /*< set @mariadb_slave_capability */ uint8_t *fde_event; /*< Format Description Event */ int fde_len; /*< Length of fde_event */ } MASTER_RESPONSES; @@ -242,55 +242,54 @@ typedef struct { * The per instance data for the router. */ typedef struct router_instance { - SERVICE *service; /*< Pointer to the service using this router */ - ROUTER_SLAVE *slaves; /*< Link list of all the slave connections */ - SPINLOCK lock; /*< Spinlock for the instance data */ - char *uuid; /*< UUID for the router to use w/master */ - int masterid; /*< Server ID of the master */ - int serverid; /*< Server ID to use with master */ - int initbinlog; /*< Initial binlog file number */ - char *user; /*< User name to use with master */ - char *password; /*< Password to use with master */ - char *fileroot; /*< Root of binlog filename */ - bool master_chksum;/*< Does the master provide checksums */ - bool mariadb10_compat; /*< MariaDB 10.0 compatibility */ - char *master_uuid; /*< UUID of the master */ - DCB *master; /*< DCB for master connection */ - DCB *client; /*< DCB for dummy client */ - SESSION *session; /*< Fake session for master connection */ - unsigned int master_state; /*< State of the master FSM */ - uint8_t lastEventReceived; - uint32_t lastEventTimestamp; /*< Timestamp from last event */ - GWBUF *residual; /*< Any residual binlog event */ - MASTER_RESPONSES saved_master; /*< Saved master responses */ - char *binlogdir; /*< The directory with the binlog files */ - SPINLOCK binlog_lock; /*< Lock to control update of the binlog position */ - char binlog_name[BINLOG_FNAMELEN+1]; + SERVICE *service; /*< Pointer to the service using this router */ + ROUTER_SLAVE *slaves; /*< Link list of all the slave connections */ + SPINLOCK lock; /*< Spinlock for the instance data */ + char *uuid; /*< UUID for the router to use w/master */ + int masterid; /*< Server ID of the master */ + int serverid; /*< Server ID to use with master */ + int initbinlog; /*< Initial binlog file number */ + char *user; /*< User name to use with master */ + char *password; /*< Password to use with master */ + char *fileroot; /*< Root of binlog filename */ + bool master_chksum; /*< Does the master provide checksums */ + bool mariadb10_compat; /*< MariaDB 10.0 compatibility */ + char *master_uuid; /*< UUID of the master */ + DCB *master; /*< DCB for master connection */ + DCB *client; /*< DCB for dummy client */ + SESSION *session; /*< Fake session for master connection */ + unsigned int master_state; /*< State of the master FSM */ + uint8_t lastEventReceived; + uint32_t lastEventTimestamp; /*< Timestamp from last event */ + GWBUF *residual; /*< Any residual binlog event */ + MASTER_RESPONSES saved_master; /*< Saved master responses */ + char *binlogdir; /*< The directory with the binlog files */ + SPINLOCK binlog_lock; /*< Lock to control update of the binlog position */ + char binlog_name[BINLOG_FNAMELEN+1]; /*< Name of the current binlog file */ - uint64_t binlog_position; + uint64_t binlog_position; /*< Current binlog position */ - int binlog_fd; /*< File descriptor of the binlog + int binlog_fd; /*< File descriptor of the binlog * file being written */ - uint64_t last_written; /*< Position of last event written */ - char prevbinlog[BINLOG_FNAMELEN+1]; - int rotating; /*< Rotation in progress flag */ - BLFILE *files; /*< Files used by the slaves */ - SPINLOCK fileslock; /*< Lock for the files queue above */ - unsigned int low_water; /*< Low water mark for client DCB */ - unsigned int high_water; /*< High water mark for client DCB */ - unsigned int short_burst; /*< Short burst for slave catchup */ - unsigned int long_burst; /*< Long burst for slave catchup */ - unsigned long burst_size; /*< Maximum size of burst to send */ - unsigned long heartbeat; /*< Configured heartbeat value */ - ROUTER_STATS stats; /*< Statistics for this router */ - int active_logs; - int reconnect_pending; - int retry_backoff; - time_t connect_time; - int handling_threads; - struct router_instance - *next; + uint64_t last_written; /*< Position of last event written */ + char prevbinlog[BINLOG_FNAMELEN+1]; + int rotating; /*< Rotation in progress flag */ + BLFILE *files; /*< Files used by the slaves */ + SPINLOCK fileslock; /*< Lock for the files queue above */ + unsigned int low_water; /*< Low water mark for client DCB */ + unsigned int high_water; /*< High water mark for client DCB */ + unsigned int short_burst; /*< Short burst for slave catchup */ + unsigned int long_burst; /*< Long burst for slave catchup */ + unsigned long burst_size; /*< Maximum size of burst to send */ + unsigned long heartbeat; /*< Configured heartbeat value */ + ROUTER_STATS stats; /*< Statistics for this router */ + int active_logs; + int reconnect_pending; + int retry_backoff; + time_t connect_time; + int handling_threads; + struct router_instance *next; } ROUTER_INSTANCE; /** @@ -317,6 +316,7 @@ typedef struct router_instance { #define BLRM_REGISTER 0x0012 #define BLRM_BINLOGDUMP 0x0013 #define BLRM_MARIADB10 0x0014 + #define BLRM_MAXSTATE 0x0014 static char *blrm_states[] = { "Unconnected", "Connecting", "Authenticated", "Timestamp retrieval", @@ -324,7 +324,7 @@ static char *blrm_states[] = { "Unconnected", "Connecting", "Authenticated", "Ti "binlog checksum rerieval", "GTID Mode retrieval", "Master UUID retrieval", "Set Slave UUID", "Set Names latin1", "Set Names utf8", "select 1", "select version()", "select @@version_comment", "select @@hostname", - "select @@mx_allowed_packet", "Register slave", "Binlog Dump","Set MariaDB slave capability" }; + "select @@mx_allowed_packet", "Register slave", "Binlog Dump", "Set MariaDB slave capability" }; #define BLRS_CREATED 0x0000 #define BLRS_UNREGISTERED 0x0001 diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index bc1e676d0..2efa417e4 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -448,12 +448,27 @@ char query[128]; GWBUF_CONSUME_ALL(router->saved_master.chksum2); router->saved_master.chksum2 = buf; blr_cache_response(router, "chksum2", buf); - //buf = blr_make_query("SELECT @@GLOBAL.GTID_MODE"); - buf = blr_make_query("SET @mariadb_slave_capability=4"); - router->master_state = BLRM_GTIDMODE; + + if (router->mariadb10_compat) { + buf = blr_make_query("SET @mariadb_slave_capability=4"); + router->master_state = BLRM_MARIADB10; + } else { + buf = blr_make_query("SELECT @@GLOBAL.GTID_MODE"); + router->master_state = BLRM_GTIDMODE; + } router->master->func.write(router->master, buf); break; } + case BLRM_MARIADB10: + // Response to the SET @mariadb_slave_capability=4, should be stored + if (router->saved_master.mariadb10) + GWBUF_CONSUME_ALL(router->saved_master.mariadb10); + router->saved_master.mariadb10 = buf; + blr_cache_response(router, "mariadb10", buf); + buf = blr_make_registration(router); + router->master_state = BLRM_REGISTER; + router->master->func.write(router->master, buf); + break; case BLRM_GTIDMODE: // Response to the GTID_MODE, should be stored if (router->saved_master.gtid_mode) diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 8a008e35f..fe2bc2dff 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -366,11 +366,11 @@ int query_len; free(query_text); return blr_slave_replay(router, slave, router->saved_master.heartbeat); } - else if (strcasecmp(word, "@mariadb_slave_capability") == 0) + else if (strcasecmp(word, "@mariadb_slave_capability") == 0) { free(query_text); - return blr_slave_replay(router, slave, router->saved_master.gtid_mode); - //return blr_slave_send_ok(router, slave); + if (router->mariadb10_compat) + return blr_slave_replay(router, slave, router->saved_master.mariadb10); } else if (strcasecmp(word, "@master_binlog_checksum") == 0) { From 3f2876bde35d11464638c88cc3c0f52ff13316ee Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Thu, 7 May 2015 15:32:12 +0200 Subject: [PATCH 05/14] Fixed buffer free Fixed buffer free --- server/modules/routing/binlog/blr_slave.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index fe2bc2dff..1928e5d9d 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -368,9 +368,10 @@ int query_len; } else if (strcasecmp(word, "@mariadb_slave_capability") == 0) { - free(query_text); - if (router->mariadb10_compat) + if (router->mariadb10_compat) { + free(query_text); return blr_slave_replay(router, slave, router->saved_master.mariadb10); + } } else if (strcasecmp(word, "@master_binlog_checksum") == 0) { From 2c2a03a6f696894cb015f32a0ae9d2ca50123806 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Thu, 7 May 2015 16:10:35 +0200 Subject: [PATCH 06/14] Always reply to SET @mariadb_slave_capability Always reply to SET @mariadb_slave_capability, with saved master reply for mariadb10 master or with OK otherwise --- server/modules/routing/binlog/blr_slave.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 1928e5d9d..c963d8ab4 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -368,9 +368,11 @@ int query_len; } else if (strcasecmp(word, "@mariadb_slave_capability") == 0) { + free(query_text); if (router->mariadb10_compat) { - free(query_text); 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) From 7d48779913c7ebf62bd1eed7ce5a3f437bfee0ef Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Thu, 7 May 2015 17:02:33 +0200 Subject: [PATCH 07/14] Added MAX_EVENT_TYPE_MARIADB10 check Added MAX_EVENT_TYPE_MARIADB10 check for router->mariadb10_compat --- server/modules/include/blr.h | 3 ++- server/modules/routing/binlog/blr_file.c | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/server/modules/include/blr.h b/server/modules/include/blr.h index 8aecd83f0..7b57fd15f 100644 --- a/server/modules/include/blr.h +++ b/server/modules/include/blr.h @@ -397,7 +397,8 @@ static char *blrs_states[] = { "Created", "Unregistered", "Registered", #define ANONYMOUS_GTID_EVENT 0x22 #define PREVIOUS_GTIDS_EVENT 0x23 -#define MAX_EVENT_TYPE 0xa3 +#define MAX_EVENT_TYPE 0x23 +#define MAX_EVENT_TYPE_MARIADB10 0xa3 /** * Binlog event flags diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index 2473909ec..ec7864d5e 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -443,15 +443,26 @@ struct stat statb; hdr->next_pos = EXTRACT32(&hdbuf[13]); hdr->flags = EXTRACT16(&hdbuf[17]); - if (hdr->event_type > MAX_EVENT_TYPE) - { - LOGIF(LE, (skygw_log_write(LOGFILE_ERROR, - "Invalid event type 0x%x. " + if (router->mariadb10_compat) { + if (hdr->event_type > MAX_EVENT_TYPE_MARIADB10) { + LOGIF(LE, (skygw_log_write(LOGFILE_ERROR, + "Invalid MariaDB 10 event type 0x%x. " "Binlog file is %s, position %d", hdr->event_type, file->binlogname, pos))); - return NULL; - } + return NULL; + } + } else { + if (hdr->event_type > MAX_EVENT_TYPE) { + LOGIF(LE, (skygw_log_write(LOGFILE_ERROR, + "Invalid event type 0x%x. " + "Binlog file is %s, position %d", + hdr->event_type, + file->binlogname, pos))); + + return NULL; + } + } if (hdr->next_pos < pos && hdr->event_type != ROTATE_EVENT) { From 5d1e09ca4f22ba0a5402a089173cf4652ad71e08 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Thu, 7 May 2015 17:14:39 +0200 Subject: [PATCH 08/14] Added MariaDB 10 Compatibility without GTID Added MariaDB 10 Compatibility without GTID --- server/modules/routing/binlog/blr.c | 2 ++ server/modules/routing/binlog/blr_file.c | 3 ++- server/modules/routing/binlog/blr_master.c | 3 ++- server/modules/routing/binlog/blr_slave.c | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/modules/routing/binlog/blr.c b/server/modules/routing/binlog/blr.c index 2f5a38bee..071563952 100644 --- a/server/modules/routing/binlog/blr.c +++ b/server/modules/routing/binlog/blr.c @@ -35,6 +35,8 @@ * 02/04/2014 Mark Riddoch Initial implementation * 17/02/2015 Massimiliano Pinto Addition of slave port and username in diagnostics * 18/02/2015 Massimiliano Pinto Addition of dcb_close in closeSession + * 07/05/2015 Massimiliano Pinto Addition of MariaDB 10 compatibility support + * * @endverbatim */ diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index ec7864d5e..e59a7be19 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -23,8 +23,9 @@ * @verbatim * Revision History * - * Date Who Description + * Date Who Description * 14/04/2014 Mark Riddoch Initial implementation + * 07/05/2015 Massimiliano Pinto Added MAX_EVENT_TYPE_MARIADB10 * * @endverbatim */ diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index 2efa417e4..f230442f1 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -31,8 +31,9 @@ * @verbatim * Revision History * - * Date Who Description + * Date Who Description * 02/04/2014 Mark Riddoch Initial implementation + * 07/05/2015 Massimiliano Pinto Added MariaDB 10 Compatibility * * @endverbatim */ diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index c963d8ab4..141ff3a03 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -36,9 +36,11 @@ * 18/02/2015 Massimiliano Pinto Addition of DISCONNECT ALL and DISCONNECT SERVER server_id * 18/03/2015 Markus Makela Better detection of CRC32 | NONE checksum * 19/03/2015 Massimiliano Pinto Addition of basic MariaDB 10 compatibility support + * 07/05/2015 Massimiliano Pinto Added MariaDB 10 Compatibility * * @endverbatim */ + #include #include #include From 230f88737cca9e6a5811f7261a2bc63eff0adf6a Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Thu, 7 May 2015 18:05:04 +0200 Subject: [PATCH 09/14] Added reading saved mariadb10 data Added reading saved mariadb10 data --- server/modules/routing/binlog/blr.c | 1 + 1 file changed, 1 insertion(+) diff --git a/server/modules/routing/binlog/blr.c b/server/modules/routing/binlog/blr.c index 071563952..becea18b0 100644 --- a/server/modules/routing/binlog/blr.c +++ b/server/modules/routing/binlog/blr.c @@ -395,6 +395,7 @@ unsigned char *defuuid; inst->saved_master.selectvercom = blr_cache_read_response(inst, "selectvercom"); inst->saved_master.selecthostname = blr_cache_read_response(inst, "selecthostname"); inst->saved_master.map = blr_cache_read_response(inst, "map"); + inst->saved_master.mariadb10 = blr_cache_read_response(inst, "mariadb10"); /* * Initialise the binlog file and position From f991e58b5714b82952b19d4283b0117f414e01d6 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Mon, 11 May 2015 11:43:21 +0200 Subject: [PATCH 10/14] MariaDB 10 master requires MariaDB 10 slaves Only MariaDB 10 slaves can register to binblog server with a MariaDB 10 Master --- server/modules/include/blr.h | 6 ++++-- server/modules/routing/binlog/blr.c | 1 + server/modules/routing/binlog/blr_slave.c | 26 ++++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/server/modules/include/blr.h b/server/modules/include/blr.h index 7b57fd15f..3dbc43853 100644 --- a/server/modules/include/blr.h +++ b/server/modules/include/blr.h @@ -24,8 +24,9 @@ * @verbatim * Revision History * - * Date Who Description - * 02/04/14 Mark Riddoch Initial implementation + * Date Who Description + * 02/04/14 Mark Riddoch Initial implementation + * 11/05/15 Massimilaino Pinto Added mariadb10_compat to master and slave structs * * @endverbatim */ @@ -175,6 +176,7 @@ typedef struct router_slave { uint32_t lastEventTimestamp;/*< Last event timestamp sent */ SPINLOCK catch_lock; /*< Event catchup lock */ unsigned int cstate; /*< Catch up state */ + bool mariadb10_compat;/*< MariaDB 10.0 compatibility */ SPINLOCK rses_lock; /*< Protects rses_deleted */ pthread_t pthread; struct router_instance diff --git a/server/modules/routing/binlog/blr.c b/server/modules/routing/binlog/blr.c index becea18b0..8dce5ea58 100644 --- a/server/modules/routing/binlog/blr.c +++ b/server/modules/routing/binlog/blr.c @@ -498,6 +498,7 @@ ROUTER_SLAVE *slave; strcpy(slave->binlogfile, "unassigned"); slave->connect_time = time(0); slave->lastEventTimestamp = 0; + slave->mariadb10_compat = false; /** * Add this session to the list of active sessions. diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 141ff3a03..b932000d3 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -37,6 +37,7 @@ * 18/03/2015 Markus Makela Better detection of CRC32 | NONE checksum * 19/03/2015 Massimiliano Pinto Addition of basic MariaDB 10 compatibility support * 07/05/2015 Massimiliano Pinto Added MariaDB 10 Compatibility + * 11/05/2015 Massimiliano Pinto Only MariaDB 10 Slaves can register to binlog router with a MariaDB 10 Master * * @endverbatim */ @@ -125,7 +126,27 @@ blr_slave_request(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) return blr_slave_query(router, slave, queue); break; case COM_REGISTER_SLAVE: - return blr_slave_register(router, slave, queue); + /* + * If Master is MariaDB10 don't allow registration from + * MariaDB/Mysql 5 Slaves + */ + + if (router->mariadb10_compat && !slave->mariadb10_compat) { + slave->state = BLRS_ERRORED; + blr_send_custom_error(slave->dcb, 1, 0, + "MariaDB 10 Slave is required for Slave registration"); + + LOGIF(LE, (skygw_log_write( + LOGFILE_ERROR, + "MariaDB 10 Slave is required for Slave registration", + MYSQL_COMMAND(queue)))); + + dcb_close(slave->dcb); + return 1; + } else { + /* Master and Slave version OK: continue with slave registration */ + return blr_slave_register(router, slave, queue); + } break; case COM_BINLOG_DUMP: return blr_slave_binlog_dump(router, slave, queue); @@ -370,6 +391,9 @@ int query_len; } else if (strcasecmp(word, "@mariadb_slave_capability") == 0) { + /* mariadb10 compatibility is set for the slave */ + slave->mariadb10_compat=true; + free(query_text); if (router->mariadb10_compat) { return blr_slave_replay(router, slave, router->saved_master.mariadb10); From a48e694dba044ae25debf846585c4079f17a679b Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Mon, 11 May 2015 12:42:14 +0200 Subject: [PATCH 11/14] Fix for log messages Fix for log messages about MariaDB 10 registration and unexpected query --- server/modules/routing/binlog/blr_slave.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index b932000d3..87b795ea6 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -138,8 +138,9 @@ blr_slave_request(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) LOGIF(LE, (skygw_log_write( LOGFILE_ERROR, - "MariaDB 10 Slave is required for Slave registration", - MYSQL_COMMAND(queue)))); + "%s: Slave %s: a MariaDB 10 Slave is required for Slave registration", + router->service->name, + slave->dcb->remote))); dcb_close(slave->dcb); return 1; @@ -472,7 +473,7 @@ int query_len; query_text = strndup(qtext, query_len); LOGIF(LE, (skygw_log_write( - LOGFILE_ERROR, "Unexpected query from slave server %s", query_text))); + LOGFILE_ERROR, "Unexpected query from slave %s: %s", slave->dcb->remote, query_text))); free(query_text); blr_slave_send_error(router, slave, "Unexpected SQL query received from slave."); return 1; From 2f2c9c8cbc7d4f6fc343f99c8c5e9f1bd0f7b279 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Tue, 2 Jun 2015 09:45:26 +0200 Subject: [PATCH 12/14] Fix for MariaDB10 state machine Fix for MariaDB10 state machine --- server/modules/routing/binlog/blr_master.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index f230442f1..3a0519108 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -466,8 +466,8 @@ char query[128]; GWBUF_CONSUME_ALL(router->saved_master.mariadb10); router->saved_master.mariadb10 = buf; blr_cache_response(router, "mariadb10", buf); - buf = blr_make_registration(router); - router->master_state = BLRM_REGISTER; + buf = blr_make_query("SHOW VARIABLES LIKE 'SERVER_UUID'"); + router->master_state = BLRM_MUUID; router->master->func.write(router->master, buf); break; case BLRM_GTIDMODE: From 94ba445d2fad80fd9dc7075db792ced8a3ea2001 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 28 May 2015 10:30:21 +0300 Subject: [PATCH 13/14] Added 5.5.5- string to the start of MariaDB 10.0 version strings. --- server/core/config.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/core/config.c b/server/core/config.c index d22bb777e..a2414ea7a 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -231,7 +231,7 @@ int rval; strcpy(version_string,tmp); } - ptr = strstr(tmp, "-embedded"); + ptr = strstr(version_string, "-embedded"); if (ptr) { *ptr = '\0'; } @@ -417,7 +417,21 @@ hashtable_memory_fns(monitorhash,strdup,NULL,free,NULL); } if (version_string) { + + /** Add the 5.5.5- string to the start of the version string if + * the version string starts with "10.". + * This mimics MariaDB 10.0 replication which adds 5.5.5- for backwards compatibility. */ + if(strncmp(version_string,"10.",3) == 0) + { + ((SERVICE *)(obj->element))->version_string = malloc((strlen(version_string) + + strlen("5.5.5-") + 1) * sizeof(char)); + strcpy(((SERVICE *)(obj->element))->version_string,"5.5.5-"); + strcat(((SERVICE *)(obj->element))->version_string,version_string); + } + else + { ((SERVICE *)(obj->element))->version_string = strdup(version_string); + } } else { if (gateway.version_string) ((SERVICE *)(obj->element))->version_string = strdup(gateway.version_string); From 1275a594acf71d276f6c3390cceb9ec58cd4f151 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 7 May 2015 05:56:28 +0300 Subject: [PATCH 14/14] Added missing utils library link from testmodutils. --- server/core/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/core/test/CMakeLists.txt b/server/core/test/CMakeLists.txt index 82e58919f..5c1f9a8ad 100644 --- a/server/core/test/CMakeLists.txt +++ b/server/core/test/CMakeLists.txt @@ -21,7 +21,7 @@ target_link_libraries(test_spinlock fullcore log_manager) target_link_libraries(test_filter fullcore) target_link_libraries(test_buffer fullcore log_manager) target_link_libraries(test_dcb fullcore) -target_link_libraries(test_modutil fullcore) +target_link_libraries(test_modutil fullcore utils log_manager) target_link_libraries(test_poll fullcore) target_link_libraries(test_service fullcore) target_link_libraries(test_server fullcore)