Add default for missing MASTER_LOG_POS

Add default for missing MASTER_LOG_POS

4 if binlog is a new one
current pos if binlog = current one
This commit is contained in:
MassimilianoPinto
2015-06-23 17:19:54 +02:00
parent 7a0a010a86
commit 543873a44f

View File

@ -2432,6 +2432,8 @@ int blr_handle_change_master(ROUTER_INSTANCE* router, char *command, char *error
char *master_user = NULL;
char *master_password = NULL;
int change_binlog = 0;
long long pos = 0;
char *passed_pos = NULL;
MASTER_SERVER_CFG *current_master = NULL;
/* save current replication parameters */
@ -2485,15 +2487,16 @@ int blr_handle_change_master(ROUTER_INSTANCE* router, char *command, char *error
}
/* Change the position in the current or new binlog filename */
if (master_log_pos) {
char *passed_pos = master_log_pos + 15;
long long pos = atoll(passed_pos);
free(master_log_pos);
if (master_log_pos == NULL) {
pos = 0;
} else {
passed_pos = master_log_pos + 15;
pos = atoll(passed_pos);
}
/* if binlog name has changed to next one only position 4 is allowed */
if (strcmp(master_logfile, router->binlog_name)) {
if (pos != 4) {
if (pos > 0 && pos != 4) {
snprintf(error, BINLOG_ERROR_MSG_LEN, "Can not set MASTER_LOG_POS to %s for MASTER_LOG_FILE %s: "
"Permitted binlog pos is %d. Current master_log_file=%s, master_log_pos=%lu",
@ -2505,6 +2508,8 @@ int blr_handle_change_master(ROUTER_INSTANCE* router, char *command, char *error
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR, "%s: %s", router->service->name, error)));
if (master_log_pos)
free(master_log_pos);
free(master_logfile);
/* restore previous master_host and master_port */
@ -2521,6 +2526,8 @@ int blr_handle_change_master(ROUTER_INSTANCE* router, char *command, char *error
router->binlog_position = 4;
if (master_log_pos)
free(master_log_pos);
free(master_logfile);
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE, "%s: New MASTER_LOG_FILE is [%s]",
@ -2528,10 +2535,8 @@ int blr_handle_change_master(ROUTER_INSTANCE* router, char *command, char *error
router->binlog_name)));
}
} else {
free(master_logfile);
/* Position cannot be different from current pos */
if (pos != router->binlog_position) {
if (pos > 0 && pos != router->binlog_position) {
snprintf(error, BINLOG_ERROR_MSG_LEN, "Can not set MASTER_LOG_POS to %s: "
"Permitted binlog pos is %lu. Current master_log_file=%s, master_log_pos=%lu",
@ -2542,23 +2547,26 @@ int blr_handle_change_master(ROUTER_INSTANCE* router, char *command, char *error
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR, "%s: %s", router->service->name, error)));
if (master_log_pos)
free(master_log_pos);
free(master_logfile);
/* restore previous master_host and master_port */
blr_master_restore_config(router, current_master);
spinlock_release(&router->lock);
return -1;
} else {
/* set new position */
router->binlog_position = pos;
if (master_log_pos)
free(master_log_pos);
free(master_logfile);
}
}
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE, "%s: New MASTER_LOG_POS is [%u]",
router->service->name,
router->binlog_position)));
}
/* Change the replication user */
if (master_user) {