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.
This commit is contained in:
Markus Mäkelä
2016-12-22 11:06:34 +02:00
parent 2bdda586f7
commit 47ac20adea
4 changed files with 64 additions and 97 deletions

View File

@ -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));

View File

@ -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",

View File

@ -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 ?

View File

@ -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 <ptr of 'User's data' from services list>|<service name>",
"\t\tExample : show dbusers <service name>",
{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,84 +1511,67 @@ 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;
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;
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;
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;
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;
break;
case ARG_TYPE_NUMERIC:
for (int i = 0; arg[i]; i++)
{
int i;
for (i = 0; arg[i]; i++)
if (isdigit(arg[i]))
{
if (arg[i] < '0' || arg[i] > '9')
break;
}
}
rval = atoi(arg);
}
return rval;
}
static void free_arg(int arg_type, void *value)
{
return 0;
switch (arg_type)
{
case ARG_TYPE_SESSION:
session_put_ref(value);
break;
default:
break;
}
}
return atoi(arg);
}
}
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]);
}
}
}
}