Merge branch 'develop' into MXS-1075

This commit is contained in:
MassimilianoPinto
2017-03-09 15:08:04 +01:00
55 changed files with 809 additions and 668 deletions

View File

@ -308,10 +308,9 @@ blr_file_init(ROUTER_INSTANCE *router)
root_len = strlen(router->fileroot);
if ((dirp = opendir(path)) == NULL)
{
char err_msg[BLRM_STRERROR_R_MSG_SIZE];
MXS_ERROR("%s: Unable to read the binlog directory %s, %s.",
router->service->name, router->binlogdir,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
return 0;
}
while ((dp = readdir(dirp)) != NULL)
@ -434,20 +433,20 @@ blr_file_create(ROUTER_INSTANCE *router, char *file)
else
{
MXS_ERROR("%s: Failed to write magic string to created binlog file %s, %s.",
router->service->name, path, strerror_r(errno, err_msg, sizeof(err_msg)));
router->service->name, path, mxs_strerror(errno));
close(fd);
if (!unlink(path))
{
MXS_ERROR("%s: Failed to delete file %s, %s.",
router->service->name, path, strerror_r(errno, err_msg, sizeof(err_msg)));
router->service->name, path, mxs_strerror(errno));
}
}
}
else
{
MXS_ERROR("%s: Failed to create binlog file %s, %s.",
router->service->name, path, strerror_r(errno, err_msg, sizeof(err_msg)));
router->service->name, path, mxs_strerror(errno));
}
return created;
@ -578,19 +577,18 @@ blr_write_binlog_record(ROUTER_INSTANCE *router, REP_HEADER *hdr, uint32_t size,
/* Check write operation result*/
if (n != size)
{
char err_msg[MXS_STRERROR_BUFLEN];
MXS_ERROR("%s: Failed to write binlog record at %lu of %s, %s. "
"Truncating to previous record.",
router->service->name, router->binlog_position,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
/* Remove any partial event that was written */
if (ftruncate(router->binlog_fd, router->binlog_position))
{
MXS_ERROR("%s: Failed to truncate binlog record at %lu of %s, %s. ",
router->service->name, router->binlog_position,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
}
return 0;
}
@ -837,9 +835,8 @@ blr_read_binlog(ROUTER_INSTANCE *router,
break;
case -1:
{
char err_msg[MXS_STRERROR_BUFLEN];
snprintf(errmsg, BINLOG_ERROR_MSG_LEN, "Failed to read binlog file '%s'; (%s), event at %lu",
file->binlogname, strerror_r(errno, err_msg, sizeof(err_msg)), pos);
file->binlogname, mxs_strerror(errno), pos);
if (errno == EBADF)
{
@ -900,10 +897,9 @@ blr_read_binlog(ROUTER_INSTANCE *router,
break;
case -1:
{
char err_msg[MXS_STRERROR_BUFLEN];
snprintf(errmsg, BINLOG_ERROR_MSG_LEN,
"Failed to reread header in binlog file '%s'; (%s), event at %lu",
file->binlogname, strerror_r(errno, err_msg, sizeof(err_msg)), pos);
file->binlogname, mxs_strerror(errno), pos);
if (errno == EBADF)
{
@ -984,13 +980,12 @@ blr_read_binlog(ROUTER_INSTANCE *router,
if (n == -1)
{
char err_msg[MXS_STRERROR_BUFLEN];
snprintf(errmsg, BINLOG_ERROR_MSG_LEN,
"Error reading the binlog event at %lu in binlog file '%s';"
"(%s), expected %d bytes.",
pos,
file->binlogname,
strerror_r(errno, err_msg, sizeof(err_msg)),
mxs_strerror(errno),
hdr->event_size - BINLOG_EVENT_HDR_LEN);
}
else
@ -1200,9 +1195,8 @@ blr_cache_response(ROUTER_INSTANCE *router, char *response, GWBUF *buf)
}
if (write(fd, GWBUF_DATA(buf), GWBUF_LENGTH(buf)) == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to write cached response: %d, %s",
errno, strerror_r(errno, err, sizeof(err)));
errno, mxs_strerror(errno));
}
close(fd);
@ -1258,9 +1252,8 @@ blr_cache_read_response(ROUTER_INSTANCE *router, char *response)
}
if (read(fd, GWBUF_DATA(buf), statb.st_size) == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to read cached response: %d, %s",
errno, strerror_r(errno, err, sizeof(err)));
errno, mxs_strerror(errno));
}
close(fd);
return buf;
@ -1439,10 +1432,9 @@ blr_read_events_all_events(ROUTER_INSTANCE *router,
break;
case -1:
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to read binlog file %s at position %llu"
" (%s).", router->binlog_name, pos,
strerror_r(errno, err, sizeof(err)));
mxs_strerror(errno));
if (errno == EBADF)
{
@ -1658,11 +1650,10 @@ blr_read_events_all_events(ROUTER_INSTANCE *router,
{
if (n == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Error reading the event at %llu in %s. "
"%s, expected %d bytes.",
pos, router->binlog_name,
strerror_r(errno, err, sizeof(err)),
mxs_strerror(errno),
hdr.event_size - BINLOG_EVENT_HDR_LEN);
}
else
@ -2467,7 +2458,6 @@ blr_file_write_master_config(ROUTER_INSTANCE *router, char *error)
char filename[len + sizeof('/') + sizeof(MASTER_INI)]; // sizeof includes NULL
char tmp_file[len + sizeof('/') + sizeof(MASTER_INI) + sizeof('.') + sizeof(TMP)];
char err_msg[MXS_STRERROR_BUFLEN];
char *ssl_ca;
char *ssl_cert;
char *ssl_key;
@ -2481,7 +2471,7 @@ blr_file_write_master_config(ROUTER_INSTANCE *router, char *error)
if (config_file == NULL)
{
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u",
strerror_r(errno, err_msg, sizeof(err_msg)), errno);
mxs_strerror(errno), errno);
return 2;
}
@ -2489,7 +2479,7 @@ blr_file_write_master_config(ROUTER_INSTANCE *router, char *error)
{
fclose(config_file);
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u",
strerror_r(errno, err_msg, sizeof(err_msg)), errno);
mxs_strerror(errno), errno);
return 2;
}
@ -2541,14 +2531,14 @@ blr_file_write_master_config(ROUTER_INSTANCE *router, char *error)
if (rc == -1)
{
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u",
strerror_r(errno, err_msg, sizeof(err_msg)), errno);
mxs_strerror(errno), errno);
return 3;
}
if (chmod(filename, S_IRUSR | S_IWUSR) < 0)
{
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u",
strerror_r(errno, err_msg, sizeof(err_msg)), errno);
mxs_strerror(errno), errno);
return 3;
}
@ -2748,12 +2738,11 @@ blr_write_special_event(ROUTER_INSTANCE *router, uint32_t file_offset, uint32_t
/* Write the event */
if ((n = pwrite(router->binlog_fd, new_event, event_size, router->last_written)) != event_size)
{
char err_msg[MXS_STRERROR_BUFLEN];
MXS_ERROR("%s: Failed to write %s special binlog record at %lu of %s, %s. "
"Truncating to previous record.",
router->service->name, new_event_desc, (unsigned long)file_offset,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
/* Remove any partial event that was written */
if (ftruncate(router->binlog_fd, router->binlog_position))
@ -2761,7 +2750,7 @@ blr_write_special_event(ROUTER_INSTANCE *router, uint32_t file_offset, uint32_t
MXS_ERROR("%s: Failed to truncate %s special binlog record at %lu of %s, %s. ",
router->service->name, new_event_desc, (unsigned long)file_offset,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
}
MXS_FREE(new_event);
return 0;