diff options
Diffstat (limited to 'src/utilities/util_dump.c')
-rw-r--r-- | src/utilities/util_dump.c | 139 |
1 files changed, 79 insertions, 60 deletions
diff --git a/src/utilities/util_dump.c b/src/utilities/util_dump.c index 37a26089f7c..6f918b51774 100644 --- a/src/utilities/util_dump.c +++ b/src/utilities/util_dump.c @@ -7,19 +7,19 @@ #include "util.h" +static int dump_config(WT_SESSION *, const char *); +static int dump_file_config(WT_SESSION *, const char *); static int dump_prefix(int); static int dump_suffix(void); +static int dump_table_config(WT_SESSION *, WT_CURSOR *, const char *); static int print_config(WT_SESSION *, const char *, const char *, const char *); -static int schema(WT_SESSION *, const char *); -static int schema_file(WT_SESSION *, WT_CURSOR *, const char *); -static int schema_table(WT_SESSION *, WT_CURSOR *, const char *); static int usage(void); static inline int dump_forward(WT_CURSOR *cursor, const char *name) { + WT_DECL_RET; const char *key, *value; - int ret; while ((ret = cursor->next(cursor)) == 0) { if ((ret = cursor->get_key(cursor, &key)) != 0) @@ -35,8 +35,8 @@ dump_forward(WT_CURSOR *cursor, const char *name) static inline int dump_reverse(WT_CURSOR *cursor, const char *name) { + WT_DECL_RET; const char *key, *value; - int ret; while ((ret = cursor->prev(cursor)) == 0) { if ((ret = cursor->get_key(cursor, &key)) != 0) @@ -53,12 +53,14 @@ int util_dump(WT_SESSION *session, int argc, char *argv[]) { WT_CURSOR *cursor; - int ch, hex, ret, reverse; - char *name; + WT_DECL_RET; + size_t len; + int ch, hex, reverse; + char *config, *name, *snapshot; hex = reverse = 0; - name = NULL; - while ((ch = util_getopt(argc, argv, "f:rx")) != EOF) + config = name = snapshot = NULL; + while ((ch = util_getopt(argc, argv, "f:rs:x")) != EOF) switch (ch) { case 'f': /* output file */ if (freopen(util_optarg, "w", stdout) == NULL) @@ -68,6 +70,9 @@ util_dump(WT_SESSION *session, int argc, char *argv[]) case 'r': reverse = 1; break; + case 's': + snapshot = util_optarg; + break; case 'x': hex = 1; break; @@ -86,12 +91,24 @@ util_dump(WT_SESSION *session, int argc, char *argv[]) goto err; if (dump_prefix(hex) != 0 || - schema(session, name) != 0 || + dump_config(session, name) != 0 || dump_suffix() != 0) goto err; - if ((ret = session->open_cursor(session, - name, NULL, hex ? "dump=hex" : "dump=print", &cursor)) != 0) { + len = snapshot == NULL ? 0 : strlen("snapshot=") + strlen(snapshot); + len += strlen(hex ? "dump=hex" : "dump=print"); + if ((config = malloc(len + 10)) == NULL) + goto err; + if (snapshot == NULL) + config[0] = '\0'; + else { + (void)strcpy(config, "snapshot="); + (void)strcat(config, snapshot); + (void)strcat(config, ","); + } + (void)strcat(config, hex ? "dump=hex" : "dump=print"); + if ((ret = session->open_cursor( + session, name, NULL, config, &cursor)) != 0) { fprintf(stderr, "%s: cursor open(%s) failed: %s\n", progname, name, wiredtiger_strerror(ret)); goto err; @@ -106,6 +123,8 @@ util_dump(WT_SESSION *session, int argc, char *argv[]) err: ret = 1; } + if (config != NULL) + free(config); if (name != NULL) free(name); @@ -113,54 +132,53 @@ err: ret = 1; } /* - * schema -- - * Dump the schema for the uri. + * config -- + * Dump the config for the uri. */ static int -schema(WT_SESSION *session, const char *uri) +dump_config(WT_SESSION *session, const char *uri) { WT_CURSOR *cursor; - int ret, tret; - - ret = 0; - - /* Open the schema file. */ - if ((ret = session->open_cursor( - session, WT_SCHEMA_URI, NULL, NULL, &cursor)) != 0) { - fprintf(stderr, "%s: %s: session.open_cursor: %s\n", - progname, WT_SCHEMA_URI, wiredtiger_strerror(ret)); - return (1); - } + WT_DECL_RET; + int tret; + + /* Dump the config. */ + if (strncmp(uri, "table:", strlen("table:")) == 0) { + /* Open a metadata cursor. */ + if ((ret = session->open_cursor( + session, WT_METADATA_URI, NULL, NULL, &cursor)) != 0) { + fprintf(stderr, "%s: %s: session.open_cursor: %s\n", + progname, + WT_METADATA_URI, wiredtiger_strerror(ret)); + return (1); + } - /* Dump the schema. */ - if (strncmp(uri, "table:", strlen("table:")) == 0) - ret = schema_table(session, cursor, uri); - else - ret = schema_file(session, cursor, uri); + ret = dump_table_config(session, cursor, uri); - if ((tret = cursor->close(cursor)) != 0 && ret == 0) - ret = tret; + if ((tret = cursor->close(cursor)) != 0 && ret == 0) + ret = tret; + } else + ret = dump_file_config(session, uri); return (ret); } /* - * schema_table -- - * Dump the schema for a table. + * dump_table_config -- + * Dump the config for a table. */ static int -schema_table(WT_SESSION *session, WT_CURSOR *cursor, const char *uri) +dump_table_config(WT_SESSION *session, WT_CURSOR *cursor, const char *uri) { struct { - char *key; /* Schema key */ - char *value; /* Schema value */ + char *key; /* Metadata key */ + char *value; /* Metadata value */ } *list; - int i, elem, list_elem, ret; + WT_DECL_RET; + int i, elem, list_elem; const char *key, *name, *value; char *buf, *filename, *p, *t, *sep; - ret = 0; - /* Get the name. */ if ((name = strchr(uri, ':')) == NULL) { fprintf(stderr, "%s: %s: corrupted uri\n", progname, uri); @@ -176,7 +194,7 @@ schema_table(WT_SESSION *session, WT_CURSOR *cursor, const char *uri) return (util_cerr(uri, "get_key", ret)); if ((buf = strdup(key)) == NULL) return (util_err(errno, NULL)); - + /* Check for the dump table's column groups or indices. */ if ((p = strchr(buf, ':')) == NULL) continue; @@ -206,7 +224,7 @@ schema_table(WT_SESSION *session, WT_CURSOR *cursor, const char *uri) ret = 0; /* - * Dump out the schema information: first, dump the uri entry itself + * Dump out the config information: first, dump the uri entry itself * (requires a lookup). */ cursor->set_key(cursor, uri); @@ -248,7 +266,7 @@ schema_table(WT_SESSION *session, WT_CURSOR *cursor, const char *uri) cursor->set_key(cursor, p); if ((ret = cursor->search(cursor)) != 0) { fprintf(stderr, - "%s: %s: unable to find schema reference for the " + "%s: %s: unable to find metadata for the " "underlying file %s\n", progname, list[i].key, p); return (1); @@ -270,25 +288,26 @@ schema_table(WT_SESSION *session, WT_CURSOR *cursor, const char *uri) } /* - * schema_file -- - * Dump the schema for a file. + * dump_file_config -- + * Dump the config for a file. */ static int -schema_file(WT_SESSION *session, WT_CURSOR *cursor, const char *uri) +dump_file_config(WT_SESSION *session, const char *uri) { - const char *key, *value; - int ret; + WT_DECL_RET; + const char *value; - ret = 0; + /* + * We want to be able to dump the metadata file itself, but the + * configuration for that file lives in the turtle file. Reach + * down into the library and ask for the file's configuration, + * that will work in all cases. + */ + if ((ret = __wt_metadata_get(session, uri, &value)) != 0) + return (util_err(ret, "metadata read: %s", uri)); - cursor->set_key(cursor, uri); - if ((ret = cursor->search(cursor)) != 0) - return (util_cerr(uri, "search", ret)); - if ((ret = cursor->get_key(cursor, &key)) != 0) - return (util_cerr(uri, "get_key", ret)); - if ((ret = cursor->get_value(cursor, &value)) != 0) - return (util_cerr(uri, "get_value", ret)); - return (print_config(session, key, value, NULL)); + /* Leak the memory, I don't care. */ + return (print_config(session, uri, value, NULL)); } /* @@ -331,8 +350,8 @@ static int print_config(WT_SESSION *session, const char *key, const char *v1, const char *v2) { + WT_DECL_RET; const char *value_ret; - int ret; /* * The underlying call will ignore v2 if v1 is NULL -- check here and @@ -357,7 +376,7 @@ usage(void) { (void)fprintf(stderr, "usage: %s %s " - "dump [-rx] [-f output-file] uri\n", + "dump [-rx] [-f output-file] [-s snapshot] uri\n", progname, usage_prefix); return (1); } |