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

@ -639,22 +639,9 @@ char *user;
"%lu [dcb_connect] Failed to link to session, the " "%lu [dcb_connect] Failed to link to session, the "
"session has been removed.\n", "session has been removed.\n",
pthread_self()))); pthread_self())));
dcb_final_free(dcb); dcb_close(dcb);
return NULL; 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( LOGIF(LD, (skygw_log_write(
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [dcb_connect] Reusing a persistent connection, dcb %p\n", pthread_self(), dcb))); "%lu [dcb_connect] Reusing a persistent connection, dcb %p\n", pthread_self(), dcb)));
@ -745,7 +732,7 @@ char *user;
/** Copy status field to DCB */ /** Copy status field to DCB */
dcb->dcb_server_status = server->status; 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 * backend_dcb is connected to backend server, and once backend_dcb
@ -2025,6 +2012,7 @@ dcb_close(DCB *dcb)
* Add DCB to persistent pool if it qualifies, close otherwise * Add DCB to persistent pool if it qualifies, close otherwise
* *
* @param dcb The DCB to go to persistent pool or be closed * @param dcb The DCB to go to persistent pool or be closed
* @return bool - whether the DCB was added to the pool
* *
*/ */
static bool static bool
@ -2114,7 +2102,9 @@ printDCB(DCB *dcb)
if (dcb->remote) if (dcb->remote)
printf("\tConnected to: %s\n", dcb->remote); printf("\tConnected to: %s\n", dcb->remote);
if (dcb->user) 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) if (dcb->writeq)
printf("\tQueued write data: %d\n",gwbuf_length(dcb->writeq)); printf("\tQueued write data: %d\n",gwbuf_length(dcb->writeq));
char *statusname = server_status(dcb->server); char *statusname = server_status(dcb->server);
@ -2196,6 +2186,9 @@ dprintOneDCB(DCB *pdcb, DCB *dcb)
if (dcb->user) if (dcb->user)
dcb_printf(pdcb, "\tUsername: %s\n", dcb_printf(pdcb, "\tUsername: %s\n",
dcb->user); dcb->user);
if (dcb->protoname)
dcb_printf(pdcb, "\tProtocol: %s\n",
dcb->protoname);
if (dcb->writeq) if (dcb->writeq)
dcb_printf(pdcb, "\tQueued write data: %d\n", dcb_printf(pdcb, "\tQueued write data: %d\n",
gwbuf_length(dcb->writeq)); gwbuf_length(dcb->writeq));
@ -2225,7 +2218,7 @@ dprintOneDCB(DCB *pdcb, DCB *dcb)
char buff[20]; char buff[20];
struct tm * timeinfo; struct tm * timeinfo;
timeinfo = localtime (&dcb->persistentstart); 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); 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 * @param pdcb DCB to print results to
*/ */
@ -2339,6 +2332,9 @@ dprintDCB(DCB *pdcb, DCB *dcb)
if (dcb->user) if (dcb->user)
dcb_printf(pdcb, "\tUsername: %s\n", dcb_printf(pdcb, "\tUsername: %s\n",
dcb->user); dcb->user);
if (dcb->protoname)
dcb_printf(pdcb, "\tProtocol: %s\n",
dcb->protoname);
dcb_printf(pdcb, "\tOwning Session: %p\n", dcb->session); dcb_printf(pdcb, "\tOwning Session: %p\n", dcb->session);
if (dcb->writeq) if (dcb->writeq)
dcb_printf(pdcb, "\tQueued write data: %d\n", gwbuf_length(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]; char buff[20];
struct tm * timeinfo; struct tm * timeinfo;
timeinfo = localtime (&dcb->persistentstart); 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); 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 * Check persistent pool for expiry or excess size and count
* *
* @param dcb The DCB being closed. * @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 int
dcb_persistent_clean_count(DCB *dcb, bool cleanall) dcb_persistent_clean_count(DCB *dcb, bool cleanall)
@ -3090,8 +3089,9 @@ dcb_persistent_clean_count(DCB *dcb, bool cleanall)
if (cleanall if (cleanall
|| persistentdcb-> dcb_errhandle_called || persistentdcb-> dcb_errhandle_called
|| count >= server->persistpoolmax || count >= server->persistpoolmax
|| time(NULL) - persistentdcb->persistentstart > server->persistmaxtime) || (time(NULL) - persistentdcb->persistentstart) > server->persistmaxtime)
{ {
/* Remove from persistent pool */
if (previousdcb) { if (previousdcb) {
previousdcb->nextpersistent = nextdcb; previousdcb->nextpersistent = nextdcb;
} }
@ -3099,6 +3099,7 @@ dcb_persistent_clean_count(DCB *dcb, bool cleanall)
{ {
server->persistent = nextdcb; server->persistent = nextdcb;
} }
/* Add removed DCBs to disposal list for processing outside spinlock */
persistentdcb->nextpersistent = disposals; persistentdcb->nextpersistent = disposals;
disposals = persistentdcb; disposals = persistentdcb;
atomic_add(&server->stats.n_persistent, -1); atomic_add(&server->stats.n_persistent, -1);

View File

@ -143,6 +143,7 @@ SERVER *server;
* *
* @param server The server to set the name on * @param server The server to set the name on
* @param user The name of the user needing the connection * @param user The name of the user needing the connection
* @param protocol The name of the protocol needed for the connection
*/ */
DCB * DCB *
server_get_persistent(SERVER *server, char *user, const char *protocol) 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); spinlock_acquire(&server->persistlock);
dcb = server->persistent; dcb = server->persistent;
while (dcb) { 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) if (NULL == previous)
{ {
@ -177,13 +183,14 @@ server_get_persistent(SERVER *server, char *user, const char *protocol)
LOGFILE_DEBUG, LOGFILE_DEBUG,
"%lu [server_get_persistent] Rejected dcb " "%lu [server_get_persistent] Rejected dcb "
"%p from pool, user %s looking for %s, protocol %s " "%p from pool, user %s looking for %s, protocol %s "
"looking for %s, error handle called %s.", "looking for %s, hung flag %s, error handle called %s.",
pthread_self(), pthread_self(),
dcb, dcb,
dcb->user ? dcb->user : "NULL", dcb->user ? dcb->user : "NULL",
user, user,
dcb->protoname ? dcb->protoname : "NULL", dcb->protoname ? dcb->protoname : "NULL",
protocol, protocol,
(dcb->flags & DCBF_HUNG) ? "true" : "false",
dcb-> dcb_errhandle_called ? "true" : "false"))); dcb-> dcb_errhandle_called ? "true" : "false")));
} }
previous = dcb; previous = dcb;

