diff --git a/server/modules/routing/binlogrouter/blr_file.c b/server/modules/routing/binlogrouter/blr_file.c index cd3f736d6..c4141433d 100644 --- a/server/modules/routing/binlogrouter/blr_file.c +++ b/server/modules/routing/binlogrouter/blr_file.c @@ -516,55 +516,25 @@ blr_file_create(ROUTER_INSTANCE *router, char *file) router->storage_type == BLR_BINLOG_STORAGE_TREE) { char prefix[BINLOG_FILE_EXTRA_INFO]; + // Add prefix sprintf(prefix, - "%" PRIu32 "/", - router->mariadb10_gtid_domain); - - // Add domain_id - strcat(path, prefix); - - /** - * - 1 - Check and create $domain_id dir - */ - if (access(path, R_OK) == -1) - { - int mkdir_rval; - mkdir_rval = mkdir(path, 0700); - if (mkdir_rval == -1) - { - MXS_ERROR("Service %s, Failed to create binlog" - " directory tree (domain_id) '%s': [%d] %s", - router->service->name, - path, - errno, - mxs_strerror(errno)); - return 0; - } - } - - // Add server_id - sprintf(prefix, - "%" PRIu32 "/", + "%" PRIu32 "/%" PRIu32 "/", + router->mariadb10_gtid_domain, router->orig_masterid); strcat(path, prefix); /** - * - 2 - Check and create $server_id dir under $domain_id + * Check and create $domain_id/$server_id dir */ - if (access(path, R_OK) == -1) + if (!mxs_mkdir_all(path, 0700)) { - int mkdir_rval; - mkdir_rval = mkdir(path, 0700); - if (mkdir_rval == -1) - { - MXS_ERROR("Service %s, Failed to create binlog" - " directory tree (domain_id/server_id) '%s': [%d] %s", - router->service->name, - path, - errno, - mxs_strerror(errno)); - return 0; - } + MXS_ERROR("Service %s, Failed to create binlog" + " directory tree '%s': [%d] %s", + router->service->name, + path, + errno, + mxs_strerror(errno)); + return 0; } } diff --git a/server/modules/routing/binlogrouter/blr_master.c b/server/modules/routing/binlogrouter/blr_master.c index c38312424..f4f5bd67d 100644 --- a/server/modules/routing/binlogrouter/blr_master.c +++ b/server/modules/routing/binlogrouter/blr_master.c @@ -2821,18 +2821,41 @@ static void blr_start_master_registration(ROUTER_INSTANCE *router, GWBUF *buf) buf); // Next state is BLRM_MARIADB10_GTID_DOMAIN or BLRM_LATIN1 { - unsigned int state = router->mariadb10_master_gtid ? + /** + * Always request "gtid_domain_id" to Master server + * if MariaDB 10 Compatibilty is On + */ + unsigned int state = router->mariadb10_compat ? BLRM_MARIADB10_GTID_DOMAIN : BLRM_LATIN1; - const char *command = router->mariadb10_master_gtid ? + const char *command = router->mariadb10_compat ? "SELECT @@GLOBAL.gtid_domain_id" : "SET NAMES latin1"; blr_register_send_command(router, command, state); } break; case BLRM_MARIADB10_GTID_DOMAIN: // MariaDB10 Only - // Next state is BLRM_MARIADB10_REQUEST_GTID - blr_register_mariadb_gtid_request(router, buf); + { + // Extract GTID domain + char *val = blr_extract_column(buf, 1); + // Store the Master GTID domain + router->mariadb10_gtid_domain = atol(val); + MXS_FREE(val); + // Don't save the server response + gwbuf_free(buf); + } + + // Next state is BLRM_MARIADB10_REQUEST_GTID or BLRM_LATIN1 + if (!router->mariadb10_master_gtid) + { + blr_register_send_command(router, + "SET NAMES latin1", + BLRM_LATIN1); + } + else + { + blr_register_mariadb_gtid_request(router, buf); + } break; case BLRM_MARIADB10_REQUEST_GTID: // MariaDB10 Only // Don't save GTID request diff --git a/server/modules/routing/binlogrouter/blr_slave.c b/server/modules/routing/binlogrouter/blr_slave.c index 955b1cb1d..9717eb7c8 100644 --- a/server/modules/routing/binlogrouter/blr_slave.c +++ b/server/modules/routing/binlogrouter/blr_slave.c @@ -6521,13 +6521,13 @@ static bool blr_handle_simple_select_stmt(ROUTER_INSTANCE *router, { /* If not mariadb10 mastergtid an error message will be returned */ if (slave->mariadb10_compat && - router->mariadb10_master_gtid) + router->mariadb10_gtid) { char heading[40]; char gtid_domain[40]; sprintf(gtid_domain, - "%lu", - (unsigned long)router->mariadb10_gtid_domain); + "%" PRIu32 "", + router->mariadb10_gtid_domain); strcpy(heading, word); blr_slave_send_var_value(router, @@ -6842,14 +6842,43 @@ static bool blr_slave_gtid_request(ROUTER_INSTANCE *router, } else { - /** - * The requested binlog file is not the GTID info file. - * The binlog file could be different due to: - * a rotate event or other non GTID events written - * after that GTID. - * Events are sent from requested file@pos - */ - slave->binlog_pos = req_pos; + /** + * The requested binlog file is not the GTID info file. + * The binlog file could be different due to: + * a rotate event or other non GTID events written + * after that GTID. + * If file exists events will be sent from requested file@pos + * otherwise file & pos = GTID info file. + */ + + // Add tree prefix + char t_prefix[BINLOG_FILE_EXTRA_INFO] = ""; + char file_path[PATH_MAX + 1] = ""; + if (router->storage_type == BLR_BINLOG_STORAGE_TREE) + { + sprintf(t_prefix, + "%" PRIu32 "/%" PRIu32 "/", + f_gtid.gtid_elms.domain_id, + f_gtid.gtid_elms.server_id); + } + + // Get binlog filename full-path + blr_get_file_fullpath(slave->binlogfile, + router->binlogdir, + file_path, + t_prefix[0] ? t_prefix: NULL); + if (blr_slave_get_file_size(file_path) != 0) + { + slave->binlog_pos = req_pos; + } + else + { + /* Set binlog file to the GTID one */ + strcpy(slave->binlogfile, f_gtid.file); + + /* Set pos to GTID next event pos */ + slave->binlog_pos = f_gtid.end; + } } /* Set GTID details in f_info*/ @@ -8020,14 +8049,14 @@ static void blr_slave_skip_empty_files(ROUTER_INSTANCE *router, /** * Get the next file in sequence or next by GTID maps - * if current file has 4 bytes size. + * if current file has 4 bytes size or it doesn't exist at all. * Stop if the new file is the current binlog file. */ while (!blr_compare_binlogs(router, f_tree, router_curr_file, binlog_file) && - blr_slave_get_file_size(file_path) == 4 && + blr_slave_get_file_size(file_path) <= 4 && blr_file_next_exists(router, slave, next_file)) { // Log skipped file