Merge branch 'develop' into MAX-309

Merge branch 'develop' into MAX-309
This commit is contained in:
MassimilianoPinto
2014-10-21 18:00:16 +02:00
4 changed files with 60 additions and 25 deletions

1
.gitignore vendored
View File

@ -30,6 +30,7 @@ depend.mk
*~ *~
*# *#
.#* .#*
._*
# Vi swap files # Vi swap files
.*.swp .*.swp

View File

@ -230,7 +230,6 @@ int add_mysql_users_with_host_ipv4(USERS *users, char *user, char *host, char *p
tmp = ret_ip+strlen(ret_ip)-1; tmp = ret_ip+strlen(ret_ip)-1;
/* start from Class C */ /* start from Class C */
while(tmp > ret_ip) { while(tmp > ret_ip) {
if (*tmp == '%') { if (*tmp == '%') {
/* set only the last IPv4 byte to 1 /* set only the last IPv4 byte to 1

View File

@ -65,6 +65,7 @@ MAXKEYS *keys;
struct stat secret_stats; struct stat secret_stats;
int fd; int fd;
int len; int len;
static int reported = 0;
home = getenv("MAXSCALE_HOME"); home = getenv("MAXSCALE_HOME");
@ -80,12 +81,16 @@ int len;
errno = 0; errno = 0;
if (eno == ENOENT) if (eno == ENOENT)
{ {
LOGIF(LM, (skygw_log_write( if (!reported)
{
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE, LOGFILE_MESSAGE,
"Encrypted password file %s can't be accessed " "Encrypted password file %s can't be accessed "
"(%s). Password encryption is not used.", "(%s). Password encryption is not used.",
secret_file, secret_file,
strerror(eno)))); strerror(eno))));
reported = 1;
}
} }
else else
{ {

View File

@ -849,7 +849,7 @@ static void* newSession(
free(client_rses); free(client_rses);
client_rses = NULL; client_rses = NULL;
goto return_rses; goto return_rses;
} }
/** Copy backend pointers to router session. */ /** Copy backend pointers to router session. */
client_rses->rses_master_ref = master_ref; client_rses->rses_master_ref = master_ref;
/* assert with master_host */ /* assert with master_host */
@ -1064,10 +1064,21 @@ static bool get_dcb(
/** get root master from available servers */ /** get root master from available servers */
master_bref = get_root_master_bref(rses); master_bref = get_root_master_bref(rses);
/**
* If master can't be found, session will be closed.
*/
if (master_bref == NULL)
{
succp = false;
goto return_succp;
}
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
master_host = get_root_master(backend_ref, rses->rses_nbackends); master_host = get_root_master(backend_ref, rses->rses_nbackends);
ss_dassert(master_bref->bref_backend == master_host); if (master_bref->bref_backend != master_host)
{
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE,
"Master has changed.")));
}
#endif #endif
if (name != NULL) /*< Choose backend by name from a hint */ if (name != NULL) /*< Choose backend by name from a hint */
{ {
@ -1714,6 +1725,7 @@ static int routeQuery(
querybuf = gwbuf_make_contiguous(querybuf); querybuf = gwbuf_make_contiguous(querybuf);
} }
/** Read stored master DCB pointer */
master_dcb = router_cli_ses->rses_master_ref->bref_dcb; master_dcb = router_cli_ses->rses_master_ref->bref_dcb;
CHK_DCB(master_dcb); CHK_DCB(master_dcb);
@ -2000,30 +2012,43 @@ static int routeQuery(
if (!succp && TARGET_IS_MASTER(route_target)) if (!succp && TARGET_IS_MASTER(route_target))
{ {
if (master_dcb == NULL) DCB* curr_master_dcb = NULL;
succp = get_dcb(&curr_master_dcb,
router_cli_ses,
BE_MASTER,
NULL,
MAX_RLAG_UNDEFINED);
if (succp && (master_dcb == NULL || master_dcb == curr_master_dcb))
{ {
succp = get_dcb(&master_dcb, atomic_add(&inst->stats.n_master, 1);
router_cli_ses, target_dcb = master_dcb;
BE_MASTER, }
NULL, else
MAX_RLAG_UNDEFINED); {
if (!succp) if (succp && master_dcb != curr_master_dcb)
{ {
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE, LOGIF(LT, (skygw_log_write(LOGFILE_TRACE,
"Was supposed to " "Was supposed to "
"route to master " "route to master "
"but couldn't find " "but master has "
"master in a " "changed.")));
"suitable state "
"failed.")));
} }
else
{
LOGIF(LT, (skygw_log_write(LOGFILE_TRACE,
"Was supposed to "
"route to master "
"but couldn't find "
"master in a "
"suitable state "
"failed.")));
}
succp = false;
ret = 0;
} }
else
{
succp = true;
}
atomic_add(&inst->stats.n_master, 1);
target_dcb = master_dcb;
} }
if (succp) /*< Have DCB of the target backend */ if (succp) /*< Have DCB of the target backend */
@ -2595,7 +2620,7 @@ static bool select_connect_backend_servers(
} }
/* get the root Master */ /* get the root Master */
master_host = get_root_master(backend_ref, router_nservers); master_host = get_root_master(backend_ref, router_nservers);
/** Master is already chosen and connected. This is slave failure case */ /** Master is already chosen and connected. This is slave failure case */
if (*p_master_ref != NULL && if (*p_master_ref != NULL &&
@ -2610,11 +2635,16 @@ static bool select_connect_backend_servers(
master_found = true; master_found = true;
master_connected = true; master_connected = true;
/* assert with master_host */
/**
* Ensure that *p_master_ref and master_host point to same backend
* and it has a master role.
*/
ss_dassert(master_host && ss_dassert(master_host &&
((*p_master_ref)->bref_backend->backend_server == ((*p_master_ref)->bref_backend->backend_server ==
master_host->backend_server) && master_host->backend_server) &&
SERVER_MASTER); (master_host->backend_server->status &
(SERVER_MASTER|SERVER_MAINT)) == SERVER_MASTER);
} }
/** New session or master failure case */ /** New session or master failure case */
else else