diff --git a/core/dcb.c b/core/dcb.c index 150ee14a4..c9331da1c 100644 --- a/core/dcb.c +++ b/core/dcb.c @@ -82,6 +82,7 @@ DCB *rval; rval->next = NULL; rval->data = NULL; rval->protocol = NULL; + rval->session = NULL; memset(&rval->stats, 0, sizeof(DCBSTATS)); // Zero the statistics spinlock_acquire(dcbspin); diff --git a/core/depend.mk b/core/depend.mk index 7a660da19..2bb4bd23a 100644 --- a/core/depend.mk +++ b/core/depend.mk @@ -399,36 +399,46 @@ config.o: config.c /usr/include/stdio.h /usr/include/features.h \ /usr/include/bits/setjmp.h ../include/dcb.h ../include/buffer.h \ ../include/server.h ../include/users.h ../include/hashtable.h \ ../include/atomic.h -users.o: users.c /usr/include/stdlib.h /usr/include/features.h \ +users.o: users.c /usr/include/stdio.h /usr/include/features.h \ /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \ /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stddef.h \ - /usr/include/bits/waitflags.h /usr/include/bits/waitstatus.h \ - /usr/include/endian.h /usr/include/bits/endian.h \ - /usr/include/bits/byteswap.h /usr/include/sys/types.h \ /usr/include/bits/types.h /usr/include/bits/typesizes.h \ - /usr/include/time.h /usr/include/sys/select.h /usr/include/bits/select.h \ - /usr/include/bits/sigset.h /usr/include/bits/time.h \ - /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ - /usr/include/alloca.h /usr/include/string.h /usr/include/xlocale.h \ - ../include/users.h ../include/hashtable.h ../include/spinlock.h \ - ../include/thread.h /usr/include/pthread.h /usr/include/sched.h \ - /usr/include/bits/sched.h /usr/include/bits/setjmp.h ../include/atomic.h -hashtable.o: hashtable.c /usr/include/stdlib.h /usr/include/features.h \ - /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ - /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \ - /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stddef.h \ - /usr/include/bits/waitflags.h /usr/include/bits/waitstatus.h \ - /usr/include/endian.h /usr/include/bits/endian.h \ - /usr/include/bits/byteswap.h /usr/include/sys/types.h \ - /usr/include/bits/types.h /usr/include/bits/typesizes.h \ - /usr/include/time.h /usr/include/sys/select.h /usr/include/bits/select.h \ - /usr/include/bits/sigset.h /usr/include/bits/time.h \ - /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \ - /usr/include/alloca.h /usr/include/string.h /usr/include/xlocale.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/bits/waitflags.h \ + /usr/include/bits/waitstatus.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/bits/byteswap.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/xlocale.h ../include/users.h \ ../include/hashtable.h ../include/spinlock.h ../include/thread.h \ /usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \ - /usr/include/bits/setjmp.h ../include/atomic.h + /usr/include/bits/setjmp.h ../include/atomic.h ../include/dcb.h \ + ../include/buffer.h +hashtable.o: hashtable.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \ + /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/stdlib.h /usr/include/bits/waitflags.h \ + /usr/include/bits/waitstatus.h /usr/include/endian.h \ + /usr/include/bits/endian.h /usr/include/bits/byteswap.h \ + /usr/include/sys/types.h /usr/include/time.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/bits/time.h /usr/include/sys/sysmacros.h \ + /usr/include/bits/pthreadtypes.h /usr/include/alloca.h \ + /usr/include/string.h /usr/include/xlocale.h ../include/hashtable.h \ + ../include/spinlock.h ../include/thread.h /usr/include/pthread.h \ + /usr/include/sched.h /usr/include/bits/sched.h \ + /usr/include/bits/setjmp.h ../include/atomic.h ../include/dcb.h \ + ../include/buffer.h dbusers.o: dbusers.c /usr/include/stdio.h /usr/include/features.h \ /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \ diff --git a/core/hashtable.c b/core/hashtable.c index 08e3d95f9..30c4814bc 100644 --- a/core/hashtable.c +++ b/core/hashtable.c @@ -15,6 +15,7 @@ * * Copyright SkySQL Ab 2013 */ +#include #include #include #include @@ -279,6 +280,73 @@ HASHENTRIES *entry; } } +/** + * Print hash table statistics to the standard output + * + * @param table The hash table + */ +void +hashtable_stats(HASHTABLE *table) +{ +int total, longest, i, j; +HASHENTRIES *entries; + + printf("Hashtable: %p, size %d\n", table, table->hashsize); + total = 0; + longest = 0; + hashtable_read_lock(table); + for (i = 0; i < table->hashsize; i++) + { + j = 0; + entries = table->entries[i]; + while (entries) + { + j++; + entries = entries->next; + } + total += j; + if (j > longest) + longest = j; + } + hashtable_read_unlock(table); + printf("\tNo. of entries: %d\n", total); + printf("\tAverage chain length: %.1f\n", (float)total / table->hashsize); + printf("\tLongest chain length: %d\n", longest); +} + +/** + * Print hash table statistics to a DCB + * + * @param table The hash table + */ +void +dcb_hashtable_stats(DCB *dcb, HASHTABLE *table) +{ +int total, longest, i, j; +HASHENTRIES *entries; + + dcb_printf(dcb, "Hashtable: %p, size %d\n", table, table->hashsize); + total = 0; + longest = 0; + hashtable_read_lock(table); + for (i = 0; i < table->hashsize; i++) + { + j = 0; + entries = table->entries[i]; + while (entries) + { + j++; + entries = entries->next; + } + total += j; + if (j > longest) + longest = j; + } + hashtable_read_unlock(table); + dcb_printf(dcb, "\tNo. of entries: %d\n", total); + dcb_printf(dcb, "\tAverage chain length: %.1f\n", (float)total / table->hashsize); + dcb_printf(dcb, "\tLongest chain length: %d\n", longest); +} /** * Take a read lock on the hashtable. diff --git a/core/service.c b/core/service.c index 9829789fd..31aceb7ea 100644 --- a/core/service.c +++ b/core/service.c @@ -364,6 +364,7 @@ SERVER *ptr = service->databases; printf("\t\t%s:%d Protocol: %s\n", ptr->name, ptr->port, ptr->protocol); ptr = ptr->nextdb; } + printf("\tUsers data: %p\n", service->users); printf("\tTotal connections: %d\n", service->stats.n_sessions); printf("\tCurrently connected: %d\n", service->stats.n_current); } @@ -418,6 +419,7 @@ SERVICE *ptr; server->protocol); server = server->nextdb; } + dcb_printf(dcb, "\tUsers data: %p\n", ptr->users); dcb_printf(dcb, "\tTotal connections: %d\n", ptr->stats.n_sessions); dcb_printf(dcb, "\tCurrently connected: %d\n", ptr->stats.n_current); ptr = ptr->next; diff --git a/core/users.c b/core/users.c index c30ceb955..427ad743a 100644 --- a/core/users.c +++ b/core/users.c @@ -15,6 +15,7 @@ * * Copyright SkySQL Ab 2013 */ +#include #include #include #include @@ -147,3 +148,28 @@ users_update(USERS *users, char *user, char *auth) return 0; return hashtable_add(users->data, user, auth); } + +/** + * Print details of the users storage mechanism + * + * @param users The users table + */ +void +usersPrint(USERS *users) +{ + printf("Users table data\n"); + hashtable_stats(users->data); +} + +/** + * Print details of the users storage mechanism to a DCB + * + * @param dcb DCB to print to + * @param users The users table + */ +void +dcb_usersPrint(DCB *dcb, USERS *users) +{ + dcb_printf(dcb, "Users table data\n"); + dcb_hashtable_stats(dcb, users->data); +} diff --git a/include/hashtable.h b/include/hashtable.h index b14764978..5a571bb3b 100644 --- a/include/hashtable.h +++ b/include/hashtable.h @@ -32,6 +32,7 @@ */ #include #include +#include /** * The entries within a hashtable. @@ -77,4 +78,6 @@ extern int hashtable_delete(HASHTABLE *, void *); /**< Delete an entry table */ extern void *hashtable_fetch(HASHTABLE *, void *); /**< Fetch the data for a given key */ +extern void hashtable_stats(HASHTABLE *); /**< Print statisitics */ +extern void dcb_hashtable_stats(DCB *, HASHTABLE *); /**< Print statisitics */ #endif diff --git a/include/users.h b/include/users.h index 441091090..11dc2f60a 100644 --- a/include/users.h +++ b/include/users.h @@ -18,6 +18,7 @@ * Copyright SkySQL Ab 2013 */ #include +#include /** * @file users.h The functions to manipulate the table of users maintained @@ -57,4 +58,6 @@ extern int users_add(USERS *, char *, char *); /**< Add a user to the users tabl extern int users_delete(USERS *, char *); /**< Delete a user from the users table */ extern char *users_fetch(USERS *, char *); /**< Fetch the authentication data for a user */ extern int users_update(USERS *, char *, char *); /**< Change the password data for a user in the users table */ +extern void usersPrint(USERS *); /**< Print data about the users loaded */ +extern void dcb_usersPrint(DCB *, USERS *); /**< Print data about the users loaded */ #endif diff --git a/modules/protocol/depend.mk b/modules/protocol/depend.mk index 6c755f96b..ab2883581 100644 --- a/modules/protocol/depend.mk +++ b/modules/protocol/depend.mk @@ -163,3 +163,36 @@ mysql_common.o: mysql_common.c ../include/mysql_client_server_protocol.h \ ../../include/server.h ../../include/router.h ../../include/session.h \ ../../include/poll.h ../../include/users.h ../../include/hashtable.h \ ../../include/atomic.h +telnetd.o: telnetd.c /usr/include/stdio.h /usr/include/features.h \ + /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \ + /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \ + /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stddef.h \ + /usr/include/bits/types.h /usr/include/bits/typesizes.h \ + /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ + /usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stdarg.h \ + /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \ + /usr/include/string.h /usr/include/xlocale.h ../../include/dcb.h \ + ../../include/spinlock.h ../../include/thread.h /usr/include/pthread.h \ + /usr/include/endian.h /usr/include/bits/endian.h \ + /usr/include/bits/byteswap.h /usr/include/sched.h /usr/include/time.h \ + /usr/include/bits/sched.h /usr/include/bits/time.h \ + /usr/include/bits/pthreadtypes.h /usr/include/bits/setjmp.h \ + ../../include/buffer.h ../../include/service.h ../../include/server.h \ + ../../include/session.h /usr/include/sys/ioctl.h \ + /usr/include/bits/ioctls.h /usr/include/asm/ioctls.h \ + /usr/include/asm-generic/ioctls.h /usr/include/linux/ioctl.h \ + /usr/include/asm/ioctl.h /usr/include/asm-generic/ioctl.h \ + /usr/include/bits/ioctl-types.h /usr/include/sys/ttydefaults.h \ + /usr/include/errno.h /usr/include/bits/errno.h \ + /usr/include/linux/errno.h /usr/include/asm/errno.h \ + /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \ + /usr/include/sys/socket.h /usr/include/sys/uio.h \ + /usr/include/sys/types.h /usr/include/sys/select.h \ + /usr/include/bits/select.h /usr/include/bits/sigset.h \ + /usr/include/sys/sysmacros.h /usr/include/bits/uio.h \ + /usr/include/bits/socket.h /usr/include/bits/sockaddr.h \ + /usr/include/asm/socket.h /usr/include/asm-generic/socket.h \ + /usr/include/asm/sockios.h /usr/include/asm-generic/sockios.h \ + /usr/include/netinet/in.h /usr/include/stdint.h \ + /usr/include/bits/wchar.h /usr/include/bits/in.h \ + /usr/include/arpa/inet.h ../../include/router.h ../../include/poll.h diff --git a/modules/routing/debugcmd.c b/modules/routing/debugcmd.c index e773d5675..1548cff03 100644 --- a/modules/routing/debugcmd.c +++ b/modules/routing/debugcmd.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #define MAXARGS 5 @@ -77,6 +78,7 @@ struct subcommand showoptions[] = { { "dcbs", 0, dprintAllDCBs, "Show all descriptor control blocks (network connections)" }, { "dcb", 1, dprintDCB, "Show a single descriptor control block e.g. show dcb 0x493340" }, { "epoll", 0, dprintPollStats, "Show the poll statistics" }, + { "users", 1, dcb_usersPrint, "Show statistics for a suers table" }, { NULL, 0, NULL, NULL } }; diff --git a/modules/routing/depend.mk b/modules/routing/depend.mk index e90941377..7658fe6c1 100644 --- a/modules/routing/depend.mk +++ b/modules/routing/depend.mk @@ -79,4 +79,4 @@ debugcmd.o: debugcmd.c /usr/include/stdio.h /usr/include/features.h \ /usr/include/bits/setjmp.h ../../include/dcb.h ../../include/buffer.h \ ../../include/server.h ../../include/session.h ../../include/router.h \ ../../include/modules.h ../../include/atomic.h ../../include/poll.h \ - ../include/debugcli.h + ../../include/users.h ../../include/hashtable.h ../include/debugcli.h