Hopefully final tidy up.

This commit is contained in:
counterpoint
2015-06-23 14:58:53 +01:00
parent 0c98a318dd
commit 09fdb0a2c2
13 changed files with 87 additions and 68 deletions

View File

@ -41,9 +41,9 @@
* 30/10/14 Massimiliano Pinto Added disable_master_failback parameter
* 07/11/14 Massimiliano Pinto Addition of monitor timeouts for connect/read/write
* 20/02/15 Markus Mäkelä Added connection_timeout parameter for services
* 05/03/15 Massimiliano Pinto Added notification_feedback support
* 05/03/15 Massimiliano Pinto Added notification_feedback support
* 20/04/15 Guillaume Lefranc Added available_when_donor parameter
* 22/04/15 Martin Brampton Added disable_master_role_setting parameter
* 22/04/15 Martin Brampton Added disable_master_role_setting parameter
*
* @endverbatim
*/

View File

@ -639,22 +639,9 @@ char *user;
"%lu [dcb_connect] Failed to link to session, the "
"session has been removed.\n",
pthread_self())));
dcb_final_free(dcb);
dcb_close(dcb);
return NULL;
}
/*
dcb->dcb_server_status = server->status;
dcb->state = DCB_STATE_ALLOC;
if (poll_add_dcb(dcb))
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"%lu [dcb_connect] Failed to add DCB %p to polling.\n",
pthread_self(), dcb)));
dcb_final_free(dcb);
return NULL;
}
*/
LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG,
"%lu [dcb_connect] Reusing a persistent connection, dcb %p\n", pthread_self(), dcb)));
@ -663,10 +650,10 @@ char *user;
}
else
{
LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG,
"%lu [dcb_connect] Failed to find a reusable persistent connection.\n",
pthread_self())));
LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG,
"%lu [dcb_connect] Failed to find a reusable persistent connection.\n",
pthread_self())));
}
}
@ -745,7 +732,7 @@ char *user;
/** Copy status field to DCB */
dcb->dcb_server_status = server->status;
ss_debug(dcb->dcb_port = server->port;)
dcb->dcb_port = server->port;
/**
* backend_dcb is connected to backend server, and once backend_dcb
@ -760,9 +747,9 @@ char *user;
rc = poll_add_dcb(dcb);
if (rc == DCBFD_CLOSED) {
dcb_set_state(dcb, DCB_STATE_DISCONNECTED, NULL);
dcb_final_free(dcb);
return NULL;
dcb_set_state(dcb, DCB_STATE_DISCONNECTED, NULL);
dcb_final_free(dcb);
return NULL;
}
/**
* The dcb will be addded into poll set by dcb->func.connect
@ -2025,6 +2012,7 @@ dcb_close(DCB *dcb)
* Add DCB to persistent pool if it qualifies, close otherwise
*
* @param dcb The DCB to go to persistent pool or be closed
* @return bool - whether the DCB was added to the pool
*
*/
static bool
@ -2114,7 +2102,9 @@ printDCB(DCB *dcb)
if (dcb->remote)
printf("\tConnected to: %s\n", dcb->remote);
if (dcb->user)
printf("\tUsername to: %s\n", dcb->user);
printf("\tUsername: %s\n", dcb->user);
if (dcb->protoname)
printf("\tProtocol: %s\n", dcb->protoname);
if (dcb->writeq)
printf("\tQueued write data: %d\n",gwbuf_length(dcb->writeq));
char *statusname = server_status(dcb->server);
@ -2196,6 +2186,9 @@ dprintOneDCB(DCB *pdcb, DCB *dcb)
if (dcb->user)
dcb_printf(pdcb, "\tUsername: %s\n",
dcb->user);
if (dcb->protoname)
dcb_printf(pdcb, "\tProtocol: %s\n",
dcb->protoname);
if (dcb->writeq)
dcb_printf(pdcb, "\tQueued write data: %d\n",
gwbuf_length(dcb->writeq));
@ -2225,7 +2218,7 @@ dprintOneDCB(DCB *pdcb, DCB *dcb)
char buff[20];
struct tm * timeinfo;
timeinfo = localtime (&dcb->persistentstart);
strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo);
strftime(buff, sizeof(buff), "%b %d %H:%M:%S", timeinfo);
dcb_printf(pdcb, "\t\tAdded to persistent pool: %s", buff);
}
}
@ -2256,7 +2249,7 @@ DCB *dcb;
}
/**
* Diagnotic routine to print DCB data in a tabular form.
* Diagnostic routine to print DCB data in a tabular form.
*
* @param pdcb DCB to print results to
*/
@ -2339,6 +2332,9 @@ dprintDCB(DCB *pdcb, DCB *dcb)
if (dcb->user)
dcb_printf(pdcb, "\tUsername: %s\n",
dcb->user);
if (dcb->protoname)
dcb_printf(pdcb, "\tProtocol: %s\n",
dcb->protoname);
dcb_printf(pdcb, "\tOwning Session: %p\n", dcb->session);
if (dcb->writeq)
dcb_printf(pdcb, "\tQueued write data: %d\n", gwbuf_length(dcb->writeq));
@ -2396,7 +2392,7 @@ dprintDCB(DCB *pdcb, DCB *dcb)
char buff[20];
struct tm * timeinfo;
timeinfo = localtime (&dcb->persistentstart);
strftime(buff, sizeof(buff), "%b %d %H:%M", timeinfo);
strftime(buff, sizeof(buff), "%b %d %H:%M:%S", timeinfo);
dcb_printf(pdcb, "\t\tAdded to persistent pool: %s", buff);
}
}
@ -3069,6 +3065,9 @@ dcb_null_auth(DCB *dcb, SERVER *server, SESSION *session, GWBUF *buf)
* Check persistent pool for expiry or excess size and count
*
* @param dcb The DCB being closed.
* @param cleanall Boolean, if true the whole pool is cleared for the
* server related to the given DCB
* @return A count of the DCBs remaining in the pool
*/
int
dcb_persistent_clean_count(DCB *dcb, bool cleanall)
@ -3083,15 +3082,16 @@ dcb_persistent_clean_count(DCB *dcb, bool cleanall)
CHK_SERVER(server);
spinlock_acquire(&server->persistlock);
persistentdcb = server->persistent;
persistentdcb = server->persistent;
while (persistentdcb) {
CHK_DCB(persistentdcb);
nextdcb = persistentdcb->nextpersistent;
nextdcb = persistentdcb->nextpersistent;
if (cleanall
|| persistentdcb-> dcb_errhandle_called
|| count >= server->persistpoolmax
|| time(NULL) - persistentdcb->persistentstart > server->persistmaxtime)
|| persistentdcb-> dcb_errhandle_called
|| count >= server->persistpoolmax
|| (time(NULL) - persistentdcb->persistentstart) > server->persistmaxtime)
{
/* Remove from persistent pool */
if (previousdcb) {
previousdcb->nextpersistent = nextdcb;
}
@ -3099,6 +3099,7 @@ dcb_persistent_clean_count(DCB *dcb, bool cleanall)
{
server->persistent = nextdcb;
}
/* Add removed DCBs to disposal list for processing outside spinlock */
persistentdcb->nextpersistent = disposals;
disposals = persistentdcb;
atomic_add(&server->stats.n_persistent, -1);

View File

@ -141,8 +141,9 @@ SERVER *server;
/**
* Get a DCB from the persistent connection pool, if possible
*
* @param server The server to set the name on
* @param user The name of the user needing the connection
* @param server The server to set the name on
* @param user The name of the user needing the connection
* @param protocol The name of the protocol needed for the connection
*/
DCB *
server_get_persistent(SERVER *server, char *user, const char *protocol)
@ -154,7 +155,12 @@ server_get_persistent(SERVER *server, char *user, const char *protocol)
spinlock_acquire(&server->persistlock);
dcb = server->persistent;
while (dcb) {
if (dcb->user && dcb->protoname && !dcb-> dcb_errhandle_called && 0 == strcmp(dcb->user, user) && 0 == strcmp(dcb->protoname, protocol))
if (dcb->user
&& dcb->protoname
&& !dcb-> dcb_errhandle_called
&& !(dcb->flags & DCBF_HUNG)
&& 0 == strcmp(dcb->user, user)
&& 0 == strcmp(dcb->protoname, protocol))
{
if (NULL == previous)
{
@ -171,21 +177,22 @@ server_get_persistent(SERVER *server, char *user, const char *protocol)
atomic_add(&server->stats.n_current, 1);
return dcb;
}
else
{
LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG,
"%lu [server_get_persistent] Rejected dcb "
"%p from pool, user %s looking for %s, protocol %s "
"looking for %s, error handle called %s.",
pthread_self(),
dcb,
dcb->user ? dcb->user : "NULL",
user,
dcb->protoname ? dcb->protoname : "NULL",
protocol,
dcb-> dcb_errhandle_called ? "true" : "false")));
}
else
{
LOGIF(LD, (skygw_log_write_flush(
LOGFILE_DEBUG,
"%lu [server_get_persistent] Rejected dcb "
"%p from pool, user %s looking for %s, protocol %s "
"looking for %s, hung flag %s, error handle called %s.",
pthread_self(),
dcb,
dcb->user ? dcb->user : "NULL",
user,
dcb->protoname ? dcb->protoname : "NULL",
protocol,
(dcb->flags & DCBF_HUNG) ? "true" : "false",
dcb-> dcb_errhandle_called ? "true" : "false")));
}
previous = dcb;
dcb = dcb->nextpersistent;
}