From 7dd498f0b942c94b5024198c45ba35489fc87cb9 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Mon, 31 Oct 2016 14:18:38 +0100 Subject: [PATCH] =?UTF-8?q?MXS-958:=20a=20new=20binlog=20file=20is=20creat?= =?UTF-8?q?ed=20after=20CHANGE=20MASTER=20if=20there=20is=E2=80=A6=20?= =?UTF-8?q?=E2=80=A6=20no=20pending=20transaction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Binlog server is already configured: if there is no pending transaction a new binlog file is created after CHANGE MASTER. If as START SLAVE is issued replication starts as usuale. If maxscale is restarted the replication starts using the new created file. --- server/modules/routing/binlog/blr_slave.c | 51 ++++++++++++----------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index b037dd8d2..b109acaf5 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -1044,11 +1044,8 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) { MXS_INFO("%s: 'master.ini' created, binlog file '%s' created", router->service->name, router->binlog_name); } - } - - if (!router->trx_safe) - { blr_master_free_config(current_master); + return blr_slave_send_ok(router, slave); } if (router->trx_safe && router->pending_transaction) @@ -1064,17 +1061,24 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) return blr_slave_send_warning_message(router, slave, message); } - else - { - blr_master_free_config(current_master); - return blr_slave_send_ok(router, slave); - } + } - } - else + blr_master_free_config(current_master); + + /* + * The CHAMGE MASTER command might specify a new binlog file. + * Let's create the binlogfile specified in MASTER_LOG_FILE + */ + + if (strlen(router->prevbinlog) && strcmp(router->prevbinlog, router->binlog_name)) { - return blr_slave_send_ok(router, slave); - } + if (blr_file_new_binlog(router, router->binlog_name)) + { + MXS_INFO("%s: created new binlog file '%s' by 'CHANGE MASTER TO' command", + router->service->name, router->binlog_name); + } + } + return blr_slave_send_ok(router, slave); } } } @@ -3456,24 +3460,23 @@ blr_start_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave) /* Send warning message to mysql command */ blr_slave_send_warning_message(router, slave, msg); } + } - /* create new one */ + /* No file has beem opened, create a new binlog file */ + if (router->binlog_fd == -1) + { blr_file_new_binlog(router, router->binlog_name); } else { - if (router->binlog_fd == -1) - { - /* create new one */ - blr_file_new_binlog(router, router->binlog_name); - } - else - { - /* use existing one */ - blr_file_append(router, router->binlog_name); - } + /* A new binlog file has been created by CHANGE MASTER TO + * if no pending transaction is detected. + * use the existing one. + */ + blr_file_use_binlog(router, router->binlog_name); } + /* Start the replication from Master server */ blr_start_master(router); MXS_NOTICE("%s: START SLAVE executed by %s@%s. Trying connection to master %s:%d, "