From 47ac20adeab5f0dd1217bdca38778f02f3359841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 22 Dec 2016 11:06:34 +0200 Subject: [PATCH] Refer to sessions by ID instead of memory address Using the unique ID for the session is easier to use than an address. This also allows the removal of all pointer values from the maxadmin output which is never useful to the end user. --- server/core/dcb.c | 7 +- server/core/service.c | 26 +---- server/core/session.c | 7 +- server/modules/routing/debugcli/debugcmd.c | 121 +++++++++------------ 4 files changed, 64 insertions(+), 97 deletions(-) diff --git a/server/core/dcb.c b/server/core/dcb.c index 8ba745b1f..44663f1b1 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -2063,7 +2063,12 @@ dprintDCB(DCB *pdcb, DCB *dcb) dcb_printf(pdcb, "\tProtocol: %s\n", dcb->protoname); } - dcb_printf(pdcb, "\tOwning Session: %p\n", dcb->session); + + if (dcb->session && dcb->session->state != SESSION_STATE_DUMMY) + { + dcb_printf(pdcb, "\tOwning Session: %lu\n", dcb->session->ses_id); + } + if (dcb->writeq) { dcb_printf(pdcb, "\tQueued write data: %d\n", gwbuf_length(dcb->writeq)); diff --git a/server/core/service.c b/server/core/service.c index 4dafcb6f1..3c0dd54ca 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -1306,10 +1306,9 @@ printService(SERVICE *service) char time_buf[30]; int i; - printf("Service %p\n", (void *)service); + printf("\tService: %s\n", service->name); - printf("\tRouter: %s (%p)\n", - service->routerModule, (void *)service->router); + printf("\tRouter: %s\n", service->routerModule); printf("\tStarted: %s", asctime_r(localtime_r(&service->stats.started, &result), time_buf)); printf("\tBackend databases\n"); @@ -1329,13 +1328,6 @@ printService(SERVICE *service) printf("\n"); } - SERV_LISTENER *port = service->ports; - while (port) - { - printf("\tUsers data: %p\n", (void *)port->users); - port = port->next; - } - printf("\tTotal connections: %d\n", service->stats.n_sessions); printf("\tCurrently connected: %d\n", service->stats.n_current); } @@ -1395,11 +1387,8 @@ void dprintService(DCB *dcb, SERVICE *service) char timebuf[30]; int i; - dcb_printf(dcb, "Service %p\n", service); - dcb_printf(dcb, "\tService: %s\n", - service->name); - dcb_printf(dcb, "\tRouter: %s (%p)\n", - service->routerModule, service->router); + dcb_printf(dcb, "\tService: %s\n", service->name); + dcb_printf(dcb, "\tRouter: %s\n", service->routerModule); switch (service->state) { case SERVICE_STATE_STARTED: @@ -1450,13 +1439,6 @@ void dprintService(DCB *dcb, SERVICE *service) service->weightby); } - SERV_LISTENER *port = service->ports; - while (port) - { - dcb_printf(dcb, "\tUsers data: %p\n", port->users); - port = port->next; - } - dcb_printf(dcb, "\tTotal connections: %d\n", service->stats.n_sessions); dcb_printf(dcb, "\tCurrently connected: %d\n", diff --git a/server/core/session.c b/server/core/session.c index 5d47889fd..bdcafa225 100644 --- a/server/core/session.c +++ b/server/core/session.c @@ -506,10 +506,9 @@ dprintSession(DCB *dcb, SESSION *print_session) char buf[30]; int i; - dcb_printf(dcb, "Session %lu (%p)\n", print_session->ses_id, print_session); + dcb_printf(dcb, "Session %lu\n", print_session->ses_id); dcb_printf(dcb, "\tState: %s\n", session_state(print_session->state)); - dcb_printf(dcb, "\tService: %s (%p)\n", print_session->service->name, print_session->service); - dcb_printf(dcb, "\tClient DCB: %p\n", print_session->client_dcb); + dcb_printf(dcb, "\tService: %s\n", print_session->service->name); if (print_session->client_dcb && print_session->client_dcb->remote) { @@ -547,7 +546,7 @@ bool dListSessions_cb(DCB *dcb, void *data) { DCB *out_dcb = (DCB*)data; SESSION *session = dcb->session; - dcb_printf(out_dcb, "%-16p | %-15s | %-14s | %s\n", session, + dcb_printf(out_dcb, "%-16lu | %-15s | %-14s | %s\n", session->ses_id, session->client_dcb && session->client_dcb->remote ? session->client_dcb->remote : "", session->service && session->service->name ? diff --git a/server/modules/routing/debugcli/debugcmd.c b/server/modules/routing/debugcli/debugcmd.c index 41df66fe3..984df36ac 100644 --- a/server/modules/routing/debugcli/debugcmd.c +++ b/server/modules/routing/debugcli/debugcmd.c @@ -143,17 +143,11 @@ struct subcommand showoptions[] = "Show all descriptor control blocks (network connections)", {0} }, - { - "dcb", 1, 1, dprintDCB, - "Show a DCB", - "Show a single descriptor control block e.g. show dcb 0x493340", - {ARG_TYPE_DCB, 0, 0} - }, { "dbusers", 1, 1, dcb_usersPrint, "Show user statistics", "Show statistics and user names for a service's user table.\n" - "\t\tExample : show dbusers |", + "\t\tExample : show dbusers ", {ARG_TYPE_SERVICE, 0, 0} }, { @@ -219,7 +213,7 @@ struct subcommand showoptions[] = { "persistent", 1, 1, dprintPersistentDCBs, "Show persistent connection pool", - "Show persistent pool for a server, e.g. show persistent dbnode1. ", + "Show persistent pool for a server, e.g. show persistent dbnode1", {ARG_TYPE_SERVER, 0, 0} }, { @@ -255,7 +249,7 @@ struct subcommand showoptions[] = { "session", 1, 1, dprintSession, "Show session details", - "Show a single session in MaxScale, e.g. show session 0x284830", + "Show a single session in MaxScale, e.g. show session 5", {ARG_TYPE_SESSION, 0, 0} }, { @@ -1507,7 +1501,6 @@ static struct { NULL, NULL } }; - /** * Convert a string argument to a numeric, observing prefixes * for number bases, e.g. 0x for hex, 0 for octal @@ -1518,83 +1511,66 @@ static struct * @return The argument as a long integer */ static unsigned long -convert_arg(int mode, char *arg, int arg_type) +convert_arg(char *arg, int arg_type) { - unsigned long rval; - SERVICE *service; + unsigned long rval; switch (arg_type) { case ARG_TYPE_ADDRESS: - return (unsigned long)strtol(arg, NULL, 0); + rval = (unsigned long)strtol(arg, NULL, 0); + break; + case ARG_TYPE_STRING: - return (unsigned long)arg; + rval = (unsigned long)arg; + break; + case ARG_TYPE_SERVICE: - if (mode == CLIM_USER || (rval = (unsigned long)strtol(arg, NULL, 0)) == 0) - { - rval = (unsigned long)service_find(arg); - } - return rval; + rval = (unsigned long)service_find(arg); + break; + case ARG_TYPE_SERVER: - if (mode == CLIM_USER || (rval = (unsigned long)strtol(arg, NULL, 0)) == 0) - { - rval = (unsigned long)server_find_by_unique_name(arg); - } - return rval; - case ARG_TYPE_DBUSERS: - if (mode == CLIM_USER || (rval = (unsigned long)strtol(arg, NULL, 0)) == 0) - { - service = service_find(arg); - if (service) - { - return (unsigned long)(service->ports->users); - } - else - { - return 0; - } - } - return rval; - case ARG_TYPE_DCB: - rval = (unsigned long)strtol(arg, NULL, 0); - if (mode == CLIM_USER && dcb_isvalid((DCB *)rval) == 0) - { - rval = 0; - } - return rval; + rval = (unsigned long)server_find_by_unique_name(arg); + break; + case ARG_TYPE_SESSION: - rval = (unsigned long)strtol(arg, NULL, 0); - if (mode == CLIM_USER && session_isvalid((SESSION *)rval) == 0) - { - rval = 0; - } - return rval; + rval = (unsigned long)session_get_by_id(strtol(arg, NULL, 0)); + break; + case ARG_TYPE_MONITOR: - if (mode == CLIM_USER || (rval = (unsigned long)strtol(arg, NULL, 0)) == 0) - { - rval = (unsigned long)monitor_find(arg); - } - return rval; + rval = (unsigned long)monitor_find(arg); + break; + case ARG_TYPE_FILTER: - if (mode == CLIM_USER || (rval = (unsigned long)strtol(arg, NULL, 0)) == 0) - { - rval = (unsigned long)filter_find(arg); - } - return rval; + rval = (unsigned long)filter_find(arg); + break; + case ARG_TYPE_NUMERIC: - { - int i; - for (i = 0; arg[i]; i++) + + for (int i = 0; arg[i]; i++) { - if (arg[i] < '0' || arg[i] > '9') + if (isdigit(arg[i])) { - return 0; + break; } } - return atoi(arg); - } + rval = atoi(arg); + } + + return rval; +} + +static void free_arg(int arg_type, void *value) +{ + switch (arg_type) + { + case ARG_TYPE_SESSION: + session_put_ref(value); + break; + + default: + break; } - return 0; } static SPINLOCK debugcmd_lock = SPINLOCK_INIT; @@ -1858,6 +1834,11 @@ execute_cmd(CLI_SESSION *cli) break; } } + + for (int k = 0; k < cmds[i].options[j].argc_max && k < argc; k++) + { + free_arg(cmds[i].options[j].arg_types[k], (void*)arg_list[k]); + } } } }