Fixed bug on candidate selection. I misinterpreted count and n_connections variables. Thus, renamed count as current_connection_count to make it more understandable.

This commit is contained in:
Jan Lindström
2013-08-13 12:12:19 +03:00
parent c1c8bf9fc5
commit 2e11a26f41
2 changed files with 13 additions and 22 deletions

View File

@ -37,8 +37,8 @@
* that is required for each of the backend servers. * that is required for each of the backend servers.
*/ */
typedef struct backend { typedef struct backend {
SERVER *server; /**< The server itself */ SERVER *server; /**< The server itself */
int count; /**< Number of connections to the server */ int current_connection_count; /**< Number of connections to the server */
} BACKEND; } BACKEND;
/** /**

View File

@ -186,7 +186,7 @@ int i, n;
return NULL; return NULL;
} }
inst->servers[n]->server = server; inst->servers[n]->server = server;
inst->servers[n]->count = 0; inst->servers[n]->current_connection_count = 0;
n++; n++;
} }
inst->servers[n] = NULL; inst->servers[n] = NULL;
@ -274,7 +274,7 @@ int i;
"Examine server in port %d with %d connections. Status is %d, " "Examine server in port %d with %d connections. Status is %d, "
"inst->bitvalue is %d", "inst->bitvalue is %d",
inst->servers[i]->server->port, inst->servers[i]->server->port,
inst->servers[i]->count, inst->servers[i]->current_connection_count,
inst->servers[i]->server->status, inst->servers[i]->server->status,
inst->bitmask); inst->bitmask);
} }
@ -285,14 +285,13 @@ int i;
our initial candidate server */ our initial candidate server */
if (candidate == NULL) { if (candidate == NULL) {
candidate = inst->servers[i]; candidate = inst->servers[i];
} else if (inst->servers[i]->server->stats.n_connections } else if (inst->servers[i]->current_connection_count < candidate->current_connection_count) {
< candidate->server->stats.n_connections) {
/* This running server has fewer /* This running server has fewer
connections, set it as a new candidate */ connections, set it as a new candidate */
candidate = inst->servers[i]; candidate = inst->servers[i];
} else if (inst->servers[i]->server->stats.n_connections } else if (inst->servers[i]->current_connection_count == candidate->current_connection_count &&
== candidate->server->stats.n_connections && inst->servers[i]->server->stats.n_connections
inst->servers[i]->count < candidate->count) { < candidate->server->stats.n_connections) {
/* This running server has the same number /* This running server has the same number
of connections currently as the candidate of connections currently as the candidate
but has had fewer connections over time but has had fewer connections over time
@ -302,15 +301,6 @@ int i;
} }
} }
if (candidate) {
skygw_log_write(
LOGFILE_TRACE,
"Selected server in port %d to as candidate. "
"Connections : %d\n",
candidate->server->port,
candidate->count);
}
/* no candidate server here, clean and return NULL */ /* no candidate server here, clean and return NULL */
if (!candidate) { if (!candidate) {
free(client); free(client);
@ -321,15 +311,16 @@ int i;
* We now have the server with the least connections. * We now have the server with the least connections.
* Bump the connection count for this server * Bump the connection count for this server
*/ */
atomic_add(&candidate->count, 1); atomic_add(&candidate->current_connection_count, 1);
client->backend = candidate; client->backend = candidate;
skygw_log_write( skygw_log_write(
LOGFILE_TRACE, LOGFILE_TRACE,
"Final selection is server in port %d. " "Final selection is server in port %d. "
"Connections : %d\n", "Connections : %d\n",
candidate->server->port, candidate->server->port,
candidate->count); candidate->current_connection_count);
/* /*
* Open a backend connection, putting the DCB for this * Open a backend connection, putting the DCB for this
* connection in the client->dcb * connection in the client->dcb
@ -338,7 +329,7 @@ int i;
if ((client->dcb = dcb_connect(candidate->server, session, if ((client->dcb = dcb_connect(candidate->server, session,
candidate->server->protocol)) == NULL) candidate->server->protocol)) == NULL)
{ {
atomic_add(&candidate->count, -1); atomic_add(&candidate->current_connection_count, -1);
free(client); free(client);
return NULL; return NULL;
} }
@ -370,7 +361,7 @@ CLIENT_SESSION *session = (CLIENT_SESSION *)router_session;
* Close the connection to the backend * Close the connection to the backend
*/ */
session->dcb->func.close(session->dcb); session->dcb->func.close(session->dcb);
atomic_add(&session->backend->count, -1); atomic_add(&session->backend->current_connection_count, -1);
atomic_add(&session->backend->server->stats.n_current, -1); atomic_add(&session->backend->server->stats.n_current, -1);
spinlock_acquire(&inst->lock); spinlock_acquire(&inst->lock);