View File

@ -26,6 +26,7 @@
* *
* Date Who Description * Date Who Description
* 10/06/13 Mark Riddoch Initial implementation * 10/06/13 Mark Riddoch Initial implementation
* 23/06/15 Martin Brampton Alternative for C++
* *
* @endverbatim * @endverbatim
*/ */

View File

@ -34,6 +34,7 @@
#include <pthread.h> #include <pthread.h>
#include <memlog.h> #include <memlog.h>
#include <zlib.h>
#define BINLOG_FNAMELEN 16 #define BINLOG_FNAMELEN 16
#define BLR_PROTOCOL "MySQLBackend" #define BLR_PROTOCOL "MySQLBackend"

View File

@ -126,6 +126,7 @@ startMonitor(void *arg,void* opt)
handle->shutdown = 0; handle->shutdown = 0;
handle->id = MONITOR_DEFAULT_ID; handle->id = MONITOR_DEFAULT_ID;
handle->master = NULL; handle->master = NULL;
handle->script = NULL;
memset(handle->events,false,sizeof(handle->events)); memset(handle->events,false,sizeof(handle->events));
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
} }

View File

@ -43,6 +43,7 @@
* 27/09/2013 Massimiliano Pinto Changed in gw_read_backend_event the check for dcb_read(), now is if rc < 0 * 27/09/2013 Massimiliano Pinto Changed in gw_read_backend_event the check for dcb_read(), now is if rc < 0
* 24/10/2014 Massimiliano Pinto Added Mysql user@host @db authentication support * 24/10/2014 Massimiliano Pinto Added Mysql user@host @db authentication support
* 10/11/2014 Massimiliano Pinto Client charset is passed to backend * 10/11/2014 Massimiliano Pinto Client charset is passed to backend
* 19/06/2015 Martin Brampton Persistent connection handling
* *
*/ */
#include <modinfo.h> #include <modinfo.h>

