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

@ -1129,7 +1129,6 @@ static bool ensure_dir_ok(const char* path, int mode)
if (path)
{
char err[MXS_STRERROR_BUFLEN];
char resolved[PATH_MAX + 1];
const char *rp = realpath(path, resolved);
@ -1150,19 +1149,19 @@ static bool ensure_dir_ok(const char* path, int mode)
else
{
MXS_ERROR("Failed to access directory '%s': %d, %s", rp,
errno, strerror_r(errno, err, sizeof(err)));
errno, mxs_strerror(errno));
}
}
else
{
MXS_ERROR("Failed to create directory '%s': %d, %s", rp,
errno, strerror_r(errno, err, sizeof(err)));
errno, mxs_strerror(errno));
}
}
else
{
MXS_ERROR("Failed to resolve real path name for '%s': %d, %s", path,
errno, strerror_r(errno, err, sizeof(err)));
errno, mxs_strerror(errno));
}
}

View File

@ -868,9 +868,8 @@ GWBUF* read_avro_json_schema(const char *avrofile, const char* dir)
}
else
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to open file '%s': %d, %s", buffer, errno,
strerror_r(errno, err, sizeof(err)));
mxs_strerror(errno));
}
}
return rval;

View File

@ -70,9 +70,8 @@ bool avro_open_binlog(const char *binlogdir, const char *file, int *dest)
{
if (errno != ENOENT)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to open binlog file %s: %d, %s", path, errno,
strerror_r(errno, err, sizeof(err)));
mxs_strerror(errno));
}
return false;
}
@ -123,7 +122,7 @@ AVRO_TABLE* avro_table_alloc(const char* filepath, const char* json_schema, cons
if (access(filepath, F_OK) == 0)
{
rc = avro_file_writer_open(filepath, &table->avro_file);
rc = avro_file_writer_open_bs(filepath, &table->avro_file, block_size);
}
else
{
@ -166,7 +165,6 @@ bool avro_save_conversion_state(AVRO_INSTANCE *router)
{
FILE *config_file;
char filename[PATH_MAX + 1];
char err_msg[MXS_STRERROR_BUFLEN];
snprintf(filename, sizeof(filename), "%s/"AVRO_PROGRESS_FILE".tmp", router->avrodir);
@ -176,7 +174,7 @@ bool avro_save_conversion_state(AVRO_INSTANCE *router)
if (config_file == NULL)
{
MXS_ERROR("Failed to open file '%s': %d, %s", filename,
errno, strerror_r(errno, err_msg, sizeof(err_msg)));
errno, mxs_strerror(errno));
return false;
}
@ -195,7 +193,7 @@ bool avro_save_conversion_state(AVRO_INSTANCE *router)
if (rc == -1)
{
MXS_ERROR("Failed to rename file '%s' to '%s': %d, %s", filename, newname,
errno, strerror_r(errno, err_msg, sizeof(err_msg)));
errno, mxs_strerror(errno));
return false;
}
@ -425,11 +423,10 @@ static GWBUF* read_event_data(AVRO_INSTANCE *router, REP_HEADER* hdr, uint64_t p
{
if (n == -1)
{
char err_msg[MXS_STRERROR_BUFLEN];
MXS_ERROR("Error reading the event at %lu in %s. "
"%s, expected %d bytes.",
pos, router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)),
mxs_strerror(errno),
hdr->event_size - BINLOG_EVENT_HDR_LEN);
}
else
@ -519,10 +516,9 @@ avro_binlog_end_t avro_read_all_events(AVRO_INSTANCE *router)
break;
case -1:
{
char err_msg[BLRM_STRERROR_R_MSG_SIZE + 1] = "";
MXS_ERROR("Failed to read binlog file %s at position %llu (%s).",
router->binlog_name, pos,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
if (errno == EBADF)
MXS_ERROR("Bad file descriptor in read binlog for file %s"

View File

@ -699,12 +699,11 @@ createInstance(SERVICE *service, char **options)
mkdir_rval = mkdir(inst->binlogdir, 0700);
if (mkdir_rval == -1)
{
char err_msg[MXS_STRERROR_BUFLEN];
MXS_ERROR("Service %s, Failed to create binlog directory '%s': [%d] %s",
service->name,
inst->binlogdir,
errno,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
free_instance(inst);
return NULL;
@ -1840,8 +1839,7 @@ errorReply(MXS_ROUTER *instance,
getsockopt(router->master->fd, SOL_SOCKET, SO_ERROR, &error, &len) == 0 &&
error != 0)
{
char errbuf[MXS_STRERROR_BUFLEN];
sprintf(msg, "%s ", strerror_r(error, errbuf, sizeof(errbuf)));
sprintf(msg, "%s ", mxs_strerror(error));
}
else
{
@ -2678,10 +2676,9 @@ int blr_parse_key_file(ROUTER_INSTANCE *router)
if (!file)
{
char errbuf[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to open KEY file '%s': %s",
router->encryption.key_management_filename,
strerror_r(errno, errbuf, sizeof(errbuf)));
mxs_strerror(errno));
return -1;
}

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;

View File

@ -2038,11 +2038,10 @@ GWBUF
break;
case -1:
{
char err_msg[MXS_STRERROR_BUFLEN];
MXS_ERROR("Reading saved events: failed to read binlog "
"file %s at position %llu"
" (%s).", router->binlog_name,
pos, strerror_r(errno, err_msg, sizeof(err_msg)));
pos, mxs_strerror(errno));
if (errno == EBADF)
{
@ -2098,11 +2097,10 @@ GWBUF
{
if (n == -1)
{
char err_msg[MXS_STRERROR_BUFLEN];
MXS_ERROR("Reading saved events: the event at %llu in %s. "
"%s, expected %d bytes.",
pos, router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)), hdr->event_size - 19);
mxs_strerror(errno), hdr->event_size - 19);
}
else
{
@ -2350,12 +2348,11 @@ blr_write_data_into_binlog(ROUTER_INSTANCE *router, uint32_t data_len, uint8_t *
if ((n = pwrite(router->binlog_fd, buf, data_len,
router->last_written)) != data_len)
{
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))
@ -2363,7 +2360,7 @@ blr_write_data_into_binlog(ROUTER_INSTANCE *router, uint32_t data_len, uint8_t *
MXS_ERROR("%s: Failed to truncate binlog record at %lu of %s, %s. ",
router->service->name, router->last_written,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
}
return 0;
}

View File

@ -936,10 +936,9 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue)
if (removed_cfg == -1)
{
char err_msg[MXS_STRERROR_BUFLEN];
snprintf(error_string, BINLOG_ERROR_MSG_LEN,
"Error removing %s, %s, errno %u", path,
strerror_r(errno, err_msg, sizeof(err_msg)), errno);
mxs_strerror(errno), errno);
MXS_ERROR("%s: %s", router->service->name, error_string);
}
@ -3782,9 +3781,8 @@ blr_start_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave)
/* Truncate previous binlog file to last_safe pos */
if (truncate(file, router->last_safe_pos) == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to truncate file: %d, %s",
errno, strerror_r(errno, err, sizeof(err)));
errno, mxs_strerror(errno));
}
/* Log it */

View File

@ -594,7 +594,8 @@ bool rwsplit_get_dcb(DCB **p_dcb, ROUTER_CLIENT_SES *rses, backend_type_t btype,
* backend and update assign it to new candidate if
* necessary.
*/
else if (SERVER_IS_SLAVE(&server))
else if (SERVER_IS_SLAVE(&server) ||
(rses->rses_config.master_accept_reads && SERVER_IS_MASTER(&server)))
{
if (max_rlag == MAX_RLAG_UNDEFINED ||
(b->server->rlag != MAX_RLAG_NOT_AVAILABLE &&

View File

@ -3313,11 +3313,13 @@ static rses_property_t* mysql_sescmd_get_property(mysql_sescmd_t* scmd)
}
/**
* Return RCAP_TYPE_STMT_INPUT.
* @brief Get router capabilities
*
* @return Always RCAP_TYPE_CONTIGUOUS_INPUT
*/
static uint64_t getCapabilities(MXS_ROUTER* instance)
{
return RCAP_TYPE_STMT_INPUT;
return RCAP_TYPE_CONTIGUOUS_INPUT;
}
/**