summaryrefslogtreecommitdiff
path: root/src/utilities
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2011-04-25 13:54:49 +1000
committerMichael Cahill <michael.cahill@wiredtiger.com>2011-04-25 13:54:49 +1000
commitb9eb1bbb21ff0109b3e28045ca9e86d59ea1ce62 (patch)
tree54c34370693cbca68a7230a516858773a80d8705 /src/utilities
parentfade055c508735bff9b3d99c7a634289ec0bb5fc (diff)
downloadmongo-b9eb1bbb21ff0109b3e28045ca9e86d59ea1ce62.tar.gz
Remove the internal API, move automatically generated code to the public API.
refs #28 --HG-- rename : dist/api_class.py => dist/api_data.py
Diffstat (limited to 'src/utilities')
-rw-r--r--src/utilities/util_dump.c15
-rw-r--r--src/utilities/util_salvage.c48
-rw-r--r--src/utilities/util_stat.c67
-rw-r--r--src/utilities/util_verify.c46
4 files changed, 113 insertions, 63 deletions
diff --git a/src/utilities/util_dump.c b/src/utilities/util_dump.c
index 88caaee6e9a..15293236500 100644
--- a/src/utilities/util_dump.c
+++ b/src/utilities/util_dump.c
@@ -9,6 +9,7 @@
#include "util.h"
const char *progname;
+extern WT_EVENT_HANDLER *__wt_event_handler_verbose;
int usage(void);
@@ -19,17 +20,17 @@ main(int argc, char *argv[])
WT_SESSION *session;
WT_CURSOR *cursor;
WT_ITEM key, value;
- const char *tablename, *home;
+ const char *home, *tablename;
char cursor_config[100], datasrc[100];
- int ch, debug, printable, ret, tret;
+ int ch, debug, printable, ret, tret, verbose;
WT_UTILITY_INTRO(progname, argv);
conn = NULL;
home = NULL;
- debug = printable = 0;
+ debug = printable = verbose = 0;
- while ((ch = getopt(argc, argv, "df:h:p")) != EOF)
+ while ((ch = getopt(argc, argv, "df:h:pVv")) != EOF)
switch (ch) {
case 'd':
debug = 1;
@@ -50,6 +51,9 @@ main(int argc, char *argv[])
case 'V': /* version */
printf("%s\n", wiredtiger_version(NULL, NULL, NULL));
return (EXIT_SUCCESS);
+ case 'v': /* version */
+ verbose = 1;
+ break;
case '?':
default:
return (usage());
@@ -62,7 +66,8 @@ main(int argc, char *argv[])
return (usage());
tablename = *argv;
- if ((ret = wiredtiger_open(home, NULL, NULL, &conn)) != 0 ||
+ if ((ret = wiredtiger_open(home, verbose ?
+ __wt_event_handler_verbose : NULL, NULL, &conn)) != 0 ||
(ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
goto err;
diff --git a/src/utilities/util_salvage.c b/src/utilities/util_salvage.c
index d55a65804b4..9462c844fa2 100644
--- a/src/utilities/util_salvage.c
+++ b/src/utilities/util_salvage.c
@@ -15,14 +15,22 @@ int usage(void);
int
main(int argc, char *argv[])
{
- BTREE *btree;
- int ch, ret, tret, verbose;
+ WT_CONNECTION *conn;
+ WT_SESSION *session;
+ const char *home, *tablename;
+ int ch, debug, ret, tret, verbose;
WT_UTILITY_INTRO(progname, argv);
- verbose = 0;
- while ((ch = getopt(argc, argv, "Vv")) != EOF)
+ debug = verbose = 0;
+ while ((ch = getopt(argc, argv, "dh:Vv")) != EOF)
switch (ch) {
+ case 'd':
+ debug = 1;
+ break;
+ case 'h': /* home directory */
+ home = optarg;
+ break;
case 'v': /* verbose */
verbose = 1;
break;
@@ -39,28 +47,26 @@ main(int argc, char *argv[])
/* The remaining argument is the file name. */
if (argc != 1)
return (usage());
+ tablename = *argv;
- if ((ret = wiredtiger_simple_setup(progname, verbose ?
- __wt_event_handler_verbose : NULL, NULL, &btree)) == 0) {
- if ((ret = btree->open(btree, NULL, *argv, 0, 0)) != 0) {
- fprintf(stderr, "%s: btree.open(%s): %s\n",
- progname, *argv, wiredtiger_strerror(ret));
- goto err;
- }
- /* XXX verbose */
- if ((ret = btree->salvage(btree, NULL, 0)) != 0) {
- fprintf(stderr, "%s: btree.salvage(%s): %s\n",
- progname, *argv, wiredtiger_strerror(ret));
- goto err;
- }
- if (verbose)
- printf("\n");
+ if ((ret = wiredtiger_open(home, verbose ?
+ __wt_event_handler_verbose : NULL, NULL, &conn)) != 0 ||
+ (ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
+ goto err;
+
+ if ((ret = session->verify_table(session,
+ tablename, "salvage")) != 0) {
+ fprintf(stderr, "%s: salvage(%s): %s\n",
+ progname, tablename, wiredtiger_strerror(ret));
+ goto err;
}
+ if (verbose)
+ printf("\n");
if (0) {
err: ret = 1;
}
- if ((tret = wiredtiger_simple_teardown(progname, btree)) != 0 && ret == 0)
+ if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0)
ret = tret;
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
@@ -68,6 +74,6 @@ err: ret = 1;
int
usage(void)
{
- (void)fprintf(stderr, "usage: %s [-Vv] file\n", progname);
+ (void)fprintf(stderr, "usage: %s [-dVv] [-h home] file\n", progname);
return (EXIT_FAILURE);
}
diff --git a/src/utilities/util_stat.c b/src/utilities/util_stat.c
index 1123fd0e728..765126960de 100644
--- a/src/utilities/util_stat.c
+++ b/src/utilities/util_stat.c
@@ -15,14 +15,28 @@ int usage(void);
int
main(int argc, char *argv[])
{
- BTREE *btree;
- int ch, ret, tret, verbose;
+ WT_CONNECTION *conn;
+ WT_SESSION *session;
+ WT_CURSOR *cursor;
+ WT_ITEM key, value;
+ const char *home, *srcname;
+ char cursor_config[100], datasrc[100];
+ int ch, debug, ret, tret, verbose;
WT_UTILITY_INTRO(progname, argv);
- verbose = 0;
- while ((ch = getopt(argc, argv, "Vv")) != EOF)
+ conn = NULL;
+ home = NULL;
+ debug = verbose = 0;
+
+ while ((ch = getopt(argc, argv, "dh:Vv")) != EOF)
switch (ch) {
+ case 'd':
+ debug = 1;
+ break;
+ case 'h': /* home directory */
+ home = optarg;
+ break;
case 'V': /* version */
printf("%s\n", wiredtiger_version(NULL, NULL, NULL));
return (EXIT_SUCCESS);
@@ -39,25 +53,44 @@ main(int argc, char *argv[])
/* The remaining argument is the file name. */
if (argc != 1)
return (usage());
+ srcname = *argv;
- if ((ret = wiredtiger_simple_setup(progname, verbose ?
- __wt_event_handler_verbose : NULL, NULL, &btree)) == 0) {
- if ((ret = btree->open(btree, NULL, *argv, 0, 0)) != 0) {
- fprintf(stderr, "%s: db.open(%s): %s\n",
- progname, *argv, wiredtiger_strerror(ret));
- goto err;
- }
- if ((ret = btree->stat_print(btree, stdout, 0)) != 0) {
- fprintf(stderr, "%s: db.stat(%s): %s\n",
- progname, *argv, wiredtiger_strerror(ret));
- goto err;
- }
+ if ((ret = wiredtiger_open(home, verbose ?
+ __wt_event_handler_verbose : NULL, NULL, &conn)) != 0 ||
+ (ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
+ goto err;
+
+ snprintf(datasrc, sizeof(datasrc), "stat:%s", srcname);
+ snprintf(cursor_config, sizeof(cursor_config), "dump=print%s",
+ debug ? ",debug" : "");
+
+
+ if ((ret = session->open_cursor(session, datasrc, NULL,
+ cursor_config, &cursor)) != 0) {
+ fprintf(stderr, "%s: cursor open(%s) failed: %s\n",
+ progname, datasrc, wiredtiger_strerror(ret));
+ goto err;
+ }
+
+ while ((ret = cursor->next(cursor)) == 0) {
+ cursor->get_key(cursor, &key);
+ fwrite(key.data, key.size, 1, stdout);
+ fwrite("\n", 1, 1, stdout);
+ cursor->get_value(cursor, &value);
+ fwrite(value.data, value.size, 1, stdout);
+ fwrite("\n", 1, 1, stdout);
+ }
+
+ if (ret != WT_NOTFOUND) {
+ fprintf(stderr, "%s: cursor get(%s) failed: %s\n",
+ progname, datasrc, wiredtiger_strerror(ret));
+ goto err;
}
if (0) {
err: ret = 1;
}
- if ((tret = wiredtiger_simple_teardown(progname, btree)) != 0 && ret == 0)
+ if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0)
ret = tret;
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/src/utilities/util_verify.c b/src/utilities/util_verify.c
index 73fc7ba5252..12caddeca54 100644
--- a/src/utilities/util_verify.c
+++ b/src/utilities/util_verify.c
@@ -15,14 +15,23 @@ int usage(void);
int
main(int argc, char *argv[])
{
- BTREE *btree;
- int ch, ret, tret, verbose;
+ WT_CONNECTION *conn;
+ WT_SESSION *session;
+ const char *home, *tablename;
+ int ch, debug, ret, tret, verbose;
WT_UTILITY_INTRO(progname, argv);
- verbose = 0;
- while ((ch = getopt(argc, argv, "Vv")) != EOF)
+ home = NULL;
+ debug = verbose = 0;
+ while ((ch = getopt(argc, argv, "dh:Vv")) != EOF)
switch (ch) {
+ case 'd':
+ debug = 1;
+ break;
+ case 'h': /* home directory */
+ home = optarg;
+ break;
case 'v': /* verbose */
verbose = 1;
break;
@@ -39,28 +48,25 @@ main(int argc, char *argv[])
/* The remaining argument is the file name. */
if (argc != 1)
return (usage());
+ tablename = *argv;
- if ((ret = wiredtiger_simple_setup(progname, verbose ?
- __wt_event_handler_verbose : NULL, NULL, &btree)) == 0) {
- if ((ret = btree->open(btree, NULL, *argv, 0, 0)) != 0) {
- fprintf(stderr, "%s: btree.open(%s): %s\n",
- progname, *argv, wiredtiger_strerror(ret));
- goto err;
- }
- /* XXX verbose */
- if ((ret = btree->verify(btree, NULL, 0)) != 0) {
- fprintf(stderr, "%s: btree.verify(%s): %s\n",
- progname, *argv, wiredtiger_strerror(ret));
- goto err;
- }
- if (verbose)
- printf("\n");
+ if ((ret = wiredtiger_open(home, verbose ?
+ __wt_event_handler_verbose : NULL, NULL, &conn)) != 0 ||
+ (ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
+ goto err;
+
+ if ((ret = session->verify_table(session, tablename, NULL)) != 0) {
+ fprintf(stderr, "%s: salvage(%s): %s\n",
+ progname, tablename, wiredtiger_strerror(ret));
+ goto err;
}
+ if (verbose)
+ printf("\n");
if (0) {
err: ret = 1;
}
- if ((tret = wiredtiger_simple_teardown(progname, btree)) != 0 && ret == 0)
+ if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0)
ret = tret;
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}