From 351f52b8e15410a1ead2053d681a7518dcbb0e64 Mon Sep 17 00:00:00 2001 From: counterpoint Date: Wed, 27 May 2015 09:57:18 +0100 Subject: [PATCH] Add "show persistent {server}" --- client/maxadmin.c | 2 +- server/core/dcb.c | 65 ++++++++++++++++++++++++++++++- server/modules/routing/debugcmd.c | 5 +++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/client/maxadmin.c b/client/maxadmin.c index 8a4d7cb43..d0be6bd8a 100644 --- a/client/maxadmin.c +++ b/client/maxadmin.c @@ -199,7 +199,7 @@ char c; for (i = optind +1; i < argc; i++) { strcat(cmd, " "); - /* Arguments after the seconf are quoted to allow for names + /* Arguments after the second are quoted to allow for names * that contain white space */ if (i - optind > 1) diff --git a/server/core/dcb.c b/server/core/dcb.c index 9c2eed2aa..fc4c2a3f2 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -642,7 +642,7 @@ char *user; { LOGIF(LD, (skygw_log_write( LOGFILE_DEBUG, - "%lu [dcb_connect] Looking for persistent connection DCB user %s protocol %s\n", user, protocol))); + "%lu [dcb_connect] Looking for persistent connection DCB user %s protocol %s\n", pthread_self(), user, protocol))); dcb = server_get_persistent(server, user, protocol); if (dcb) { @@ -662,7 +662,7 @@ char *user; dcb->dcb_server_status = server->status; LOGIF(LD, (skygw_log_write( LOGFILE_DEBUG, - "%lu [dcb_connect] Reusing a persistent connection, dcb %p\n", dcb))); + "%lu [dcb_connect] Reusing a persistent connection, dcb %p\n", pthread_self(), dcb))); return dcb; } } @@ -1474,6 +1474,67 @@ DCB *dcb; spinlock_release(&dcbspin); } +/** + * Diagnostic to print all DCBs in persistent pool for a server + * + * @param pdcb DCB to print results to + * @param server SERVER for which DCBs are to be printed + */ +void dprintPersistentDCBs(DCB *pdcb, SERVER *server) +{ +DCB *dcb; + + spinlock_acquire(&server->persistlock); +#if SPINLOCK_PROFILE + dcb_printf(pdcb, "DCB List Spinlock Statistics:\n"); + spinlock_stats(&dcbspin, spin_reporter, pdcb); + dcb_printf(pdcb, "Zombie Queue Lock Statistics:\n"); + spinlock_stats(&zombiespin, spin_reporter, pdcb); +#endif + dcb = server->persistent; + while (dcb) + { + dcb_printf(pdcb, "DCB: %p\n", (void *)dcb); + dcb_printf(pdcb, "\tDCB state: %s\n", + gw_dcb_state2string(dcb->state)); + if (dcb->session && dcb->session->service) + dcb_printf(pdcb, "\tService: %s\n", + dcb->session->service->name); + if (dcb->remote) + dcb_printf(pdcb, "\tConnected to: %s\n", + dcb->remote); + if (dcb->user) + dcb_printf(pdcb, "\tUsername: %s\n", + dcb->user); + if (dcb->writeq) + dcb_printf(pdcb, "\tQueued write data: %d\n", + gwbuf_length(dcb->writeq)); + char *statusname = server_status(dcb->server); + if (statusname) + { + dcb_printf(pdcb, "\tServer status: %s\n", statusname); + free(statusname); + } + char *rolename = dcb_role_name(dcb); + if (rolename) + { + dcb_printf(pdcb, "\tRole: %s\n", rolename); + free(rolename); + } + dcb_printf(pdcb, "\tStatistics:\n"); + dcb_printf(pdcb, "\t\tNo. of Reads: %d\n", dcb->stats.n_reads); + dcb_printf(pdcb, "\t\tNo. of Writes: %d\n", dcb->stats.n_writes); + dcb_printf(pdcb, "\t\tNo. of Buffered Writes: %d\n", dcb->stats.n_buffered); + dcb_printf(pdcb, "\t\tNo. of Accepts: %d\n", dcb->stats.n_accepts); + dcb_printf(pdcb, "\t\tNo. of High Water Events: %d\n", dcb->stats.n_high_water); + dcb_printf(pdcb, "\t\tNo. of Low Water Events: %d\n", dcb->stats.n_low_water); + if (dcb->flags & DCBF_CLONE) + dcb_printf(pdcb, "\t\tDCB is a clone.\n"); + dcb = dcb->nextpersistent; + } + spinlock_release(&server->persistlock); +} + /** * Diagnotic routine to print DCB data in a tabular form. * diff --git a/server/modules/routing/debugcmd.c b/server/modules/routing/debugcmd.c index d85f96422..1e4606da6 100644 --- a/server/modules/routing/debugcmd.c +++ b/server/modules/routing/debugcmd.c @@ -43,6 +43,7 @@ * 29/05/14 Mark Riddoch Add Filter support * 16/10/14 Mark Riddoch Add show eventq * 05/03/15 Massimiliano Pinto Added enable/disable feedback + * 27/05/15 Martin Brampton Add show persistent [server] * * @endverbatim */ @@ -154,6 +155,10 @@ struct subcommand showoptions[] = { "Show the monitors that are configured", "Show the monitors that are configured", {0, 0, 0} }, + { "persistent", 1, dprintPersistentDCBs, + "Show persistent pool for a named server, e.g. show persistent dbnode1", + "Show persistent pool for a server, e.g. show persistent 0x485390. The address may also be replaced with the server name from the configuration file", + {ARG_TYPE_SERVER, 0, 0} }, { "server", 1, dprintServer, "Show details for a named server, e.g. show server dbnode1", "Show details for a server, e.g. show server 0x485390. The address may also be repalced with the server name from the configuration file",