View File

@ -38,6 +38,7 @@
* 13/10/2014 Massimiliano Pinto Added: dbname authentication check * 13/10/2014 Massimiliano Pinto Added: dbname authentication check
* 10/11/2014 Massimiliano Pinto Added: client charset added to protocol struct * 10/11/2014 Massimiliano Pinto Added: client charset added to protocol struct
* 29/05/2015 Markus Makela Added SSL support * 29/05/2015 Markus Makela Added SSL support
* 11/06/2015 Martin Brampton COM_QUIT suppressed for persistent connections
*/ */
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>

View File

@ -210,9 +210,8 @@ int fd;
close(router->binlog_fd); close(router->binlog_fd);
spinlock_acquire(&router->binlog_lock); spinlock_acquire(&router->binlog_lock);
strncpy(router->binlog_name, file,BINLOG_FNAMELEN); strncpy(router->binlog_name, file,BINLOG_FNAMELEN);
blr_file_add_magic(router, fd);
spinlock_release(&router->binlog_lock);
router->binlog_fd = fd; router->binlog_fd = fd;
spinlock_release(&router->binlog_lock);
return 1; return 1;
} }
@ -255,11 +254,12 @@ int fd;
"%s: binlog file %s has an invalid length %d.", "%s: binlog file %s has an invalid length %d.",
router->service->name, path, router->binlog_position))); router->service->name, path, router->binlog_position)));
close(fd); close(fd);
spinlock_release(&router->binlog_lock);
return; return;
} }
} }
spinlock_release(&router->binlog_lock);
router->binlog_fd = fd; router->binlog_fd = fd;
spinlock_release(&router->binlog_lock);
} }
/** /**

View File

@ -1693,6 +1693,9 @@ uint32_t chksum;
binlognamelen = strlen(slave->binlogfile); binlognamelen = strlen(slave->binlogfile);
len = 19 + 8 + 4 + binlognamelen; len = 19 + 8 + 4 + binlognamelen;
/* no slave crc, remove 4 bytes */
if (slave->nocrc)
len -= 4;
// Build a fake rotate event // Build a fake rotate event
resp = gwbuf_alloc(len + 5); resp = gwbuf_alloc(len + 5);
@ -1711,6 +1714,7 @@ uint32_t chksum;
memcpy(ptr, slave->binlogfile, binlognamelen); memcpy(ptr, slave->binlogfile, binlognamelen);
ptr += binlognamelen; ptr += binlognamelen;
if (!slave->nocrc) {
/* /*
* Now add the CRC to the fake binlog rotate event. * Now add the CRC to the fake binlog rotate event.
* *
@ -1722,6 +1726,7 @@ uint32_t chksum;
chksum = crc32(0L, NULL, 0); chksum = crc32(0L, NULL, 0);
chksum = crc32(chksum, GWBUF_DATA(resp) + 5, hdr.event_size - 4); chksum = crc32(chksum, GWBUF_DATA(resp) + 5, hdr.event_size - 4);
encode_value(ptr, chksum, 32); encode_value(ptr, chksum, 32);
}
slave->dcb->func.write(slave->dcb, resp); slave->dcb->func.write(slave->dcb, resp);
return 1; return 1;

View File

@ -67,6 +67,7 @@
* 06/03/2014 Massimiliano Pinto Server connection counter is now updated in closeSession * 06/03/2014 Massimiliano Pinto Server connection counter is now updated in closeSession
* 24/06/2014 Massimiliano Pinto New rules for selecting the Master server * 24/06/2014 Massimiliano Pinto New rules for selecting the Master server
* 27/06/2014 Mark Riddoch Addition of server weighting * 27/06/2014 Mark Riddoch Addition of server weighting
* 11/06/2015 Martin Brampton Remove decrement n_current (moved to dcb.c)
* *
* @endverbatim * @endverbatim
*/ */

View File

@ -1,2 +1,2 @@
add_library(utils skygw_utils.cc) add_library(utils skygw_utils.cc ../server/core/atomic.c)
target_link_libraries(utils stdc++) target_link_libraries(utils stdc++)