Develop merge

Develop merge
This commit is contained in:
MassimilianoPinto
2015-11-19 17:06:30 +01:00
29 changed files with 5387 additions and 5203 deletions

View File

@ -157,9 +157,7 @@ version()
void
ModuleInit()
{
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"Initialise binlog router module %s.\n", version_str)));
MXS_NOTICE("Initialise binlog router module %s.\n", version_str);
spinlock_init(&instlock);
instances = NULL;
}
@ -206,17 +204,16 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
if(service->credentials.name == NULL ||
service->credentials.authdata == NULL)
{
skygw_log_write(LE,"%s: Error: Service is missing user credentials."
" Add the missing username or passwd parameter to the service.",
service->name);
MXS_ERROR("%s: Error: Service is missing user credentials."
" Add the missing username or passwd parameter to the service.",
service->name);
return NULL;
}
if(options == NULL || options[0] == NULL)
{
skygw_log_write(LE,
"%s: Error: No router options supplied for binlogrouter",
service->name);
MXS_ERROR("%s: Error: No router options supplied for binlogrouter",
service->name);
return NULL;
}
@ -227,11 +224,10 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
*/
if (service->dbref != NULL)
{
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"%s: Warning: backend database server is provided by master.ini file "
"for use with the binlog router."
" Server section is no longer required.",
service->name)));
MXS_WARNING("%s: backend database server is provided by master.ini file "
"for use with the binlog router."
" Server section is no longer required.",
service->name);
server_free(service->dbref->server);
free(service->dbref);
@ -239,9 +235,8 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
}
if ((inst = calloc(1, sizeof(ROUTER_INSTANCE))) == NULL) {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"%s: Error: failed to allocate memory for router instance.",
service->name)));
MXS_ERROR("%s: Error: failed to allocate memory for router instance.",
service->name);
return NULL;
}
@ -328,10 +323,9 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
{
if ((value = strchr(options[i], '=')) == NULL)
{
LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR, "Warning : Unsupported router "
MXS_WARNING("Unsupported router "
"option %s for binlog router.",
options[i])));
options[i]);
}
else
{
@ -345,20 +339,16 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
{
inst->serverid = atoi(value);
if (strcmp(options[i], "server-id") == 0) {
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"WARNING: Configuration setting '%s' in router_options is deprecated"
" and will be removed in a later version of MaxScale. "
"Please use the new setting '%s' instead.",
"server-id", "server_id")));
MXS_WARNING("Configuration setting '%s' in router_options is deprecated"
" and will be removed in a later version of MaxScale. "
"Please use the new setting '%s' instead.",
"server-id", "server_id");
}
if (inst->serverid <= 0) {
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Service %s, invalid server-id '%s'. "
"Please configure it with a unique positive integer value (1..2^32-1)",
service->name, value)));
MXS_ERROR("Service %s, invalid server-id '%s'. "
"Please configure it with a unique positive integer value (1..2^32-1)",
service->name, value);
free(inst);
return NULL;
@ -384,12 +374,10 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
inst->set_master_server_id = strdup(value);
}
if (strcmp(options[i], "master-id") == 0) {
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"WARNING: Configuration setting '%s' in router_options is deprecated"
" and will be removed in a later version of MaxScale. "
"Please use the new setting '%s' instead.",
"master-id", "master_id")));
MXS_WARNING("Configuration setting '%s' in router_options is deprecated"
" and will be removed in a later version of MaxScale. "
"Please use the new setting '%s' instead.",
"master-id", "master_id");
}
}
else if (strcmp(options[i], "master_uuid") == 0)
@ -466,11 +454,9 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
int h_val = (int)strtol(value, NULL, 10);
if (h_val <= 0 || (errno == ERANGE)) {
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Warning : invalid heartbeat period %s."
" Setting it to default value %ld.",
value, inst->heartbeat)));
MXS_WARNING("Invalid heartbeat period %s."
" Setting it to default value %ld.",
value, inst->heartbeat);
} else {
inst->heartbeat = h_val;
}
@ -485,20 +471,17 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
}
else
{
LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR,
"Warning : Unsupported router "
"option %s for binlog router.",
options[i])));
MXS_WARNING("Unsupported router "
"option %s for binlog router.",
options[i]);
}
}
}
}
else
{
LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR, "%s: Error: No router options supplied for binlogrouter",
service->name)));
MXS_ERROR("%s: Error: No router options supplied for binlogrouter",
service->name);
}
if (inst->fileroot == NULL)
@ -520,18 +503,16 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
strcpy(inst->prevbinlog, "");
if ((inst->binlogdir == NULL) || (inst->binlogdir != NULL && !strlen(inst->binlogdir))) {
skygw_log_write_flush(LOGFILE_ERROR,
"Error : Service %s, binlog directory is not specified",
service->name);
MXS_ERROR("Service %s, binlog directory is not specified",
service->name);
free(inst);
return NULL;
}
if (inst->serverid <= 0) {
skygw_log_write_flush(LOGFILE_ERROR,
"Error : Service %s, server-id is not configured. "
"Please configure it with a unique positive integer value (1..2^32-1)",
service->name);
MXS_ERROR("Service %s, server-id is not configured. "
"Please configure it with a unique positive integer value (1..2^32-1)",
service->name);
free(inst);
return NULL;
}
@ -545,12 +526,11 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
mkdir_rval = mkdir(inst->binlogdir, 0700);
if (mkdir_rval == -1) {
char err_msg[STRERROR_BUFLEN];
skygw_log_write_flush(LOGFILE_ERROR,
"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_ERROR("Service %s, Failed to create binlog directory '%s': [%d] %s",
service->name,
inst->binlogdir,
errno,
strerror_r(errno, err_msg, sizeof(err_msg)));
free(inst);
return NULL;
@ -561,9 +541,8 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
if (service->users == NULL) {
service->users = (void *)mysql_users_alloc();
if (service->users == NULL) {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"%s: Error allocating dbusers in createInstance",
inst->service->name)));
MXS_ERROR("%s: Error allocating dbusers in createInstance",
inst->service->name);
free(inst);
return NULL;
@ -576,9 +555,8 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
SERVER *server;
server = server_alloc("_none_", "MySQLBackend", (int)3306);
if (server == NULL) {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"%s: Error for server_alloc in createInstance",
inst->service->name)));
MXS_ERROR("%s: Error for server_alloc in createInstance",
inst->service->name);
if (service->users) {
users_free(service->users);
service->users = NULL;
@ -605,11 +583,10 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
rc = ini_parse(filename, blr_handler_config, inst);
LOGIF(LT, (skygw_log_write_flush(LOGFILE_TRACE,
"%s: %s parse result is %d",
inst->service->name,
filename,
rc)));
MXS_INFO("%s: %s parse result is %d",
inst->service->name,
filename,
rc);
/*
* retcode:
@ -618,17 +595,15 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
if (rc != 0) {
if (rc == -1) {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"%s: master.ini file not found in %s."
" Master registration cannot be started."
" Configure with CHANGE MASTER TO ...",
inst->service->name, inst->binlogdir)));
MXS_ERROR("%s: master.ini file not found in %s."
" Master registration cannot be started."
" Configure with CHANGE MASTER TO ...",
inst->service->name, inst->binlogdir);
} else {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"%s: master.ini file with errors in %s."
" Master registration cannot be started."
" Fix errors in it or configure with CHANGE MASTER TO ...",
inst->service->name, inst->binlogdir)));
MXS_ERROR("%s: master.ini file with errors in %s."
" Master registration cannot be started."
" Fix errors in it or configure with CHANGE MASTER TO ...",
inst->service->name, inst->binlogdir);
}
/* Set service user or load db users */
@ -652,11 +627,9 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
/* Find latest binlog file or create a new one (000001) */
if (blr_file_init(inst) == 0)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"%s: Service not started due to lack of binlog directory %s",
service->name,
inst->binlogdir)));
MXS_ERROR("%s: Service not started due to lack of binlog directory %s",
service->name,
inst->binlogdir);
if (service->users) {
users_free(service->users);
@ -696,10 +669,8 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
/* Log whether the transaction safety option value is on*/
if (inst->trx_safe) {
LOGIF(LT, (skygw_log_write_flush(
LOGFILE_TRACE,
"%s: Service has transaction safety option set to ON",
service->name)));
MXS_INFO("%s: Service has transaction safety option set to ON",
service->name);
}
/**
@ -707,9 +678,8 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
*/
if (inst->master_state == BLRM_UNCONNECTED) {
/* Check current binlog */
LOGIF(LM, (skygw_log_write_flush(
LOGFILE_MESSAGE, "Validating binlog file '%s' ...",
inst->binlog_name)));
MXS_NOTICE("Validating binlog file '%s' ...",
inst->binlog_name);
if (inst->trx_safe && !blr_check_binlog(inst)) {
/* Don't start replication, just return */
@ -717,15 +687,11 @@ char task_name[BLRM_TASK_NAME_LEN+1] = "";
}
if (!inst->trx_safe) {
LOGIF(LT, (skygw_log_write_flush(
LOGFILE_TRACE,
"Current binlog file is %s, current pos is %lu\n",
inst->binlog_name, inst->binlog_position)));
MXS_INFO("Current binlog file is %s, current pos is %lu\n",
inst->binlog_name, inst->binlog_position);
} else {
LOGIF(LT, (skygw_log_write_flush(
LOGFILE_TRACE,
"Current binlog file is %s, safe pos %lu, current pos is %lu\n",
inst->binlog_name, inst->binlog_position, inst->current_pos)));
MXS_INFO("Current binlog file is %s, safe pos %lu, current pos is %lu\n",
inst->binlog_name, inst->binlog_position, inst->current_pos);
}
/* Start replication from master server */
@ -752,20 +718,16 @@ newSession(ROUTER *instance, SESSION *session)
ROUTER_INSTANCE *inst = (ROUTER_INSTANCE *)instance;
ROUTER_SLAVE *slave;
LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG,
"binlog router: %lu [newSession] new router session with "
"session %p, and inst %p.",
pthread_self(),
session,
inst)));
MXS_DEBUG("binlog router: %lu [newSession] new router session with "
"session %p, and inst %p.",
pthread_self(),
session,
inst);
if ((slave = (ROUTER_SLAVE *)calloc(1, sizeof(ROUTER_SLAVE))) == NULL)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Insufficient memory to create new slave session for binlog router")));
MXS_ERROR("Insufficient memory to create new slave session for binlog router");
return NULL;
}
@ -849,14 +811,12 @@ int prev_val;
}
spinlock_release(&router->lock);
LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG,
"%lu [freeSession] Unlinked router_client_session %p from "
"router %p. Connections : %d. ",
pthread_self(),
slave,
router,
prev_val-1)));
MXS_DEBUG("%lu [freeSession] Unlinked router_client_session %p from "
"router %p. Connections : %d. ",
pthread_self(),
slave,
router,
prev_val-1);
if (slave->hostname)
free(slave->hostname);
@ -886,16 +846,12 @@ ROUTER_SLAVE *slave = (ROUTER_SLAVE *)router_session;
/*
* We must be closing the master session.
*/
LOGIF(LM, (skygw_log_write_flush(
LOGFILE_MESSAGE,
"%s: Master %s disconnected after %ld seconds. "
"%lu events read,",
router->service->name, router->service->dbref->server->name,
time(0) - router->connect_time, router->stats.n_binlogs_ses)));
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Binlog router close session with master server %s",
router->service->dbref->server->unique_name)));
MXS_NOTICE("%s: Master %s disconnected after %ld seconds. "
"%lu events read,",
router->service->name, router->service->dbref->server->name,
time(0) - router->connect_time, router->stats.n_binlogs_ses);
MXS_ERROR("Binlog router close session with master server %s",
router->service->dbref->server->unique_name);
blr_master_reconnect(router);
return;
}
@ -923,14 +879,12 @@ ROUTER_SLAVE *slave = (ROUTER_SLAVE *)router_session;
slave->binlogfile,
(unsigned long)slave->binlog_pos)));
} else {
LOGIF(LM, (skygw_log_write_flush(
LOGFILE_MESSAGE,
"%s: Slave %s, server id %d, disconnected after %ld seconds. "
"%d SQL commands",
router->service->name, slave->dcb->remote,
slave->serverid,
time(0) - slave->connect_time,
slave->stats.n_queries)));
MXS_NOTICE("%s: Slave %s, server id %d, disconnected after %ld seconds. "
"%d SQL commands",
router->service->name, slave->dcb->remote,
slave->serverid,
time(0) - slave->connect_time,
slave->stats.n_queries);
}
/*
@ -1440,33 +1394,29 @@ unsigned long mysql_errno;
free(router->m_errmsg);
router->m_errmsg = strdup(errmsg);
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, "%s: Master connection error %lu '%s' in state '%s', "
"%sattempting reconnect to master %s:%d",
router->service->name, mysql_errno, errmsg,
blrm_states[router->master_state], msg,
router->service->dbref->server->name,
router->service->dbref->server->port)));
MXS_ERROR("%s: Master connection error %lu '%s' in state '%s', "
"%sattempting reconnect to master %s:%d",
router->service->name, mysql_errno, errmsg,
blrm_states[router->master_state], msg,
router->service->dbref->server->name,
router->service->dbref->server->port);
} else {
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR, "%s: Master connection error %lu '%s' in state '%s', "
"%sattempting reconnect to master %s:%d",
router->service->name, router->m_errno, router->m_errmsg,
blrm_states[router->master_state], msg,
router->service->dbref->server->name,
router->service->dbref->server->port)));
MXS_ERROR("%s: Master connection error %lu '%s' in state '%s', "
"%sattempting reconnect to master %s:%d",
router->service->name, router->m_errno, router->m_errmsg,
blrm_states[router->master_state], msg,
router->service->dbref->server->name,
router->service->dbref->server->port);
}
if (errmsg)
free(errmsg);
*succp = true;
dcb_close(backend_dcb);
LOGIF(LM, (skygw_log_write_flush(
LOGFILE_MESSAGE,
"%s: Master %s disconnected after %ld seconds. "
"%lu events read.",
router->service->name, router->service->dbref->server->name,
time(0) - router->connect_time, router->stats.n_binlogs_ses)));
MXS_NOTICE("%s: Master %s disconnected after %ld seconds. "
"%lu events read.",
router->service->name, router->service->dbref->server->name,
time(0) - router->connect_time, router->stats.n_binlogs_ses);
blr_master_reconnect(router);
}
@ -1734,10 +1684,10 @@ SERVICE *service;
{
return blr_handle_config_item(name, value, inst);
} else {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"Error : master.ini has an invalid section [%s], it should be [binlog_configuration]. Service %s",
section,
service->name)));
MXS_ERROR("master.ini has an invalid section [%s], it should be [binlog_configuration]. "
"Service %s",
section,
service->name);
return 0;
}
@ -1796,9 +1746,8 @@ char *service_user = NULL;
char *service_passwd = NULL;
if (serviceGetUser(service, &service_user, &service_passwd) == 0) {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"failed to get service user details for service %s",
service->name)));
MXS_ERROR("failed to get service user details for service %s",
service->name);
return 1;
}
@ -1806,10 +1755,9 @@ char *service_passwd = NULL;
dpwd = decryptPassword(service->credentials.authdata);
if (!dpwd) {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"decrypt password failed for service user %s, service %s",
service_user,
service->name)));
MXS_ERROR("decrypt password failed for service user %s, service %s",
service_user,
service->name);
return 1;
}
@ -1817,9 +1765,8 @@ char *service_passwd = NULL;
newpasswd = create_hex_sha1_sha1_passwd(dpwd);
if (!newpasswd) {
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
"create hex_sha1_sha1_password failed for service user %s",
service_user)));
MXS_ERROR("create hex_sha1_sha1_password failed for service user %s",
service_user);
free(dpwd);
return 1;
@ -1859,10 +1806,8 @@ SERVICE *service;
if (loaded < 0)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Unable to load users for service %s",
service->name)));
MXS_ERROR("Unable to load users for service %s",
service->name);
/* Try loading authentication data from file cache */
@ -1870,29 +1815,23 @@ SERVICE *service;
if (loaded != -1)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Service %s, Using cached credential information file %s.",
service->name,
path)));
MXS_ERROR("Service %s, Using cached credential information file %s.",
service->name,
path);
} else {
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error: Service %s, Unable to read cache credential information from %s."
" No database user added to service users table.",
service->name,
path)));
MXS_ERROR("Service %s, Unable to read cache credential information from %s."
" No database user added to service users table.",
service->name,
path);
}
} else {
/* don't update cache if no user was loaded */
if (loaded == 0)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Service %s: failed to load any user "
"information. Authentication will "
"probably fail as a result.",
service->name)));
MXS_ERROR("Service %s: failed to load any user "
"information. Authentication will "
"probably fail as a result.",
service->name);
} else {
/* update cached data */
blr_save_dbusers(router);
@ -1936,12 +1875,11 @@ int mkdir_rval = 0;
if (mkdir_rval == -1)
{
char err_msg[STRERROR_BUFLEN];
skygw_log_write(LOGFILE_ERROR,
"Error : Service %s, Failed to create directory '%s': [%d] %s",
service->name,
path,
errno,
strerror_r(errno, err_msg, sizeof(err_msg)));
MXS_ERROR("Service %s, Failed to create directory '%s': [%d] %s",
service->name,
path,
errno,
strerror_r(errno, err_msg, sizeof(err_msg)));
return -1;
}
@ -1999,9 +1937,7 @@ static int blr_check_binlog(ROUTER_INSTANCE *router) {
n = blr_read_events_all_events(router, 0, 0);
LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG,
"blr_read_events_all_events() ret = %i\n", n)));
MXS_DEBUG("blr_read_events_all_events() ret = %i\n", n);
if (n != 0) {
char msg_err[BINLOG_ERROR_MSG_LEN + 1] = "";
@ -2017,11 +1953,9 @@ static int blr_check_binlog(ROUTER_INSTANCE *router) {
/* set last_safe_pos */
router->last_safe_pos = router->binlog_position;
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error found in binlog file %s. Safe starting pos is %lu",
router->binlog_name,
router->binlog_position)));
MXS_ERROR("Error found in binlog file %s. Safe starting pos is %lu",
router->binlog_name,
router->binlog_position);
return 0;
} else {