summaryrefslogtreecommitdiff
path: root/src/utilities/util_list.c
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2012-04-03 12:58:39 +0000
committerKeith Bostic <keith@wiredtiger.com>2012-04-03 12:58:39 +0000
commit0db63d7c7470d677f3b06fda9b552407ebb7a078 (patch)
tree75e176860ed322a2c10e820ffa3fcabfb4ba0e79 /src/utilities/util_list.c
parentb276c01f4af5e514acd27adfc06dd290c98eb48f (diff)
downloadmongo-0db63d7c7470d677f3b06fda9b552407ebb7a078.tar.gz
Add support for the -s (snapshot) and -v (everything) options to the
wt list utility.
Diffstat (limited to 'src/utilities/util_list.c')
-rw-r--r--src/utilities/util_list.c111
1 files changed, 100 insertions, 11 deletions
diff --git a/src/utilities/util_list.c b/src/utilities/util_list.c
index 4fbf2f76542..590cadabc31 100644
--- a/src/utilities/util_list.c
+++ b/src/utilities/util_list.c
@@ -7,16 +7,26 @@
#include "util.h"
-static int list_print(WT_SESSION *);
+static int list_print(WT_SESSION *, const char *, int, int);
+static int list_print_snapshot(WT_SESSION *, const char *);
static int usage(void);
int
util_list(WT_SESSION *session, int argc, char *argv[])
{
- int ch;
+ int ch, ret, sflag, vflag;
+ char *name;
- while ((ch = util_getopt(argc, argv, "")) != EOF)
+ sflag = vflag = 0;
+ name = NULL;
+ while ((ch = util_getopt(argc, argv, "sv")) != EOF)
switch (ch) {
+ case 's':
+ sflag = 1;
+ break;
+ case 'v':
+ vflag = 1;
+ break;
case '?':
default:
return (usage());
@@ -24,10 +34,24 @@ util_list(WT_SESSION *session, int argc, char *argv[])
argc -= util_optind;
argv += util_optind;
- if (argc != 0)
+ switch (argc) {
+ case 0:
+ break;
+ case 1:
+ if ((name = util_name(
+ *argv, "table", UTIL_FILE_OK | UTIL_TABLE_OK)) == NULL)
+ return (1);
+ break;
+ default:
return (usage());
+ }
+
+ ret = list_print(session, name, sflag, vflag);
+
+ if (name != NULL)
+ free(name);
- return (list_print(session));
+ return (ret);
}
/*
@@ -35,11 +59,11 @@ util_list(WT_SESSION *session, int argc, char *argv[])
* List the high-level objects in the database.
*/
static int
-list_print(WT_SESSION *session)
+list_print(WT_SESSION *session, const char *name, int sflag, int vflag)
{
WT_CURSOR *cursor;
int ret;
- const char *key;
+ const char *key, *value;
ret = 0;
@@ -66,9 +90,26 @@ list_print(WT_SESSION *session)
if ((ret = cursor->get_key(cursor, &key)) != 0)
return (util_cerr("schema", "get_key", ret));
- /* All we care about are top-level objects (files or tables). */
- if (MATCH(key, "table:") || MATCH(key, "file:"))
- printf("%s\n", key);
+ /*
+ * If no object specified, show top-level objects (files and
+ * tables).
+ */
+ if (name == NULL) {
+ if (!MATCH(key, "table:") && !MATCH(key, "file:"))
+ continue;
+ } else
+ if (!MATCH(key, name))
+ continue;
+ printf("%s\n", key);
+ if (!sflag && !vflag)
+ continue;
+ if ((ret = cursor->get_value(cursor, &value)) != 0)
+ return (util_cerr("schema", "get_value", ret));
+ if (sflag && (ret = list_print_snapshot(session, value)) != 0)
+ return (ret);
+ if (vflag)
+ printf("%s\n", value);
+
}
if (ret != WT_NOTFOUND)
return (util_cerr("schema", "next", ret));
@@ -76,12 +117,60 @@ list_print(WT_SESSION *session)
return (0);
}
+/*
+ * list_print_snapshot --
+ * List the snapshot information.
+ */
+static int
+list_print_snapshot(WT_SESSION *session, const char *config)
+{
+ WT_SNAPSHOT *snap, *snapbase;
+ size_t len;
+ time_t t;
+ uintmax_t a;
+ int ret;
+ char buf[256];
+
+ /*
+ * We may not find any snapshots for this file, in which case we don't
+ * report an error, and continue our caller's loop. Otherwise, report
+ * each snapshot's name and time.
+ */
+ if ((ret =
+ __wt_snap_list_get(session, config, &snapbase)) == WT_NOTFOUND)
+ return (0);
+ WT_RET(ret);
+
+ /* Find the longest name, so we can pretty-print. */
+ len = 0;
+ WT_SNAPSHOT_FOREACH(snapbase, snap)
+ if (strlen(snap->name) > len)
+ len = strlen(snap->name);
+ ++len;
+
+ WT_SNAPSHOT_FOREACH(snapbase, snap) {
+ /*
+ * We have the seconds since the Epoch in a string. Convert to
+ * a maximum-sized integral type, assign to a correctly typed
+ * variable, display the result.
+ */
+ if (sscanf(snap->t, "%" SCNuMAX, &a) != 1)
+ return (
+ util_err(0, "unable to interpret snapshot time"));
+ t = (time_t)a;
+ printf("\t%*s: %s", (int)len, snap->name, ctime_r(&t, buf));
+ }
+
+ __wt_snap_list_free(session, snapbase);
+ return (0);
+}
+
static int
usage(void)
{
(void)fprintf(stderr,
"usage: %s %s "
- "list\n",
+ "list [-sv] [uri]\n",
progname, usage_prefix);
return (1);
}