diff options
Diffstat (limited to 'src/third_party/wiredtiger/src/utilities')
29 files changed, 3158 insertions, 3262 deletions
diff --git a/src/third_party/wiredtiger/src/utilities/util.h b/src/third_party/wiredtiger/src/utilities/util.h index 3b12d9be98a..af2f854786e 100644 --- a/src/third_party/wiredtiger/src/utilities/util.h +++ b/src/third_party/wiredtiger/src/utilities/util.h @@ -9,49 +9,49 @@ #include <wt_internal.h> typedef struct { - void *mem; /* Managed memory chunk */ - size_t memsize; /* Managed memory size */ + void *mem; /* Managed memory chunk */ + size_t memsize; /* Managed memory size */ } ULINE; -extern const char *home; /* Home directory */ -extern const char *progname; /* Program name */ -extern const char *usage_prefix; /* Global arguments */ -extern bool verbose; /* Verbose flag */ +extern const char *home; /* Home directory */ +extern const char *progname; /* Program name */ +extern const char *usage_prefix; /* Global arguments */ +extern bool verbose; /* Verbose flag */ extern WT_EVENT_HANDLER *verbose_handler; -extern int __wt_opterr; /* if error message should be printed */ -extern int __wt_optind; /* index into parent argv vector */ -extern int __wt_optopt; /* character checked for validity */ -extern int __wt_optreset; /* reset getopt */ -extern char *__wt_optarg; /* argument associated with option */ +extern int __wt_opterr; /* if error message should be printed */ +extern int __wt_optind; /* index into parent argv vector */ +extern int __wt_optopt; /* character checked for validity */ +extern int __wt_optreset; /* reset getopt */ +extern char *__wt_optarg; /* argument associated with option */ -int util_alter(WT_SESSION *, int, char *[]); -int util_backup(WT_SESSION *, int, char *[]); -int util_cerr(WT_CURSOR *, const char *, int); -int util_compact(WT_SESSION *, int, char *[]); -void util_copyright(void); -int util_create(WT_SESSION *, int, char *[]); -int util_downgrade(WT_SESSION *, int, char *[]); -int util_drop(WT_SESSION *, int, char *[]); -int util_dump(WT_SESSION *, int, char *[]); -int util_err(WT_SESSION *, int, const char *, ...) - WT_GCC_FUNC_DECL_ATTRIBUTE((format (printf, 3, 4))); -int util_flush(WT_SESSION *, const char *); -int util_import(WT_SESSION *, int, char *[]); -int util_list(WT_SESSION *, int, char *[]); -int util_load(WT_SESSION *, int, char *[]); -int util_loadtext(WT_SESSION *, int, char *[]); -int util_printlog(WT_SESSION *, int, char *[]); -int util_read(WT_SESSION *, int, char *[]); -int util_read_line(WT_SESSION *, ULINE *, bool, bool *); -int util_rebalance(WT_SESSION *, int, char *[]); -int util_rename(WT_SESSION *, int, char *[]); -int util_salvage(WT_SESSION *, int, char *[]); -int util_stat(WT_SESSION *, int, char *[]); -int util_str2num(WT_SESSION *, const char *, bool, uint64_t *); -int util_truncate(WT_SESSION *, int, char *[]); -int util_upgrade(WT_SESSION *, int, char *[]); -char *util_uri(WT_SESSION *, const char *, const char *); -int util_verify(WT_SESSION *, int, char *[]); -int util_write(WT_SESSION *, int, char *[]); +int util_alter(WT_SESSION *, int, char *[]); +int util_backup(WT_SESSION *, int, char *[]); +int util_cerr(WT_CURSOR *, const char *, int); +int util_compact(WT_SESSION *, int, char *[]); +void util_copyright(void); +int util_create(WT_SESSION *, int, char *[]); +int util_downgrade(WT_SESSION *, int, char *[]); +int util_drop(WT_SESSION *, int, char *[]); +int util_dump(WT_SESSION *, int, char *[]); +int util_err(WT_SESSION *, int, const char *, ...) + WT_GCC_FUNC_DECL_ATTRIBUTE((format(printf, 3, 4))); +int util_flush(WT_SESSION *, const char *); +int util_import(WT_SESSION *, int, char *[]); +int util_list(WT_SESSION *, int, char *[]); +int util_load(WT_SESSION *, int, char *[]); +int util_loadtext(WT_SESSION *, int, char *[]); +int util_printlog(WT_SESSION *, int, char *[]); +int util_read(WT_SESSION *, int, char *[]); +int util_read_line(WT_SESSION *, ULINE *, bool, bool *); +int util_rebalance(WT_SESSION *, int, char *[]); +int util_rename(WT_SESSION *, int, char *[]); +int util_salvage(WT_SESSION *, int, char *[]); +int util_stat(WT_SESSION *, int, char *[]); +int util_str2num(WT_SESSION *, const char *, bool, uint64_t *); +int util_truncate(WT_SESSION *, int, char *[]); +int util_upgrade(WT_SESSION *, int, char *[]); +char *util_uri(WT_SESSION *, const char *, const char *); +int util_verify(WT_SESSION *, int, char *[]); +int util_write(WT_SESSION *, int, char *[]); diff --git a/src/third_party/wiredtiger/src/utilities/util_alter.c b/src/third_party/wiredtiger/src/utilities/util_alter.c index 441dedf8bc9..996c489aa19 100644 --- a/src/third_party/wiredtiger/src/utilities/util_alter.c +++ b/src/third_party/wiredtiger/src/utilities/util_alter.c @@ -13,40 +13,38 @@ static int usage(void); int util_alter(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char **configp; - - while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) - switch (ch) { - case '?': - default: - return (usage()); - } - - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining arguments are uri/string pairs. */ - if (argc % 2 != 0) - return (usage()); - - for (configp = argv; *configp != NULL; configp += 2) - if ((ret = session->alter( - session, configp[0], configp[1])) != 0) { - (void)util_err(session, ret, - "session.alter: %s, %s", configp[0], configp[1]); - return (1); - } - return (0); + WT_DECL_RET; + int ch; + char **configp; + + while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) + switch (ch) { + case '?': + default: + return (usage()); + } + + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining arguments are uri/string pairs. */ + if (argc % 2 != 0) + return (usage()); + + for (configp = argv; *configp != NULL; configp += 2) + if ((ret = session->alter(session, configp[0], configp[1])) != 0) { + (void)util_err(session, ret, "session.alter: %s, %s", configp[0], configp[1]); + return (1); + } + return (0); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "alter uri configuration ...\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "alter uri configuration ...\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_backup.c b/src/third_party/wiredtiger/src/utilities/util_backup.c index f544c76cc05..b7e45d37ef5 100644 --- a/src/third_party/wiredtiger/src/utilities/util_backup.c +++ b/src/third_party/wiredtiger/src/utilities/util_backup.c @@ -14,115 +14,113 @@ static int usage(void); int util_backup(WT_SESSION *session, int argc, char *argv[]) { - WT_CURSOR *cursor; - WT_DECL_ITEM(tmp); - WT_DECL_RET; - WT_SESSION_IMPL *session_impl; - int ch; - const char *directory, *name; - bool target; - - session_impl = (WT_SESSION_IMPL *)session; - - target = false; - while ((ch = __wt_getopt(progname, argc, argv, "t:")) != EOF) - switch (ch) { - case 't': - if (!target) { - WT_ERR(__wt_scr_alloc(session_impl, 0, &tmp)); - WT_ERR(__wt_buf_fmt( - session_impl, tmp, "%s", "target=(")); - } - WT_ERR(__wt_buf_catfmt(session_impl, tmp, - "%s\"%s\"", target ? "," : "", __wt_optarg)); - target = true; - break; - case '?': - default: - WT_ERR(usage()); - } - argc -= __wt_optind; - argv += __wt_optind; - - if (argc != 1) { - (void)usage(); - goto err; - } - directory = *argv; - - /* Terminate any target. */ - if (target) - WT_ERR(__wt_buf_catfmt(session_impl, tmp, "%s", ")")); - - if ((ret = session->open_cursor(session, "backup:", - NULL, target ? (char *)tmp->data : NULL, &cursor)) != 0) { - fprintf(stderr, "%s: cursor open(backup:) failed: %s\n", - progname, session->strerror(session, ret)); - goto err; - } - - /* Copy the files. */ - while ( - (ret = cursor->next(cursor)) == 0 && - (ret = cursor->get_key(cursor, &name)) == 0) - if ((ret = copy(session, directory, name)) != 0) - goto err; - if (ret == WT_NOTFOUND) - ret = 0; - - if (ret != 0) { - fprintf(stderr, "%s: cursor next(backup:) failed: %s\n", - progname, session->strerror(session, ret)); - goto err; - } - -err: __wt_scr_free(session_impl, &tmp); - return (ret); + WT_CURSOR *cursor; + WT_DECL_ITEM(tmp); + WT_DECL_RET; + WT_SESSION_IMPL *session_impl; + int ch; + const char *directory, *name; + bool target; + + session_impl = (WT_SESSION_IMPL *)session; + + target = false; + while ((ch = __wt_getopt(progname, argc, argv, "t:")) != EOF) + switch (ch) { + case 't': + if (!target) { + WT_ERR(__wt_scr_alloc(session_impl, 0, &tmp)); + WT_ERR(__wt_buf_fmt(session_impl, tmp, "%s", "target=(")); + } + WT_ERR(__wt_buf_catfmt(session_impl, tmp, "%s\"%s\"", target ? "," : "", __wt_optarg)); + target = true; + break; + case '?': + default: + WT_ERR(usage()); + } + argc -= __wt_optind; + argv += __wt_optind; + + if (argc != 1) { + (void)usage(); + goto err; + } + directory = *argv; + + /* Terminate any target. */ + if (target) + WT_ERR(__wt_buf_catfmt(session_impl, tmp, "%s", ")")); + + if ((ret = session->open_cursor( + session, "backup:", NULL, target ? (char *)tmp->data : NULL, &cursor)) != 0) { + fprintf(stderr, "%s: cursor open(backup:) failed: %s\n", progname, + session->strerror(session, ret)); + goto err; + } + + /* Copy the files. */ + while ((ret = cursor->next(cursor)) == 0 && (ret = cursor->get_key(cursor, &name)) == 0) + if ((ret = copy(session, directory, name)) != 0) + goto err; + if (ret == WT_NOTFOUND) + ret = 0; + + if (ret != 0) { + fprintf(stderr, "%s: cursor next(backup:) failed: %s\n", progname, + session->strerror(session, ret)); + goto err; + } + +err: + __wt_scr_free(session_impl, &tmp); + return (ret); } static int copy(WT_SESSION *session, const char *directory, const char *name) { - WT_DECL_RET; - size_t len; - char *to; - - to = NULL; - - /* Build the target pathname. */ - len = strlen(directory) + strlen(name) + 2; - if ((to = malloc(len)) == NULL) { - fprintf(stderr, "%s: %s\n", progname, strerror(errno)); - return (1); - } - if ((ret = __wt_snprintf(to, len, "%s/%s", directory, name)) != 0) { - fprintf(stderr, "%s: %s\n", progname, strerror(ret)); - goto err; - } - - if (verbose && printf("Backing up %s/%s to %s\n", home, name, to) < 0) { - fprintf(stderr, "%s: %s\n", progname, strerror(EIO)); - goto err; - } - - /* - * Use WiredTiger to copy the file: ensuring stability of the copied - * file on disk requires care, and WiredTiger knows how to do it. - */ - if ((ret = __wt_copy_and_sync(session, name, to)) != 0) - fprintf(stderr, "%s/%s to %s: backup copy: %s\n", - home, name, to, session->strerror(session, ret)); - -err: free(to); - return (ret); + WT_DECL_RET; + size_t len; + char *to; + + to = NULL; + + /* Build the target pathname. */ + len = strlen(directory) + strlen(name) + 2; + if ((to = malloc(len)) == NULL) { + fprintf(stderr, "%s: %s\n", progname, strerror(errno)); + return (1); + } + if ((ret = __wt_snprintf(to, len, "%s/%s", directory, name)) != 0) { + fprintf(stderr, "%s: %s\n", progname, strerror(ret)); + goto err; + } + + if (verbose && printf("Backing up %s/%s to %s\n", home, name, to) < 0) { + fprintf(stderr, "%s: %s\n", progname, strerror(EIO)); + goto err; + } + + /* + * Use WiredTiger to copy the file: ensuring stability of the copied file on disk requires care, + * and WiredTiger knows how to do it. + */ + if ((ret = __wt_copy_and_sync(session, name, to)) != 0) + fprintf(stderr, "%s/%s to %s: backup copy: %s\n", home, name, to, + session->strerror(session, ret)); + +err: + free(to); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "backup [-t uri] directory\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "backup [-t uri] directory\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_compact.c b/src/third_party/wiredtiger/src/utilities/util_compact.c index f9caa5b43b6..ab70db8b16c 100644 --- a/src/third_party/wiredtiger/src/utilities/util_compact.c +++ b/src/third_party/wiredtiger/src/utilities/util_compact.c @@ -13,39 +13,39 @@ static int usage(void); int util_compact(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char *uri; - - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) - switch (ch) { - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining argument is the table name. */ - if (argc != 1) - return (usage()); - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); - - if ((ret = session->compact(session, uri, NULL)) != 0) - (void)util_err(session, ret, "session.compact: %s", uri); - - free(uri); - return (ret); + WT_DECL_RET; + int ch; + char *uri; + + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) + switch (ch) { + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining argument is the table name. */ + if (argc != 1) + return (usage()); + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); + + if ((ret = session->compact(session, uri, NULL)) != 0) + (void)util_err(session, ret, "session.compact: %s", uri); + + free(uri); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "compact uri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "compact uri\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_cpyright.c b/src/third_party/wiredtiger/src/utilities/util_cpyright.c index b15dd71de3e..523ad41b23b 100644 --- a/src/third_party/wiredtiger/src/utilities/util_cpyright.c +++ b/src/third_party/wiredtiger/src/utilities/util_cpyright.c @@ -11,26 +11,25 @@ void util_copyright(void) { - printf("%s\n", "Copyright (c) 2008-2019 MongoDB, Inc."); - printf("%s\n\n", "All rights reserved."); + printf("%s\n", "Copyright (c) 2008-2019 MongoDB, Inc."); + printf("%s\n\n", "All rights reserved."); - printf("%s\n\n", - "This program is free software: you can redistribute it and/or\n" - "modify it under the terms of versions 2 or 3 of the GNU General\n" - "Public License as published by the Free Software Foundation."); + printf("%s\n\n", + "This program is free software: you can redistribute it and/or\n" + "modify it under the terms of versions 2 or 3 of the GNU General\n" + "Public License as published by the Free Software Foundation."); - printf("%s\n\n", - "This program is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - "GNU General Public License for more details:"); + printf("%s\n\n", + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details:"); - printf("\t%s\n\n", - "http://www.gnu.org/licenses/gpl-3.0-standalone.html"); + printf("\t%s\n\n", "http://www.gnu.org/licenses/gpl-3.0-standalone.html"); - printf("%s\n", - "For a license to use the WiredTiger software under conditions\n" - "other than those described by the GNU General Public License,\n" - "or for technical support for this software, contact WiredTiger,\n" - "Inc. at info@wiredtiger.com."); + printf("%s\n", + "For a license to use the WiredTiger software under conditions\n" + "other than those described by the GNU General Public License,\n" + "or for technical support for this software, contact WiredTiger,\n" + "Inc. at info@wiredtiger.com."); } diff --git a/src/third_party/wiredtiger/src/utilities/util_create.c b/src/third_party/wiredtiger/src/utilities/util_create.c index 03c94c34f32..ca88373e0fa 100644 --- a/src/third_party/wiredtiger/src/utilities/util_create.c +++ b/src/third_party/wiredtiger/src/utilities/util_create.c @@ -13,44 +13,44 @@ static int usage(void); int util_create(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char *config, *uri; - - config = uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "c:")) != EOF) - switch (ch) { - case 'c': /* command-line configuration */ - config = __wt_optarg; - break; - case '?': - default: - return (usage()); - } - - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining argument is the uri. */ - if (argc != 1) - return (usage()); - - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); - - if ((ret = session->create(session, uri, config)) != 0) - (void)util_err(session, ret, "session.create: %s", uri); - - free(uri); - return (ret); + WT_DECL_RET; + int ch; + char *config, *uri; + + config = uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "c:")) != EOF) + switch (ch) { + case 'c': /* command-line configuration */ + config = __wt_optarg; + break; + case '?': + default: + return (usage()); + } + + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining argument is the uri. */ + if (argc != 1) + return (usage()); + + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); + + if ((ret = session->create(session, uri, config)) != 0) + (void)util_err(session, ret, "session.create: %s", uri); + + free(uri); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "create [-c configuration] uri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "create [-c configuration] uri\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_downgrade.c b/src/third_party/wiredtiger/src/utilities/util_downgrade.c index ce780c8614c..1bc93bc1272 100644 --- a/src/third_party/wiredtiger/src/utilities/util_downgrade.c +++ b/src/third_party/wiredtiger/src/utilities/util_downgrade.c @@ -13,46 +13,45 @@ static int usage(void); int util_downgrade(WT_SESSION *session, int argc, char *argv[]) { - WT_CONNECTION *conn; - WT_DECL_RET; - int ch; - char config_str[128], *release; - - release = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "V:")) != EOF) - switch (ch) { - case 'V': - release = __wt_optarg; - break; - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - - /* - * The release argument is required. - * There should not be any more arguments. - */ - if (argc != 0 || release == NULL) - return (usage()); - - if ((ret = __wt_snprintf(config_str, sizeof(config_str), - "compatibility=(release=%s)", release)) != 0) - return (util_err(session, ret, NULL)); - conn = session->connection; - if ((ret = conn->reconfigure(conn, config_str)) != 0) - return (util_err(session, ret, "WT_CONNECTION.downgrade")); - - return (0); + WT_CONNECTION *conn; + WT_DECL_RET; + int ch; + char config_str[128], *release; + + release = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "V:")) != EOF) + switch (ch) { + case 'V': + release = __wt_optarg; + break; + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + + /* + * The release argument is required. There should not be any more arguments. + */ + if (argc != 0 || release == NULL) + return (usage()); + + if ((ret = __wt_snprintf( + config_str, sizeof(config_str), "compatibility=(release=%s)", release)) != 0) + return (util_err(session, ret, NULL)); + conn = session->connection; + if ((ret = conn->reconfigure(conn, config_str)) != 0) + return (util_err(session, ret, "WT_CONNECTION.downgrade")); + + return (0); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "downgrade -V release\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "downgrade -V release\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_drop.c b/src/third_party/wiredtiger/src/utilities/util_drop.c index b1b0991e68b..8d062a59cb6 100644 --- a/src/third_party/wiredtiger/src/utilities/util_drop.c +++ b/src/third_party/wiredtiger/src/utilities/util_drop.c @@ -13,40 +13,40 @@ static int usage(void); int util_drop(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char *uri; - - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) - switch (ch) { - case '?': - default: - return (usage()); - } - - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining argument is the uri. */ - if (argc != 1) - return (usage()); - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); - - if ((ret = session->drop(session, uri, "force")) != 0) - (void)util_err(session, ret, "session.drop: %s", uri); - - free(uri); - return (ret); + WT_DECL_RET; + int ch; + char *uri; + + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) + switch (ch) { + case '?': + default: + return (usage()); + } + + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining argument is the uri. */ + if (argc != 1) + return (usage()); + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); + + if ((ret = session->drop(session, uri, "force")) != 0) + (void)util_err(session, ret, "session.drop: %s", uri); + + free(uri); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "drop uri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "drop uri\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_dump.c b/src/third_party/wiredtiger/src/utilities/util_dump.c index fdd0d28a30c..28935fe7f2a 100644 --- a/src/third_party/wiredtiger/src/utilities/util_dump.c +++ b/src/third_party/wiredtiger/src/utilities/util_dump.c @@ -10,8 +10,8 @@ #include "util.h" #include "util_dump.h" -#define STRING_MATCH_CONFIG(s, item) \ - (strncmp(s, (item).str, (item).len) == 0 && (s)[(item).len] == '\0') +#define STRING_MATCH_CONFIG(s, item) \ + (strncmp(s, (item).str, (item).len) == 0 && (s)[(item).len] == '\0') static int dump_config(WT_SESSION *, const char *, WT_CURSOR *, bool, bool); static int dump_json_begin(WT_SESSION *); @@ -21,10 +21,8 @@ static int dump_json_table_end(WT_SESSION *); static int dump_prefix(WT_SESSION *, bool, bool); static int dump_record(WT_CURSOR *, bool, bool); static int dump_suffix(WT_SESSION *, bool); -static int dump_table_config( - WT_SESSION *, WT_CURSOR *, WT_CURSOR *, const char *, bool); -static int dump_table_parts_config( - WT_SESSION *, WT_CURSOR *, const char *, const char *, bool); +static int dump_table_config(WT_SESSION *, WT_CURSOR *, WT_CURSOR *, const char *, bool); +static int dump_table_parts_config(WT_SESSION *, WT_CURSOR *, const char *, const char *, bool); static int dup_json_string(const char *, char **); static int print_config(WT_SESSION *, const char *, const char *, bool, bool); static int usage(void); @@ -34,222 +32,214 @@ static FILE *fp; int util_dump(WT_SESSION *session, int argc, char *argv[]) { - WT_CURSOR *cursor; - WT_DECL_ITEM(tmp); - WT_DECL_RET; - WT_SESSION_IMPL *session_impl; - int ch, i; - char *checkpoint, *ofile, *p, *simpleuri, *uri; - bool hex, json, reverse; - - session_impl = (WT_SESSION_IMPL *)session; - - cursor = NULL; - checkpoint = ofile = simpleuri = uri = NULL; - hex = json = reverse = false; - while ((ch = __wt_getopt(progname, argc, argv, "c:f:jrx")) != EOF) - switch (ch) { - case 'c': - checkpoint = __wt_optarg; - break; - case 'f': - ofile = __wt_optarg; - break; - case 'j': - json = true; - break; - case 'r': - reverse = true; - break; - case 'x': - hex = true; - break; - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining argument is the uri. */ - if (argc < 1 || (argc != 1 && !json)) - return (usage()); - - /* -j and -x are incompatible. */ - if (hex && json) { - fprintf(stderr, - "%s: the -j and -x dump options are incompatible\n", - progname); - return (usage()); - } - - /* Open any optional output file. */ - if (ofile == NULL) - fp = stdout; - else if ((fp = fopen(ofile, "w")) == NULL) - return (util_err(session, errno, "%s: open", ofile)); - - if (json && - (dump_json_begin(session) != 0 || - dump_prefix(session, hex, json) != 0)) - goto err; - - WT_RET(__wt_scr_alloc(session_impl, 0, &tmp)); - for (i = 0; i < argc; i++) { - if (json && i > 0) - if (dump_json_separator(session) != 0) - goto err; - free(uri); - free(simpleuri); - uri = simpleuri = NULL; - - if ((uri = util_uri(session, argv[i], "table")) == NULL) - goto err; - - WT_ERR(__wt_buf_set(session_impl, tmp, "", 0)); - if (checkpoint != NULL) - WT_ERR(__wt_buf_catfmt( - session_impl, tmp, "checkpoint=%s,", checkpoint)); - WT_ERR(__wt_buf_catfmt(session_impl, tmp, - "dump=%s", json ? "json" : (hex ? "hex" : "print"))); - if ((ret = session->open_cursor( - session, uri, NULL, (char *)tmp->data, &cursor)) != 0) { - fprintf(stderr, "%s: cursor open(%s) failed: %s\n", - progname, uri, session->strerror(session, ret)); - goto err; - } - - if ((simpleuri = strdup(uri)) == NULL) { - (void)util_err(session, errno, NULL); - goto err; - } - if ((p = strchr(simpleuri, '(')) != NULL) - *p = '\0'; - if (dump_config(session, simpleuri, cursor, hex, json) != 0) - goto err; - - if (dump_record(cursor, reverse, json) != 0) - goto err; - if (json && dump_json_table_end(session) != 0) - goto err; - - ret = cursor->close(cursor); - cursor = NULL; - if (ret != 0) { - (void)util_err(session, ret, NULL); - goto err; - } - } - if (json && dump_json_end(session) != 0) - goto err; - - if (0) { -err: ret = 1; - } - - if (cursor != NULL && (ret = cursor->close(cursor)) != 0) - ret = util_err(session, ret, NULL); - if (ofile != NULL && (ret = fclose(fp)) != 0) - ret = util_err(session, errno, NULL); - - __wt_scr_free(session_impl, &tmp); - free(uri); - free(simpleuri); - - return (ret); + WT_CURSOR *cursor; + WT_DECL_ITEM(tmp); + WT_DECL_RET; + WT_SESSION_IMPL *session_impl; + int ch, i; + char *checkpoint, *ofile, *p, *simpleuri, *uri; + bool hex, json, reverse; + + session_impl = (WT_SESSION_IMPL *)session; + + cursor = NULL; + checkpoint = ofile = simpleuri = uri = NULL; + hex = json = reverse = false; + while ((ch = __wt_getopt(progname, argc, argv, "c:f:jrx")) != EOF) + switch (ch) { + case 'c': + checkpoint = __wt_optarg; + break; + case 'f': + ofile = __wt_optarg; + break; + case 'j': + json = true; + break; + case 'r': + reverse = true; + break; + case 'x': + hex = true; + break; + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining argument is the uri. */ + if (argc < 1 || (argc != 1 && !json)) + return (usage()); + + /* -j and -x are incompatible. */ + if (hex && json) { + fprintf(stderr, "%s: the -j and -x dump options are incompatible\n", progname); + return (usage()); + } + + /* Open any optional output file. */ + if (ofile == NULL) + fp = stdout; + else if ((fp = fopen(ofile, "w")) == NULL) + return (util_err(session, errno, "%s: open", ofile)); + + if (json && (dump_json_begin(session) != 0 || dump_prefix(session, hex, json) != 0)) + goto err; + + WT_RET(__wt_scr_alloc(session_impl, 0, &tmp)); + for (i = 0; i < argc; i++) { + if (json && i > 0) + if (dump_json_separator(session) != 0) + goto err; + free(uri); + free(simpleuri); + uri = simpleuri = NULL; + + if ((uri = util_uri(session, argv[i], "table")) == NULL) + goto err; + + WT_ERR(__wt_buf_set(session_impl, tmp, "", 0)); + if (checkpoint != NULL) + WT_ERR(__wt_buf_catfmt(session_impl, tmp, "checkpoint=%s,", checkpoint)); + WT_ERR( + __wt_buf_catfmt(session_impl, tmp, "dump=%s", json ? "json" : (hex ? "hex" : "print"))); + if ((ret = session->open_cursor(session, uri, NULL, (char *)tmp->data, &cursor)) != 0) { + fprintf(stderr, "%s: cursor open(%s) failed: %s\n", progname, uri, + session->strerror(session, ret)); + goto err; + } + + if ((simpleuri = strdup(uri)) == NULL) { + (void)util_err(session, errno, NULL); + goto err; + } + if ((p = strchr(simpleuri, '(')) != NULL) + *p = '\0'; + if (dump_config(session, simpleuri, cursor, hex, json) != 0) + goto err; + + if (dump_record(cursor, reverse, json) != 0) + goto err; + if (json && dump_json_table_end(session) != 0) + goto err; + + ret = cursor->close(cursor); + cursor = NULL; + if (ret != 0) { + (void)util_err(session, ret, NULL); + goto err; + } + } + if (json && dump_json_end(session) != 0) + goto err; + + if (0) { +err: + ret = 1; + } + + if (cursor != NULL && (ret = cursor->close(cursor)) != 0) + ret = util_err(session, ret, NULL); + if (ofile != NULL && (ret = fclose(fp)) != 0) + ret = util_err(session, errno, NULL); + + __wt_scr_free(session_impl, &tmp); + free(uri); + free(simpleuri); + + return (ret); } /* * dump_config -- - * Dump the config for the uri. + * Dump the config for the uri. */ static int -dump_config(WT_SESSION *session, const char *uri, WT_CURSOR *cursor, bool hex, - bool json) +dump_config(WT_SESSION *session, const char *uri, WT_CURSOR *cursor, bool hex, bool json) { - WT_CURSOR *mcursor; - WT_DECL_RET; - int tret; - - /* Open a metadata cursor. */ - if ((ret = session->open_cursor( - session, "metadata:create", NULL, NULL, &mcursor)) != 0) { - fprintf(stderr, "%s: %s: session.open_cursor: %s\n", progname, - "metadata:create", session->strerror(session, ret)); - return (1); - } - /* - * Search for the object itself, just to make sure it exists, we don't - * want to output a header if the user entered the wrong name. This is - * where we find out a table doesn't exist, use a simple error message. - */ - mcursor->set_key(mcursor, uri); - if ((ret = mcursor->search(mcursor)) == 0) { - if ((!json && dump_prefix(session, hex, json) != 0) || - dump_table_config(session, mcursor, cursor, - uri, json) != 0 || - dump_suffix(session, json) != 0) - ret = 1; - } else if (ret == WT_NOTFOUND) - ret = util_err(session, 0, "%s: No such object exists", uri); - else - ret = util_err(session, ret, "%s", uri); - - if ((tret = mcursor->close(mcursor)) != 0) { - tret = util_cerr(mcursor, "close", tret); - if (ret == 0) - ret = tret; - } - - return (ret); + WT_CURSOR *mcursor; + WT_DECL_RET; + int tret; + + /* Open a metadata cursor. */ + if ((ret = session->open_cursor(session, "metadata:create", NULL, NULL, &mcursor)) != 0) { + fprintf(stderr, "%s: %s: session.open_cursor: %s\n", progname, "metadata:create", + session->strerror(session, ret)); + return (1); + } + /* + * Search for the object itself, just to make sure it exists, we don't want to output a header + * if the user entered the wrong name. This is where we find out a table doesn't exist, use a + * simple error message. + */ + mcursor->set_key(mcursor, uri); + if ((ret = mcursor->search(mcursor)) == 0) { + if ((!json && dump_prefix(session, hex, json) != 0) || + dump_table_config(session, mcursor, cursor, uri, json) != 0 || + dump_suffix(session, json) != 0) + ret = 1; + } else if (ret == WT_NOTFOUND) + ret = util_err(session, 0, "%s: No such object exists", uri); + else + ret = util_err(session, ret, "%s", uri); + + if ((tret = mcursor->close(mcursor)) != 0) { + tret = util_cerr(mcursor, "close", tret); + if (ret == 0) + ret = tret; + } + + return (ret); } /* * dump_json_begin -- - * Output the dump file header prefix. + * Output the dump file header prefix. */ static int dump_json_begin(WT_SESSION *session) { - if (fprintf(fp, "{\n") < 0) - return (util_err(session, EIO, NULL)); - return (0); + if (fprintf(fp, "{\n") < 0) + return (util_err(session, EIO, NULL)); + return (0); } /* * dump_json_end -- - * Output the dump file header suffix. + * Output the dump file header suffix. */ static int dump_json_end(WT_SESSION *session) { - if (fprintf(fp, "\n}\n") < 0) - return (util_err(session, EIO, NULL)); - return (0); + if (fprintf(fp, "\n}\n") < 0) + return (util_err(session, EIO, NULL)); + return (0); } /* * dump_json_begin -- - * Output a separator between two JSON outputs in a list. + * Output a separator between two JSON outputs in a list. */ static int dump_json_separator(WT_SESSION *session) { - if (fprintf(fp, ",\n") < 0) - return (util_err(session, EIO, NULL)); - return (0); + if (fprintf(fp, ",\n") < 0) + return (util_err(session, EIO, NULL)); + return (0); } /* * dump_json_table_end -- - * Output the JSON syntax that ends a table. + * Output the JSON syntax that ends a table. */ static int dump_json_table_end(WT_SESSION *session) { - if (fprintf(fp, " ]\n }\n ]") < 0) - return (util_err(session, EIO, NULL)); - return (0); + if (fprintf(fp, " ]\n }\n ]") < 0) + return (util_err(session, EIO, NULL)); + return (0); } /* @@ -257,411 +247,386 @@ dump_json_table_end(WT_SESSION *session) * Add a formatted config string to an output buffer. */ static int -dump_add_config(WT_SESSION *session, char **bufp, size_t *leftp, - const char *fmt, ...) - WT_GCC_FUNC_ATTRIBUTE((format (printf, 4, 5))) +dump_add_config(WT_SESSION *session, char **bufp, size_t *leftp, const char *fmt, ...) + WT_GCC_FUNC_ATTRIBUTE((format(printf, 4, 5))) { - WT_DECL_RET; - size_t n; - va_list ap; - - va_start(ap, fmt); - ret = __wt_vsnprintf_len_set(*bufp, *leftp, &n, fmt, ap); - va_end(ap); - if (ret != 0) - return (util_err(session, ret, NULL)); - *bufp += n; - *leftp -= n; - return (0); + WT_DECL_RET; + size_t n; + va_list ap; + + va_start(ap, fmt); + ret = __wt_vsnprintf_len_set(*bufp, *leftp, &n, fmt, ap); + va_end(ap); + if (ret != 0) + return (util_err(session, ret, NULL)); + *bufp += n; + *leftp -= n; + return (0); } /* * dump_projection -- - * Create a new config containing projection information. + * Create a new config containing projection information. */ static int -dump_projection(WT_SESSION *session, const char *config, WT_CURSOR *cursor, - char **newconfigp) +dump_projection(WT_SESSION *session, const char *config, WT_CURSOR *cursor, char **newconfigp) { - WT_CONFIG_ITEM key, value; - WT_CONFIG_PARSER *parser; - WT_DECL_RET; - WT_EXTENSION_API *wt_api; - size_t len, vallen; - int nkeys; - const char *keyformat, *p; - char *newconfig; - - len = strlen(config) + strlen(cursor->value_format) + - strlen(cursor->uri) + 20; - if ((newconfig = malloc(len)) == NULL) - return util_err(session, errno, NULL); - *newconfigp = newconfig; - wt_api = session->connection->get_extension_api(session->connection); - if ((ret = wt_api->config_parser_open(wt_api, session, config, - strlen(config), &parser)) != 0) - return (util_err( - session, ret, "WT_EXTENSION_API.config_parser_open")); - keyformat = cursor->key_format; - for (nkeys = 0; *keyformat; keyformat++) - if (!__wt_isdigit((u_char)*keyformat)) - nkeys++; - - /* - * Copy the configuration, replacing some fields to match the - * projection. - */ - while ((ret = parser->next(parser, &key, &value)) == 0) { - WT_RET(dump_add_config(session, &newconfig, &len, - "%.*s=", (int)key.len, key.str)); - if (STRING_MATCH_CONFIG("value_format", key)) - WT_RET(dump_add_config(session, &newconfig, &len, - "%s", cursor->value_format)); - else if (STRING_MATCH_CONFIG("columns", key)) { - /* copy names of keys */ - p = value.str; - vallen = value.len; - while (vallen > 0) { - if ((*p == ',' || *p == ')') && --nkeys == 0) - break; - p++; - vallen--; - } - WT_RET(dump_add_config(session, &newconfig, &len, - "%.*s", (int)(p - value.str), value.str)); - - /* copy names of projected values */ - p = strchr(cursor->uri, '('); - assert(p != NULL); - assert(p[strlen(p) - 1] == ')'); - p++; - if (*p != ')') - WT_RET(dump_add_config(session, &newconfig, - &len, "%s", ",")); - WT_RET(dump_add_config(session, &newconfig, &len, - "%.*s),", (int)(strlen(p) - 1), p)); - } else if (value.type == WT_CONFIG_ITEM_STRING && - value.len != 0) - WT_RET(dump_add_config(session, &newconfig, &len, - "\"%.*s\",", (int)value.len, value.str)); - else - WT_RET(dump_add_config(session, &newconfig, &len, - "%.*s,", (int)value.len, value.str)); - } - if (ret != WT_NOTFOUND) - return (util_err(session, ret, "WT_CONFIG_PARSER.next")); - - assert(len > 0); - if ((ret = parser->close(parser)) != 0) - return (util_err( - session, ret, "WT_CONFIG_PARSER.close")); - - return (0); + WT_CONFIG_ITEM key, value; + WT_CONFIG_PARSER *parser; + WT_DECL_RET; + WT_EXTENSION_API *wt_api; + size_t len, vallen; + int nkeys; + char *newconfig; + const char *keyformat, *p; + + len = strlen(config) + strlen(cursor->value_format) + strlen(cursor->uri) + 20; + if ((newconfig = malloc(len)) == NULL) + return util_err(session, errno, NULL); + *newconfigp = newconfig; + wt_api = session->connection->get_extension_api(session->connection); + if ((ret = wt_api->config_parser_open(wt_api, session, config, strlen(config), &parser)) != 0) + return (util_err(session, ret, "WT_EXTENSION_API.config_parser_open")); + keyformat = cursor->key_format; + for (nkeys = 0; *keyformat; keyformat++) + if (!__wt_isdigit((u_char)*keyformat)) + nkeys++; + + /* + * Copy the configuration, replacing some fields to match the projection. + */ + while ((ret = parser->next(parser, &key, &value)) == 0) { + WT_RET(dump_add_config(session, &newconfig, &len, "%.*s=", (int)key.len, key.str)); + if (STRING_MATCH_CONFIG("value_format", key)) + WT_RET(dump_add_config(session, &newconfig, &len, "%s", cursor->value_format)); + else if (STRING_MATCH_CONFIG("columns", key)) { + /* copy names of keys */ + p = value.str; + vallen = value.len; + while (vallen > 0) { + if ((*p == ',' || *p == ')') && --nkeys == 0) + break; + p++; + vallen--; + } + WT_RET( + dump_add_config(session, &newconfig, &len, "%.*s", (int)(p - value.str), value.str)); + + /* copy names of projected values */ + p = strchr(cursor->uri, '('); + assert(p != NULL); + assert(p[strlen(p) - 1] == ')'); + p++; + if (*p != ')') + WT_RET(dump_add_config(session, &newconfig, &len, "%s", ",")); + WT_RET(dump_add_config(session, &newconfig, &len, "%.*s),", (int)(strlen(p) - 1), p)); + } else if (value.type == WT_CONFIG_ITEM_STRING && value.len != 0) + WT_RET( + dump_add_config(session, &newconfig, &len, "\"%.*s\",", (int)value.len, value.str)); + else + WT_RET(dump_add_config(session, &newconfig, &len, "%.*s,", (int)value.len, value.str)); + } + if (ret != WT_NOTFOUND) + return (util_err(session, ret, "WT_CONFIG_PARSER.next")); + + assert(len > 0); + if ((ret = parser->close(parser)) != 0) + return (util_err(session, ret, "WT_CONFIG_PARSER.close")); + + return (0); } /* * dump_table_config -- - * Dump the config for a table. + * Dump the config for a table. */ static int dump_table_config( - WT_SESSION *session, WT_CURSOR *mcursor, WT_CURSOR *cursor, - const char *uri, bool json) + WT_SESSION *session, WT_CURSOR *mcursor, WT_CURSOR *cursor, const char *uri, bool json) { - WT_DECL_RET; - const char *name, *v; - char *proj_config; - - proj_config = NULL; - /* Get the table name. */ - if ((name = strchr(uri, ':')) == NULL) { - fprintf(stderr, "%s: %s: corrupted uri\n", progname, uri); - return (1); - } - ++name; - - /* - * Dump out the config information: first, dump the uri entry itself, - * it overrides all subsequent configurations. - */ - mcursor->set_key(mcursor, uri); - if ((ret = mcursor->search(mcursor)) != 0) - return (util_cerr(mcursor, "search", ret)); - if ((ret = mcursor->get_value(mcursor, &v)) != 0) - return (util_cerr(mcursor, "get_value", ret)); - - if (strchr(cursor->uri, '(') != NULL) { - WT_ERR(dump_projection(session, v, cursor, &proj_config)); - v = proj_config; - } - WT_ERR(print_config(session, uri, v, json, true)); - - WT_ERR(dump_table_parts_config( - session, mcursor, name, "colgroup:", json)); - WT_ERR(dump_table_parts_config( - session, mcursor, name, "index:", json)); - -err: free(proj_config); - return (ret); + WT_DECL_RET; + char *proj_config; + const char *name, *v; + + proj_config = NULL; + /* Get the table name. */ + if ((name = strchr(uri, ':')) == NULL) { + fprintf(stderr, "%s: %s: corrupted uri\n", progname, uri); + return (1); + } + ++name; + + /* + * Dump out the config information: first, dump the uri entry itself, it overrides all + * subsequent configurations. + */ + mcursor->set_key(mcursor, uri); + if ((ret = mcursor->search(mcursor)) != 0) + return (util_cerr(mcursor, "search", ret)); + if ((ret = mcursor->get_value(mcursor, &v)) != 0) + return (util_cerr(mcursor, "get_value", ret)); + + if (strchr(cursor->uri, '(') != NULL) { + WT_ERR(dump_projection(session, v, cursor, &proj_config)); + v = proj_config; + } + WT_ERR(print_config(session, uri, v, json, true)); + + WT_ERR(dump_table_parts_config(session, mcursor, name, "colgroup:", json)); + WT_ERR(dump_table_parts_config(session, mcursor, name, "index:", json)); + +err: + free(proj_config); + return (ret); } /* * dump_table_parts_config -- - * Dump the column groups or indices parts with a table. + * Dump the column groups or indices parts with a table. */ static int -dump_table_parts_config(WT_SESSION *session, WT_CURSOR *cursor, - const char *name, const char *entry, bool json) +dump_table_parts_config( + WT_SESSION *session, WT_CURSOR *cursor, const char *name, const char *entry, bool json) { - WT_DECL_RET; - size_t len; - int exact; - const char *groupname, *key, *sep; - char *uriprefix; - const char *v; - bool multiple; - - multiple = false; - sep = ""; - uriprefix = NULL; - - if (json) { - if (strcmp(entry, "colgroup:") == 0) { - groupname = "colgroups"; - sep = ","; - } else { - groupname = "indices"; - } - if (fprintf(fp, " \"%s\" : [", groupname) < 0) - return (util_err(session, EIO, NULL)); - } - - len = strlen(entry) + strlen(name) + 1; - if ((uriprefix = malloc(len)) == NULL) - return (util_err(session, errno, NULL)); - if ((ret = __wt_snprintf(uriprefix, len, "%s%s", entry, name)) != 0) { - free(uriprefix); - return (util_err(session, ret, NULL)); - } - - /* - * Search the file looking for column group and index key/value pairs: - * for each one, look up the related source information and append it - * to the base record, where the column group and index configuration - * overrides the source configuration. - */ - cursor->set_key(cursor, uriprefix); - ret = cursor->search_near(cursor, &exact); - free(uriprefix); - if (ret == WT_NOTFOUND) - return (0); - if (ret != 0) - return (util_cerr(cursor, "search_near", ret)); - - /* - * An exact match is only possible for column groups, and indicates - * there is an implicit (unnamed) column group. Any configuration - * for such a column group has already been folded into the - * configuration for the associated table, so it is not interesting. - */ - if (exact > 0) - goto match; - while (exact != 0 && (ret = cursor->next(cursor)) == 0) { -match: if ((ret = cursor->get_key(cursor, &key)) != 0) - return (util_cerr(cursor, "get_key", ret)); - - /* Check if we've finished the list of entries. */ - if (!WT_PREFIX_MATCH(key, entry) || - !WT_PREFIX_MATCH(key + strlen(entry), name)) - break; - - if ((ret = cursor->get_value(cursor, &v)) != 0) - return (util_cerr(cursor, "get_value", ret)); - - if (json && fprintf(fp, "%s\n", (multiple ? "," : "")) < 0) - return (util_err(session, EIO, NULL)); - /* - * The dumped configuration string is the original key plus the - * source's configuration, where the values of the original key - * override any source configurations of the same name. - */ - if (print_config(session, key, v, json, false) != 0) - return (util_err(session, EIO, NULL)); - multiple = true; - } - if (json && fprintf(fp, "%s]%s\n", - (multiple ? "\n " : ""), sep) < 0) - return (util_err(session, EIO, NULL)); - - if (ret == 0 || ret == WT_NOTFOUND) - return (0); - return (util_cerr(cursor, "next", ret)); + WT_DECL_RET; + size_t len; + int exact; + char *uriprefix; + const char *groupname, *key, *sep; + const char *v; + bool multiple; + + multiple = false; + sep = ""; + uriprefix = NULL; + + if (json) { + if (strcmp(entry, "colgroup:") == 0) { + groupname = "colgroups"; + sep = ","; + } else { + groupname = "indices"; + } + if (fprintf(fp, " \"%s\" : [", groupname) < 0) + return (util_err(session, EIO, NULL)); + } + + len = strlen(entry) + strlen(name) + 1; + if ((uriprefix = malloc(len)) == NULL) + return (util_err(session, errno, NULL)); + if ((ret = __wt_snprintf(uriprefix, len, "%s%s", entry, name)) != 0) { + free(uriprefix); + return (util_err(session, ret, NULL)); + } + + /* + * Search the file looking for column group and index key/value pairs: for each one, look up the + * related source information and append it to the base record, where the column group and index + * configuration overrides the source configuration. + */ + cursor->set_key(cursor, uriprefix); + ret = cursor->search_near(cursor, &exact); + free(uriprefix); + if (ret == WT_NOTFOUND) + return (0); + if (ret != 0) + return (util_cerr(cursor, "search_near", ret)); + + /* + * An exact match is only possible for column groups, and indicates there is an implicit + * (unnamed) column group. Any configuration for such a column group has already been folded + * into the configuration for the associated table, so it is not interesting. + */ + if (exact > 0) + goto match; + while (exact != 0 && (ret = cursor->next(cursor)) == 0) { +match: + if ((ret = cursor->get_key(cursor, &key)) != 0) + return (util_cerr(cursor, "get_key", ret)); + + /* Check if we've finished the list of entries. */ + if (!WT_PREFIX_MATCH(key, entry) || !WT_PREFIX_MATCH(key + strlen(entry), name)) + break; + + if ((ret = cursor->get_value(cursor, &v)) != 0) + return (util_cerr(cursor, "get_value", ret)); + + if (json && fprintf(fp, "%s\n", (multiple ? "," : "")) < 0) + return (util_err(session, EIO, NULL)); + /* + * The dumped configuration string is the original key plus the source's configuration, + * where the values of the original key override any source configurations of the same name. + */ + if (print_config(session, key, v, json, false) != 0) + return (util_err(session, EIO, NULL)); + multiple = true; + } + if (json && fprintf(fp, "%s]%s\n", (multiple ? "\n " : ""), sep) < 0) + return (util_err(session, EIO, NULL)); + + if (ret == 0 || ret == WT_NOTFOUND) + return (0); + return (util_cerr(cursor, "next", ret)); } /* * dump_prefix -- - * Output the dump file header prefix. + * Output the dump file header prefix. */ static int dump_prefix(WT_SESSION *session, bool hex, bool json) { - int vmajor, vminor, vpatch; + int vmajor, vminor, vpatch; - (void)wiredtiger_version(&vmajor, &vminor, &vpatch); + (void)wiredtiger_version(&vmajor, &vminor, &vpatch); - if (json && fprintf(fp, - " \"%s\" : \"%d (%d.%d.%d)\",\n", - DUMP_JSON_VERSION_MARKER, DUMP_JSON_CURRENT_VERSION, - vmajor, vminor, vpatch) < 0) - return (util_err(session, EIO, NULL)); + if (json && + fprintf(fp, " \"%s\" : \"%d (%d.%d.%d)\",\n", DUMP_JSON_VERSION_MARKER, + DUMP_JSON_CURRENT_VERSION, vmajor, vminor, vpatch) < 0) + return (util_err(session, EIO, NULL)); - if (!json && (fprintf(fp, - "WiredTiger Dump (WiredTiger Version %d.%d.%d)\n", - vmajor, vminor, vpatch) < 0 || - fprintf(fp, "Format=%s\n", hex ? "hex" : "print") < 0 || - fprintf(fp, "Header\n") < 0)) - return (util_err(session, EIO, NULL)); + if (!json && + (fprintf(fp, "WiredTiger Dump (WiredTiger Version %d.%d.%d)\n", vmajor, vminor, vpatch) < 0 || + fprintf(fp, "Format=%s\n", hex ? "hex" : "print") < 0 || fprintf(fp, "Header\n") < 0)) + return (util_err(session, EIO, NULL)); - return (0); + return (0); } /* * dump_record -- - * Dump a single record, advance cursor to next/prev, along - * with JSON formatting if needed. + * Dump a single record, advance cursor to next/prev, along with JSON formatting if needed. */ static int dump_record(WT_CURSOR *cursor, bool reverse, bool json) { - WT_DECL_RET; - WT_SESSION *session; - const char *infix, *key, *prefix, *suffix, *value; - bool once; - - session = cursor->session; - - once = false; - if (json) { - prefix = "\n{\n"; - infix = ",\n"; - suffix = "\n}"; - } else { - prefix = ""; - infix = "\n"; - suffix = "\n"; - } - while ((ret = - (reverse ? cursor->prev(cursor) : cursor->next(cursor))) == 0) { - if ((ret = cursor->get_key(cursor, &key)) != 0) - return (util_cerr(cursor, "get_key", ret)); - if ((ret = cursor->get_value(cursor, &value)) != 0) - return (util_cerr(cursor, "get_value", ret)); - if (fprintf(fp, "%s%s%s%s%s%s", json && once ? "," : "", - prefix, key, infix, value, suffix) < 0) - return (util_err(session, EIO, NULL)); - once = true; - } - if (json && once && fprintf(fp, "\n") < 0) - return (util_err(session, EIO, NULL)); - return (ret == WT_NOTFOUND ? 0 : - util_cerr(cursor, (reverse ? "prev" : "next"), ret)); + WT_DECL_RET; + WT_SESSION *session; + const char *infix, *key, *prefix, *suffix, *value; + bool once; + + session = cursor->session; + + once = false; + if (json) { + prefix = "\n{\n"; + infix = ",\n"; + suffix = "\n}"; + } else { + prefix = ""; + infix = "\n"; + suffix = "\n"; + } + while ((ret = (reverse ? cursor->prev(cursor) : cursor->next(cursor))) == 0) { + if ((ret = cursor->get_key(cursor, &key)) != 0) + return (util_cerr(cursor, "get_key", ret)); + if ((ret = cursor->get_value(cursor, &value)) != 0) + return (util_cerr(cursor, "get_value", ret)); + if (fprintf( + fp, "%s%s%s%s%s%s", json && once ? "," : "", prefix, key, infix, value, suffix) < 0) + return (util_err(session, EIO, NULL)); + once = true; + } + if (json && once && fprintf(fp, "\n") < 0) + return (util_err(session, EIO, NULL)); + return (ret == WT_NOTFOUND ? 0 : util_cerr(cursor, (reverse ? "prev" : "next"), ret)); } /* * dump_suffix -- - * Output the dump file header suffix. + * Output the dump file header suffix. */ static int dump_suffix(WT_SESSION *session, bool json) { - if (json) { - if (fprintf(fp, - " },\n" - " {\n" - " \"data\" : [") < 0) - return (util_err(session, EIO, NULL)); - } else { - if (fprintf(fp, "Data\n") < 0) - return (util_err(session, EIO, NULL)); - } - return (0); + if (json) { + if (fprintf(fp, + " },\n" + " {\n" + " \"data\" : [") < 0) + return (util_err(session, EIO, NULL)); + } else { + if (fprintf(fp, "Data\n") < 0) + return (util_err(session, EIO, NULL)); + } + return (0); } /* * dup_json_string -- - * Like strdup, but escape any characters that are special for JSON. - * The result will be embedded in a JSON string. + * Like strdup, but escape any characters that are special for JSON. The result will be embedded + * in a JSON string. */ static int dup_json_string(const char *str, char **result) { - size_t left, nchars; - const char *p; - char *q; - - nchars = 0; - for (p = str; *p; p++, nchars++) - nchars += __wt_json_unpack_char((u_char)*p, NULL, 0, false); - q = malloc(nchars + 1); - if (q == NULL) - return (1); - *result = q; - left = nchars; - for (p = str; *p; p++, nchars++) { - nchars = __wt_json_unpack_char((u_char)*p, (u_char *)q, left, - false); - left -= nchars; - q += nchars; - } - *q = '\0'; - return (0); + size_t left, nchars; + char *q; + const char *p; + + nchars = 0; + for (p = str; *p; p++, nchars++) + nchars += __wt_json_unpack_char((u_char)*p, NULL, 0, false); + q = malloc(nchars + 1); + if (q == NULL) + return (1); + *result = q; + left = nchars; + for (p = str; *p; p++, nchars++) { + nchars = __wt_json_unpack_char((u_char)*p, (u_char *)q, left, false); + left -= nchars; + q += nchars; + } + *q = '\0'; + return (0); } /* * print_config -- - * Output a key/value URI pair by combining v1 and v2. + * Output a key/value URI pair by combining v1 and v2. */ static int -print_config(WT_SESSION *session, const char *key, const char *cfg, bool json, - bool toplevel) +print_config(WT_SESSION *session, const char *key, const char *cfg, bool json, bool toplevel) { - WT_DECL_RET; - char *jsonconfig; - - /* - * We have all of the object configuration, but don't have the default - * session.create configuration. Have the underlying library add in the - * defaults and collapse it all into one load configuration string. - */ - jsonconfig = NULL; - if (json && (ret = dup_json_string(cfg, &jsonconfig)) != 0) - return (util_err(session, ret, NULL)); - - if (json) { - if (toplevel) - ret = fprintf(fp, - " \"%s\" : [\n {\n " - "\"config\" : \"%s\",\n", key, jsonconfig); - else - ret = fprintf(fp, - " {\n" - " \"uri\" : \"%s\",\n" - " \"config\" : \"%s\"\n" - " }", key, jsonconfig); - } else - ret = fprintf(fp, "%s\n%s\n", key, cfg); - free(jsonconfig); - if (ret < 0) - return (util_err(session, EIO, NULL)); - return (0); + WT_DECL_RET; + char *jsonconfig; + + /* + * We have all of the object configuration, but don't have the default session.create + * configuration. Have the underlying library add in the defaults and collapse it all into one + * load configuration string. + */ + jsonconfig = NULL; + if (json && (ret = dup_json_string(cfg, &jsonconfig)) != 0) + return (util_err(session, ret, NULL)); + + if (json) { + if (toplevel) + ret = fprintf(fp, + " \"%s\" : [\n {\n " + "\"config\" : \"%s\",\n", + key, jsonconfig); + else + ret = fprintf(fp, + " {\n" + " \"uri\" : \"%s\",\n" + " \"config\" : \"%s\"\n" + " }", + key, jsonconfig); + } else + ret = fprintf(fp, "%s\n%s\n", key, cfg); + free(jsonconfig); + if (ret < 0) + return (util_err(session, EIO, NULL)); + return (0); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "dump [-jrx] [-c checkpoint] [-f output-file] uri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "dump [-jrx] [-c checkpoint] [-f output-file] uri\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_dump.h b/src/third_party/wiredtiger/src/utilities/util_dump.h index 9d463b36121..ba649d4104c 100644 --- a/src/third_party/wiredtiger/src/utilities/util_dump.h +++ b/src/third_party/wiredtiger/src/utilities/util_dump.h @@ -6,6 +6,6 @@ * See the file LICENSE for redistribution information. */ -#define DUMP_JSON_VERSION_MARKER "WiredTiger Dump Version" -#define DUMP_JSON_CURRENT_VERSION 1 -#define DUMP_JSON_SUPPORTED_VERSION 1 +#define DUMP_JSON_VERSION_MARKER "WiredTiger Dump Version" +#define DUMP_JSON_CURRENT_VERSION 1 +#define DUMP_JSON_SUPPORTED_VERSION 1 diff --git a/src/third_party/wiredtiger/src/utilities/util_import.c b/src/third_party/wiredtiger/src/utilities/util_import.c index 995a09cfb93..f6b04398dc1 100644 --- a/src/third_party/wiredtiger/src/utilities/util_import.c +++ b/src/third_party/wiredtiger/src/utilities/util_import.c @@ -11,39 +11,39 @@ static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "import uri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "import uri\n", + progname, usage_prefix); + return (1); } int util_import(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char *uri; + WT_DECL_RET; + int ch; + char *uri; - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) - switch (ch) { - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) + switch (ch) { + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; - /* The remaining argument is the file URI. */ - if (argc != 1) - return (usage()); - if ((uri = util_uri(session, *argv, "file")) == NULL) - return (1); + /* The remaining argument is the file URI. */ + if (argc != 1) + return (usage()); + if ((uri = util_uri(session, *argv, "file")) == NULL) + return (1); - if ((ret = session->import(session, uri, NULL)) != 0) - (void)util_err(session, ret, "WT_SESSION.import: %s", uri); + if ((ret = session->import(session, uri, NULL)) != 0) + (void)util_err(session, ret, "WT_SESSION.import: %s", uri); - free(uri); - return (ret); + free(uri); + return (ret); } diff --git a/src/third_party/wiredtiger/src/utilities/util_list.c b/src/third_party/wiredtiger/src/utilities/util_list.c index ede0a91f979..00ec7c6a910 100644 --- a/src/third_party/wiredtiger/src/utilities/util_list.c +++ b/src/third_party/wiredtiger/src/utilities/util_list.c @@ -16,289 +16,277 @@ static int usage(void); int util_list(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char *uri; - bool cflag, vflag; - - cflag = vflag = false; - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "cv")) != EOF) - switch (ch) { - case 'c': - cflag = true; - break; - case 'v': - vflag = true; - break; - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; - - switch (argc) { - case 0: - break; - case 1: - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); - break; - default: - return (usage()); - } - - ret = list_print(session, uri, cflag, vflag); - - free(uri); - return (ret); + WT_DECL_RET; + int ch; + char *uri; + bool cflag, vflag; + + cflag = vflag = false; + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "cv")) != EOF) + switch (ch) { + case 'c': + cflag = true; + break; + case 'v': + vflag = true; + break; + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; + + switch (argc) { + case 0: + break; + case 1: + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); + break; + default: + return (usage()); + } + + ret = list_print(session, uri, cflag, vflag); + + free(uri); + return (ret); } /* * list_get_allocsize -- - * Get the allocation size for this file from the metadata. + * Get the allocation size for this file from the metadata. */ static int list_get_allocsize(WT_SESSION *session, const char *key, size_t *allocsize) { - WT_CONFIG_ITEM szvalue; - WT_CONFIG_PARSER *parser; - WT_DECL_RET; - WT_EXTENSION_API *wt_api; - int tret; - char *config; - - *allocsize = 0; - - parser = NULL; - config = NULL; - - wt_api = session->connection->get_extension_api(session->connection); - if ((ret = wt_api->metadata_search(wt_api, session, key, &config)) != 0) - WT_ERR(util_err( - session, ret, "%s: WT_EXTENSION_API.metadata_search", key)); - if ((ret = wt_api->config_parser_open(wt_api, session, config, - strlen(config), &parser)) != 0) - WT_ERR(util_err( - session, ret, "WT_EXTENSION_API.config_parser_open")); - if ((ret = parser->get(parser, "allocation_size", &szvalue)) == 0) - *allocsize = (size_t)szvalue.val; - else - ret = ret == WT_NOTFOUND ? - 0 : util_err(session, ret, "WT_CONFIG_PARSER.get"); + WT_CONFIG_ITEM szvalue; + WT_CONFIG_PARSER *parser; + WT_DECL_RET; + WT_EXTENSION_API *wt_api; + int tret; + char *config; + + *allocsize = 0; + + parser = NULL; + config = NULL; + + wt_api = session->connection->get_extension_api(session->connection); + if ((ret = wt_api->metadata_search(wt_api, session, key, &config)) != 0) + WT_ERR(util_err(session, ret, "%s: WT_EXTENSION_API.metadata_search", key)); + if ((ret = wt_api->config_parser_open(wt_api, session, config, strlen(config), &parser)) != 0) + WT_ERR(util_err(session, ret, "WT_EXTENSION_API.config_parser_open")); + if ((ret = parser->get(parser, "allocation_size", &szvalue)) == 0) + *allocsize = (size_t)szvalue.val; + else + ret = ret == WT_NOTFOUND ? 0 : util_err(session, ret, "WT_CONFIG_PARSER.get"); err: - if (parser != NULL && (tret = parser->close(parser)) != 0) { - tret = util_err(session, tret, "WT_CONFIG_PARSER.close"); - if (ret == 0) - ret = tret; - } - - free(config); - return (ret); + if (parser != NULL && (tret = parser->close(parser)) != 0) { + tret = util_err(session, tret, "WT_CONFIG_PARSER.close"); + if (ret == 0) + ret = tret; + } + + free(config); + return (ret); } /* * list_print -- - * List the high-level objects in the database. + * List the high-level objects in the database. */ static int list_print(WT_SESSION *session, const char *uri, bool cflag, bool vflag) { - WT_CURSOR *cursor; - WT_DECL_RET; - const char *key, *value; - bool found; - - /* Open the metadata file. */ - if ((ret = session->open_cursor( - session, WT_METADATA_URI, NULL, NULL, &cursor)) != 0) { - /* - * If there is no metadata (yet), this will return ENOENT. - * Treat that the same as an empty metadata. - */ - if (ret == ENOENT) - return (0); - - return (util_err(session, - ret, "%s: WT_SESSION.open_cursor", WT_METADATA_URI)); - } - - found = uri == NULL; - while ((ret = cursor->next(cursor)) == 0) { - /* Get the key. */ - if ((ret = cursor->get_key(cursor, &key)) != 0) - return (util_cerr(cursor, "get_key", ret)); - - /* - * If a name is specified, only show objects that match. - */ - if (uri != NULL) { - if (!WT_PREFIX_MATCH(key, uri)) - continue; - found = true; - } - - /* - * !!! - * We don't normally say anything about the WiredTiger metadata - * and lookaside tables, they're not application/user "objects" - * in the database. I'm making an exception for the checkpoint - * and verbose options. However, skip over the metadata system - * information for anything except the verbose option. - */ - if (!vflag && WT_PREFIX_MATCH(key, WT_SYSTEM_PREFIX)) - continue; - if (cflag || vflag || - (strcmp(key, WT_METADATA_URI) != 0 && - strcmp(key, WT_LAS_URI) != 0)) - printf("%s\n", key); - - if (!cflag && !vflag) - continue; - - if (cflag && (ret = list_print_checkpoint(session, key)) != 0) - return (ret); - if (vflag) { - if ((ret = cursor->get_value(cursor, &value)) != 0) - return (util_cerr(cursor, "get_value", ret)); - printf("%s\n", value); - } - } - if (ret != WT_NOTFOUND) - return (util_cerr(cursor, "next", ret)); - if (!found) { - fprintf(stderr, "%s: %s: not found\n", progname, uri); - return (1); - } - - return (0); + WT_CURSOR *cursor; + WT_DECL_RET; + const char *key, *value; + bool found; + + /* Open the metadata file. */ + if ((ret = session->open_cursor(session, WT_METADATA_URI, NULL, NULL, &cursor)) != 0) { + /* + * If there is no metadata (yet), this will return ENOENT. Treat that the same as an empty + * metadata. + */ + if (ret == ENOENT) + return (0); + + return (util_err(session, ret, "%s: WT_SESSION.open_cursor", WT_METADATA_URI)); + } + + found = uri == NULL; + while ((ret = cursor->next(cursor)) == 0) { + /* Get the key. */ + if ((ret = cursor->get_key(cursor, &key)) != 0) + return (util_cerr(cursor, "get_key", ret)); + + /* + * If a name is specified, only show objects that match. + */ + if (uri != NULL) { + if (!WT_PREFIX_MATCH(key, uri)) + continue; + found = true; + } + + /* + * !!! + * We don't normally say anything about the WiredTiger metadata + * and lookaside tables, they're not application/user "objects" + * in the database. I'm making an exception for the checkpoint + * and verbose options. However, skip over the metadata system + * information for anything except the verbose option. + */ + if (!vflag && WT_PREFIX_MATCH(key, WT_SYSTEM_PREFIX)) + continue; + if (cflag || vflag || (strcmp(key, WT_METADATA_URI) != 0 && strcmp(key, WT_LAS_URI) != 0)) + printf("%s\n", key); + + if (!cflag && !vflag) + continue; + + if (cflag && (ret = list_print_checkpoint(session, key)) != 0) + return (ret); + if (vflag) { + if ((ret = cursor->get_value(cursor, &value)) != 0) + return (util_cerr(cursor, "get_value", ret)); + printf("%s\n", value); + } + } + if (ret != WT_NOTFOUND) + return (util_cerr(cursor, "next", ret)); + if (!found) { + fprintf(stderr, "%s: %s: not found\n", progname, uri); + return (1); + } + + return (0); } /* * list_print_size -- - * List a size found in the checkpoint information. + * List a size found in the checkpoint information. */ static void list_print_size(uint64_t v) { - if (v >= WT_PETABYTE) - printf("%" PRIu64 " PB", v / WT_PETABYTE); - else if (v >= WT_TERABYTE) - printf("%" PRIu64 " TB", v / WT_TERABYTE); - else if (v >= WT_GIGABYTE) - printf("%" PRIu64 " GB", v / WT_GIGABYTE); - else if (v >= WT_MEGABYTE) - printf("%" PRIu64 " MB", v / WT_MEGABYTE); - else if (v >= WT_KILOBYTE) - printf("%" PRIu64 " KB", v / WT_KILOBYTE); - else - printf("%" PRIu64 " B", v); + if (v >= WT_PETABYTE) + printf("%" PRIu64 " PB", v / WT_PETABYTE); + else if (v >= WT_TERABYTE) + printf("%" PRIu64 " TB", v / WT_TERABYTE); + else if (v >= WT_GIGABYTE) + printf("%" PRIu64 " GB", v / WT_GIGABYTE); + else if (v >= WT_MEGABYTE) + printf("%" PRIu64 " MB", v / WT_MEGABYTE); + else if (v >= WT_KILOBYTE) + printf("%" PRIu64 " KB", v / WT_KILOBYTE); + else + printf("%" PRIu64 " B", v); } /* * list_print_checkpoint -- - * List the checkpoint information. + * List the checkpoint information. */ static int list_print_checkpoint(WT_SESSION *session, const char *key) { - WT_BLOCK_CKPT ci; - WT_CKPT *ckpt, *ckptbase; - WT_DECL_RET; - size_t allocsize, len; - time_t t; - - /* - * We may not find any checkpoints for this file, in which case we don't - * report an error, and continue our caller's loop. Otherwise, read the - * list of checkpoints and print each checkpoint's name and time. - */ - if ((ret = __wt_metadata_get_ckptlist(session, key, &ckptbase)) != 0) - return (ret == WT_NOTFOUND ? 0 : ret); - - /* We need the allocation size for decoding the checkpoint addr */ - if ((ret = list_get_allocsize(session, key, &allocsize)) != 0) - return (ret); - - /* Find the longest name, so we can pretty-print. */ - len = 0; - WT_CKPT_FOREACH(ckptbase, ckpt) - if (strlen(ckpt->name) > len) - len = strlen(ckpt->name); - ++len; - - memset(&ci, 0, sizeof(ci)); - WT_CKPT_FOREACH(ckptbase, ckpt) { - /* - * Call ctime, not ctime_r; ctime_r has portability problems, - * the Solaris version is different from the POSIX standard. - */ - if (ckpt != ckptbase) - printf("\n"); - t = (time_t)ckpt->sec; - printf("\t%*s: %.24s", (int)len, ckpt->name, ctime(&t)); - - printf(" (size "); - list_print_size(ckpt->size); - printf(")\n"); - - /* Decode the checkpoint block. */ - if (ckpt->raw.data == NULL) - continue; - if ((ret = __wt_block_ckpt_decode( - session, allocsize, ckpt->raw.data, &ci)) == 0) { - printf("\t\t" "file-size: "); - list_print_size((uint64_t)ci.file_size); - printf(", checkpoint-size: "); - list_print_size(ci.ckpt_size); - printf("\n\n"); - - printf("\t\t" " offset, size, checksum\n"); - printf( - "\t\t" "root " - ": %" PRIuMAX - ", %" PRIu32 - ", %" PRIu32 " (%#" PRIx32 ")\n", - (uintmax_t)ci.root_offset, ci.root_size, - ci.root_checksum, ci.root_checksum); - printf( - "\t\t" "alloc " - ": %" PRIuMAX - ", %" PRIu32 - ", %" PRIu32 " (%#" PRIx32 ")\n", - (uintmax_t)ci.alloc.offset, ci.alloc.size, - ci.alloc.checksum, ci.alloc.checksum); - printf( - "\t\t" "discard " - ": %" PRIuMAX - ", %" PRIu32 - ", %" PRIu32 " (%#" PRIx32 ")\n", - (uintmax_t)ci.discard.offset, ci.discard.size, - ci.discard.checksum, ci.discard.checksum); - printf( - "\t\t" "avail " - ": %" PRIuMAX - ", %" PRIu32 - ", %" PRIu32 " (%#" PRIx32 ")\n", - (uintmax_t)ci.avail.offset, ci.avail.size, - ci.avail.checksum, ci.avail.checksum); - } else { - /* Ignore the error and continue if damaged. */ - (void)util_err(session, ret, "__wt_block_ckpt_decode"); - } - } - - __wt_metadata_free_ckptlist(session, ckptbase); - return (0); + WT_BLOCK_CKPT ci; + WT_CKPT *ckpt, *ckptbase; + WT_DECL_RET; + size_t allocsize, len; + time_t t; + + /* + * We may not find any checkpoints for this file, in which case we don't report an error, and + * continue our caller's loop. Otherwise, read the list of checkpoints and print each + * checkpoint's name and time. + */ + if ((ret = __wt_metadata_get_ckptlist(session, key, &ckptbase)) != 0) + return (ret == WT_NOTFOUND ? 0 : ret); + + /* We need the allocation size for decoding the checkpoint addr */ + if ((ret = list_get_allocsize(session, key, &allocsize)) != 0) + return (ret); + + /* Find the longest name, so we can pretty-print. */ + len = 0; + WT_CKPT_FOREACH (ckptbase, ckpt) + if (strlen(ckpt->name) > len) + len = strlen(ckpt->name); + ++len; + + memset(&ci, 0, sizeof(ci)); + WT_CKPT_FOREACH (ckptbase, ckpt) { + /* + * Call ctime, not ctime_r; ctime_r has portability problems, the Solaris version is + * different from the POSIX standard. + */ + if (ckpt != ckptbase) + printf("\n"); + t = (time_t)ckpt->sec; + printf("\t%*s: %.24s", (int)len, ckpt->name, ctime(&t)); + + printf(" (size "); + list_print_size(ckpt->size); + printf(")\n"); + + /* Decode the checkpoint block. */ + if (ckpt->raw.data == NULL) + continue; + if ((ret = __wt_block_ckpt_decode(session, allocsize, ckpt->raw.data, &ci)) == 0) { + printf( + "\t\t" + "file-size: "); + list_print_size((uint64_t)ci.file_size); + printf(", checkpoint-size: "); + list_print_size(ci.ckpt_size); + printf("\n\n"); + + printf( + "\t\t" + " offset, size, checksum\n"); + printf( + "\t\t" + "root " + ": %" PRIuMAX ", %" PRIu32 ", %" PRIu32 " (%#" PRIx32 ")\n", + (uintmax_t)ci.root_offset, ci.root_size, ci.root_checksum, ci.root_checksum); + printf( + "\t\t" + "alloc " + ": %" PRIuMAX ", %" PRIu32 ", %" PRIu32 " (%#" PRIx32 ")\n", + (uintmax_t)ci.alloc.offset, ci.alloc.size, ci.alloc.checksum, ci.alloc.checksum); + printf( + "\t\t" + "discard " + ": %" PRIuMAX ", %" PRIu32 ", %" PRIu32 " (%#" PRIx32 ")\n", + (uintmax_t)ci.discard.offset, ci.discard.size, ci.discard.checksum, + ci.discard.checksum); + printf( + "\t\t" + "avail " + ": %" PRIuMAX ", %" PRIu32 ", %" PRIu32 " (%#" PRIx32 ")\n", + (uintmax_t)ci.avail.offset, ci.avail.size, ci.avail.checksum, ci.avail.checksum); + } else { + /* Ignore the error and continue if damaged. */ + (void)util_err(session, ret, "__wt_block_ckpt_decode"); + } + } + + __wt_metadata_free_ckptlist(session, ckptbase); + return (0); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "list [-cv] [uri]\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "list [-cv] [uri]\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_load.c b/src/third_party/wiredtiger/src/utilities/util_load.c index ff2c3883796..4f1d1bcb1f1 100644 --- a/src/third_party/wiredtiger/src/utilities/util_load.c +++ b/src/third_party/wiredtiger/src/utilities/util_load.c @@ -16,580 +16,558 @@ static int insert(WT_CURSOR *, const char *); static int load_dump(WT_SESSION *); static int usage(void); -static bool append = false; /* -a append (ignore number keys) */ -static char *cmdname; /* -r rename */ -static char **cmdconfig; /* configuration pairs */ -static bool json = false; /* -j input is JSON format */ -static bool no_overwrite = false; /* -n don't overwrite existing data */ +static bool append = false; /* -a append (ignore number keys) */ +static char *cmdname; /* -r rename */ +static char **cmdconfig; /* configuration pairs */ +static bool json = false; /* -j input is JSON format */ +static bool no_overwrite = false; /* -n don't overwrite existing data */ int util_load(WT_SESSION *session, int argc, char *argv[]) { - uint32_t flags; - int ch; - const char *filename; - - flags = 0; - - filename = "<stdin>"; - while ((ch = __wt_getopt(progname, argc, argv, "af:jnr:")) != EOF) - switch (ch) { - case 'a': /* append (ignore record number keys) */ - append = true; - break; - case 'f': /* input file */ - if (freopen(__wt_optarg, "r", stdin) == NULL) - return ( - util_err(session, - errno, "%s: reopen", __wt_optarg)); - else - filename = __wt_optarg; - break; - case 'j': /* input is JSON */ - json = true; - break; - case 'n': /* don't overwrite existing data */ - no_overwrite = true; - break; - case 'r': /* rename */ - cmdname = __wt_optarg; - break; - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; - - /* -a and -o are mutually exclusive. */ - if (append && no_overwrite) - return (util_err(session, EINVAL, - "the -a (append) and -n (no-overwrite) flags are mutually " - "exclusive")); - - /* The remaining arguments are configuration uri/string pairs. */ - if (argc != 0) { - if (argc % 2 != 0) - return (usage()); - cmdconfig = argv; - } - - if (json) { - if (append) - flags |= LOAD_JSON_APPEND; - if (no_overwrite) - flags |= LOAD_JSON_NO_OVERWRITE; - return (util_load_json(session, filename, flags)); - } - return (load_dump(session)); + uint32_t flags; + int ch; + const char *filename; + + flags = 0; + + filename = "<stdin>"; + while ((ch = __wt_getopt(progname, argc, argv, "af:jnr:")) != EOF) + switch (ch) { + case 'a': /* append (ignore record number keys) */ + append = true; + break; + case 'f': /* input file */ + if (freopen(__wt_optarg, "r", stdin) == NULL) + return (util_err(session, errno, "%s: reopen", __wt_optarg)); + else + filename = __wt_optarg; + break; + case 'j': /* input is JSON */ + json = true; + break; + case 'n': /* don't overwrite existing data */ + no_overwrite = true; + break; + case 'r': /* rename */ + cmdname = __wt_optarg; + break; + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; + + /* -a and -o are mutually exclusive. */ + if (append && no_overwrite) + return (util_err(session, EINVAL, + "the -a (append) and -n (no-overwrite) flags are mutually " + "exclusive")); + + /* The remaining arguments are configuration uri/string pairs. */ + if (argc != 0) { + if (argc % 2 != 0) + return (usage()); + cmdconfig = argv; + } + + if (json) { + if (append) + flags |= LOAD_JSON_APPEND; + if (no_overwrite) + flags |= LOAD_JSON_NO_OVERWRITE; + return (util_load_json(session, filename, flags)); + } + return (load_dump(session)); } /* * load_dump -- - * Load from the WiredTiger dump format. + * Load from the WiredTiger dump format. */ static int load_dump(WT_SESSION *session) { - WT_CURSOR *cursor; - WT_DECL_RET; - int tret; - char **list, **tlist, *uri, config[64]; - bool hex; - - cursor = NULL; - list = NULL; /* -Wuninitialized */ - hex = false; /* -Wuninitialized */ - uri = NULL; - - /* Read the metadata file. */ - if ((ret = config_read(session, &list, &hex)) != 0) - return (ret); - - /* Reorder and check the list. */ - if ((ret = config_reorder(session, list)) != 0) - goto err; - - /* Update the config based on any command-line configuration. */ - if ((ret = config_update(session, list)) != 0) - goto err; - - uri = list[0]; - /* Create the items in the list. */ - if ((ret = config_exec(session, list)) != 0) - goto err; - - /* Open the insert cursor. */ - if ((ret = __wt_snprintf(config, sizeof(config), - "dump=%s%s%s", - hex ? "hex" : "print", - append ? ",append" : "", - no_overwrite ? ",overwrite=false" : "")) != 0) { - ret = util_err(session, ret, NULL); - goto err; - } - if ((ret = session->open_cursor( - session, uri, NULL, config, &cursor)) != 0) { - ret = util_err(session, ret, "%s: session.open_cursor", uri); - goto err; - } - - /* - * Check the append flag (it only applies to objects where the primary - * key is a record number). - */ - if (append && !WT_STREQ(cursor->key_format, "r")) { - fprintf(stderr, - "%s: %s: -a option illegal unless the primary key is a " - "record number\n", - progname, uri); - ret = 1; - } else - ret = insert(cursor, uri); + WT_CURSOR *cursor; + WT_DECL_RET; + int tret; + char **list, **tlist, *uri, config[64]; + bool hex; + + cursor = NULL; + list = NULL; /* -Wuninitialized */ + hex = false; /* -Wuninitialized */ + uri = NULL; + + /* Read the metadata file. */ + if ((ret = config_read(session, &list, &hex)) != 0) + return (ret); + + /* Reorder and check the list. */ + if ((ret = config_reorder(session, list)) != 0) + goto err; + + /* Update the config based on any command-line configuration. */ + if ((ret = config_update(session, list)) != 0) + goto err; + + uri = list[0]; + /* Create the items in the list. */ + if ((ret = config_exec(session, list)) != 0) + goto err; + + /* Open the insert cursor. */ + if ((ret = __wt_snprintf(config, sizeof(config), "dump=%s%s%s", hex ? "hex" : "print", + append ? ",append" : "", no_overwrite ? ",overwrite=false" : "")) != 0) { + ret = util_err(session, ret, NULL); + goto err; + } + if ((ret = session->open_cursor(session, uri, NULL, config, &cursor)) != 0) { + ret = util_err(session, ret, "%s: session.open_cursor", uri); + goto err; + } + + /* + * Check the append flag (it only applies to objects where the primary key is a record number). + */ + if (append && !WT_STREQ(cursor->key_format, "r")) { + fprintf(stderr, + "%s: %s: -a option illegal unless the primary key is a " + "record number\n", + progname, uri); + ret = 1; + } else + ret = insert(cursor, uri); err: - /* - * Technically, we don't have to close the cursor because the session - * handle will do it for us, but I'd like to see the flush to disk and - * the close succeed, it's better to fail early when loading files. - */ - if (cursor != NULL && (tret = cursor->close(cursor)) != 0) { - tret = util_err(session, tret, "%s: cursor.close", uri); - if (ret == 0) - ret = tret; - } - if (ret == 0) - ret = util_flush(session, uri); - - for (tlist = list; *tlist != NULL; ++tlist) - free(*tlist); - free(list); - - return (ret == 0 ? 0 : 1); + /* + * Technically, we don't have to close the cursor because the session handle will do it for us, + * but I'd like to see the flush to disk and the close succeed, it's better to fail early when + * loading files. + */ + if (cursor != NULL && (tret = cursor->close(cursor)) != 0) { + tret = util_err(session, tret, "%s: cursor.close", uri); + if (ret == 0) + ret = tret; + } + if (ret == 0) + ret = util_flush(session, uri); + + for (tlist = list; *tlist != NULL; ++tlist) + free(*tlist); + free(list); + + return (ret == 0 ? 0 : 1); } /* * config_exec -- - * Create the tables/indices/colgroups implied by the list. + * Create the tables/indices/colgroups implied by the list. */ int config_exec(WT_SESSION *session, char **list) { - WT_DECL_RET; + WT_DECL_RET; - for (; *list != NULL; list += 2) - if ((ret = session->create(session, list[0], list[1])) != 0) - return (util_err( - session, ret, "%s: session.create", list[0])); - return (0); + for (; *list != NULL; list += 2) + if ((ret = session->create(session, list[0], list[1])) != 0) + return (util_err(session, ret, "%s: session.create", list[0])); + return (0); } /* * config_list_add -- - * Add a value to the config list. + * Add a value to the config list. */ int config_list_add(WT_SESSION *session, CONFIG_LIST *clp, char *val) { - if (clp->entry + 1 >= clp->max_entry) - if ((clp->list = realloc(clp->list, (size_t) - (clp->max_entry += 100) * sizeof(char *))) == NULL) - /* List already freed by realloc. */ - return (util_err(session, errno, NULL)); - - clp->list[clp->entry++] = val; - clp->list[clp->entry] = NULL; - return (0); + if (clp->entry + 1 >= clp->max_entry) + if ((clp->list = realloc(clp->list, (size_t)(clp->max_entry += 100) * sizeof(char *))) == + NULL) + /* List already freed by realloc. */ + return (util_err(session, errno, NULL)); + + clp->list[clp->entry++] = val; + clp->list[clp->entry] = NULL; + return (0); } /* * config_list_free -- - * Free the list and any of its entries. + * Free the list and any of its entries. */ void config_list_free(CONFIG_LIST *clp) { - char **entry; - - if (clp->list != NULL) - for (entry = &clp->list[0]; *entry != NULL; entry++) - free(*entry); - free(clp->list); - clp->list = NULL; - clp->entry = 0; - clp->max_entry = 0; + char **entry; + + if (clp->list != NULL) + for (entry = &clp->list[0]; *entry != NULL; entry++) + free(*entry); + free(clp->list); + clp->list = NULL; + clp->entry = 0; + clp->max_entry = 0; } /* * config_read -- - * Read the config lines and do some basic validation. + * Read the config lines and do some basic validation. */ static int config_read(WT_SESSION *session, char ***listp, bool *hexp) { - ULINE l; - WT_DECL_RET; - int entry, max_entry; - bool eof; - const char *s; - char **list, **tlist; - - list = NULL; - memset(&l, 0, sizeof(l)); - - /* Header line #1: "WiredTiger Dump" and a WiredTiger version. */ - if ((ret = util_read_line(session, &l, false, &eof)) != 0) - goto err; - s = "WiredTiger Dump "; - if (strncmp(l.mem, s, strlen(s)) != 0) { - ret = format(session); - goto err; - } - - /* Header line #2: "Format={hex,print}". */ - if ((ret = util_read_line(session, &l, false, &eof)) != 0) - goto err; - if (strcmp(l.mem, "Format=print") == 0) - *hexp = false; - else if (strcmp(l.mem, "Format=hex") == 0) - *hexp = true; - else { - ret = format(session); - goto err; - } - - /* Header line #3: "Header". */ - if ((ret = util_read_line(session, &l, false, &eof)) != 0) - goto err; - if (strcmp(l.mem, "Header") != 0) { - ret = format(session); - goto err; - } - - /* Now, read in lines until we get to the end of the headers. */ - for (entry = max_entry = 0, list = NULL;; ++entry) { - if ((ret = util_read_line(session, &l, false, &eof)) != 0) - goto err; - if (strcmp(l.mem, "Data") == 0) - break; - - /* - * Grow the array of header lines as necessary -- we need an - * extra slot for NULL termination. - */ - if (entry + 1 >= max_entry) { - if ((tlist = realloc(list, (size_t) - (max_entry += 100) * sizeof(char *))) == NULL) { - ret = util_err(session, errno, NULL); - - /* - * List already freed by realloc, still use err - * label for consistency. - */ - list = NULL; - goto err; - } - list = tlist; - } - if ((list[entry] = strdup(l.mem)) == NULL) { - ret = util_err(session, errno, NULL); - goto err; - } - list[entry + 1] = NULL; - } - - /* Headers are required, and they're supposed to be in pairs. */ - if (list == NULL || entry % 2 != 0) { - ret = format(session); - goto err; - } - *listp = list; - - free(l.mem); - return (0); - -err: if (list != NULL) { - for (tlist = list; *tlist != NULL; ++tlist) - free(*tlist); - free(list); - } - free(l.mem); - return (ret); + ULINE l; + WT_DECL_RET; + int entry, max_entry; + bool eof; + const char *s; + char **list, **tlist; + + list = NULL; + memset(&l, 0, sizeof(l)); + + /* Header line #1: "WiredTiger Dump" and a WiredTiger version. */ + if ((ret = util_read_line(session, &l, false, &eof)) != 0) + goto err; + s = "WiredTiger Dump "; + if (strncmp(l.mem, s, strlen(s)) != 0) { + ret = format(session); + goto err; + } + + /* Header line #2: "Format={hex,print}". */ + if ((ret = util_read_line(session, &l, false, &eof)) != 0) + goto err; + if (strcmp(l.mem, "Format=print") == 0) + *hexp = false; + else if (strcmp(l.mem, "Format=hex") == 0) + *hexp = true; + else { + ret = format(session); + goto err; + } + + /* Header line #3: "Header". */ + if ((ret = util_read_line(session, &l, false, &eof)) != 0) + goto err; + if (strcmp(l.mem, "Header") != 0) { + ret = format(session); + goto err; + } + + /* Now, read in lines until we get to the end of the headers. */ + for (entry = max_entry = 0, list = NULL;; ++entry) { + if ((ret = util_read_line(session, &l, false, &eof)) != 0) + goto err; + if (strcmp(l.mem, "Data") == 0) + break; + + /* + * Grow the array of header lines as necessary -- we need an extra slot for NULL + * termination. + */ + if (entry + 1 >= max_entry) { + if ((tlist = realloc(list, (size_t)(max_entry += 100) * sizeof(char *))) == NULL) { + ret = util_err(session, errno, NULL); + + /* + * List already freed by realloc, still use err label for consistency. + */ + list = NULL; + goto err; + } + list = tlist; + } + if ((list[entry] = strdup(l.mem)) == NULL) { + ret = util_err(session, errno, NULL); + goto err; + } + list[entry + 1] = NULL; + } + + /* Headers are required, and they're supposed to be in pairs. */ + if (list == NULL || entry % 2 != 0) { + ret = format(session); + goto err; + } + *listp = list; + + free(l.mem); + return (0); + +err: + if (list != NULL) { + for (tlist = list; *tlist != NULL; ++tlist) + free(*tlist); + free(list); + } + free(l.mem); + return (ret); } /* * config_reorder -- - * For table dumps, reorder the list so tables are first. - * For other dumps, make any needed checks. + * For table dumps, reorder the list so tables are first. For other dumps, make any needed + * checks. */ int config_reorder(WT_SESSION *session, char **list) { - char **entry, *p; - - /* - * Search for a table name -- if we find one, then it's table dump, - * otherwise, it's a single file dump. - */ - for (entry = list; *entry != NULL; ++entry) - if (WT_PREFIX_MATCH(*entry, "table:")) - break; - if (*entry == NULL) { - /* - * Single file dumps can only have two lines, the file name and - * the configuration information. - */ - if ((list[0] == NULL || list[1] == NULL || list[2] != NULL) || - (WT_PREFIX_MATCH(list[0], "file:") && - WT_PREFIX_MATCH(list[0], "lsm:"))) - return (format(session)); - - entry = list; - } - - /* - * Make sure the table key/value pair comes first, then we can just - * run through the array in order. (We already checked that we had - * a multiple of 2 entries, so this is safe.) - */ - if (entry != list) { - p = list[0]; list[0] = entry[0]; entry[0] = p; - p = list[1]; list[1] = entry[1]; entry[1] = p; - } - return (0); + char **entry, *p; + + /* + * Search for a table name -- if we find one, then it's table dump, otherwise, it's a single + * file dump. + */ + for (entry = list; *entry != NULL; ++entry) + if (WT_PREFIX_MATCH(*entry, "table:")) + break; + if (*entry == NULL) { + /* + * Single file dumps can only have two lines, the file name and the configuration + * information. + */ + if ((list[0] == NULL || list[1] == NULL || list[2] != NULL) || + (WT_PREFIX_MATCH(list[0], "file:") && WT_PREFIX_MATCH(list[0], "lsm:"))) + return (format(session)); + + entry = list; + } + + /* + * Make sure the table key/value pair comes first, then we can just run through the array in + * order. (We already checked that we had a multiple of 2 entries, so this is safe.) + */ + if (entry != list) { + p = list[0]; + list[0] = entry[0]; + entry[0] = p; + p = list[1]; + list[1] = entry[1]; + entry[1] = p; + } + return (0); } /* * config_update -- - * Reconcile and update the command line configuration against the - * config we found. + * Reconcile and update the command line configuration against the config we found. */ int config_update(WT_SESSION *session, char **list) { - WT_DECL_RET; - size_t cnt; - int found; - char **configp, **listp; - const char *p, **cfg; - - /* - * If the object has been renamed, replace all of the column group, - * index, file and table names with the new name. - */ - if (cmdname != NULL) { - for (listp = list; *listp != NULL; listp += 2) - if (WT_PREFIX_MATCH(*listp, "colgroup:") || - WT_PREFIX_MATCH(*listp, "file:") || - WT_PREFIX_MATCH(*listp, "index:") || - WT_PREFIX_MATCH(*listp, "lsm:") || - WT_PREFIX_MATCH(*listp, "table:")) - if (config_rename(session, listp, cmdname)) - return (1); - - /* - * If the object was renamed, and there are configuration pairs, - * rename the configuration pairs as well, because we don't know - * if the user used the old or new names for the pair's URI. - */ - for (configp = cmdconfig; - cmdconfig != NULL && *configp != NULL; configp += 2) - if (config_rename(session, configp, cmdname)) - return (1); - } - - /* - * Updating the key/value formats seems like an easy mistake to make. - * If there were command-line configuration pairs, walk the list of - * command-line configuration strings and check. - */ - for (configp = cmdconfig; - configp != NULL && *configp != NULL; configp += 2) - if (strstr(configp[1], "key_format=") || - strstr(configp[1], "value_format=")) - return (util_err(session, 0, - "an object's key or value format may not be " - "modified")); - - /* - * If there were command-line configuration pairs, walk the list of - * command-line URIs and find a matching dump URI. It is an error - * if a command-line URI doesn't find a single, exact match, that's - * likely a mistake. - */ - for (configp = cmdconfig; - configp != NULL && *configp != NULL; configp += 2) { - for (found = 0, listp = list; *listp != NULL; listp += 2) - if (strncmp(*configp, listp[0], strlen(*configp)) == 0) - ++found; - switch (found) { - case 0: - return (util_err(session, 0, - "the command line object name %s was not matched " - "by any loaded object name", *configp)); - case 1: - break; - default: - return (util_err(session, 0, - "the command line object name %s was not unique, " - "matching more than a single loaded object name", - *configp)); - } - } - - /* - * Allocate a big enough configuration stack to hold all of the command - * line arguments, a list of configuration values to remove, and the - * base configuration values, plus some slop. - */ - for (cnt = 0, configp = cmdconfig; - cmdconfig != NULL && *configp != NULL; configp += 2) - ++cnt; - if ((cfg = calloc(cnt + 10, sizeof(cfg[0]))) == NULL) - return (util_err(session, errno, NULL)); - - /* - * For each match, rewrite the dump configuration as described by any - * command-line configuration arguments. - * - * New filenames will be chosen as part of the table load, remove all - * "filename=", "source=" and other configurations that foil loading - * from the values; we call an unpublished API to do the work. - */ - for (listp = list; *listp != NULL; listp += 2) { - cnt = 0; - cfg[cnt++] = listp[1]; - for (configp = cmdconfig; - cmdconfig != NULL && *configp != NULL; configp += 2) - if (strncmp(*configp, listp[0], strlen(*configp)) == 0) - cfg[cnt++] = configp[1]; - cfg[cnt++] = NULL; - - if ((ret = __wt_config_merge((WT_SESSION_IMPL *)session, - cfg, - "filename=,id=," - "checkpoint=,checkpoint_lsn=,version=,source=,", - &p)) != 0) - break; - - free(listp[1]); - listp[1] = (char *)p; - } - free(cfg); - return (ret); + WT_DECL_RET; + size_t cnt; + int found; + char **configp, **listp; + const char *p, **cfg; + + /* + * If the object has been renamed, replace all of the column group, index, file and table names + * with the new name. + */ + if (cmdname != NULL) { + for (listp = list; *listp != NULL; listp += 2) + if (WT_PREFIX_MATCH(*listp, "colgroup:") || WT_PREFIX_MATCH(*listp, "file:") || + WT_PREFIX_MATCH(*listp, "index:") || WT_PREFIX_MATCH(*listp, "lsm:") || + WT_PREFIX_MATCH(*listp, "table:")) + if (config_rename(session, listp, cmdname)) + return (1); + + /* + * If the object was renamed, and there are configuration pairs, rename the configuration + * pairs as well, because we don't know if the user used the old or new names for the pair's + * URI. + */ + for (configp = cmdconfig; cmdconfig != NULL && *configp != NULL; configp += 2) + if (config_rename(session, configp, cmdname)) + return (1); + } + + /* + * Updating the key/value formats seems like an easy mistake to make. If there were command-line + * configuration pairs, walk the list of command-line configuration strings and check. + */ + for (configp = cmdconfig; configp != NULL && *configp != NULL; configp += 2) + if (strstr(configp[1], "key_format=") || strstr(configp[1], "value_format=")) + return (util_err(session, 0, + "an object's key or value format may not be " + "modified")); + + /* + * If there were command-line configuration pairs, walk the list of command-line URIs and find a + * matching dump URI. It is an error if a command-line URI doesn't find a single, exact match, + * that's likely a mistake. + */ + for (configp = cmdconfig; configp != NULL && *configp != NULL; configp += 2) { + for (found = 0, listp = list; *listp != NULL; listp += 2) + if (strncmp(*configp, listp[0], strlen(*configp)) == 0) + ++found; + switch (found) { + case 0: + return (util_err(session, 0, + "the command line object name %s was not matched " + "by any loaded object name", + *configp)); + case 1: + break; + default: + return (util_err(session, 0, + "the command line object name %s was not unique, " + "matching more than a single loaded object name", + *configp)); + } + } + + /* + * Allocate a big enough configuration stack to hold all of the command line arguments, a list + * of configuration values to remove, and the base configuration values, plus some slop. + */ + for (cnt = 0, configp = cmdconfig; cmdconfig != NULL && *configp != NULL; configp += 2) + ++cnt; + if ((cfg = calloc(cnt + 10, sizeof(cfg[0]))) == NULL) + return (util_err(session, errno, NULL)); + + /* + * For each match, rewrite the dump configuration as described by any + * command-line configuration arguments. + * + * New filenames will be chosen as part of the table load, remove all + * "filename=", "source=" and other configurations that foil loading + * from the values; we call an unpublished API to do the work. + */ + for (listp = list; *listp != NULL; listp += 2) { + cnt = 0; + cfg[cnt++] = listp[1]; + for (configp = cmdconfig; cmdconfig != NULL && *configp != NULL; configp += 2) + if (strncmp(*configp, listp[0], strlen(*configp)) == 0) + cfg[cnt++] = configp[1]; + cfg[cnt++] = NULL; + + if ((ret = __wt_config_merge((WT_SESSION_IMPL *)session, cfg, + "filename=,id=," + "checkpoint=,checkpoint_lsn=,version=,source=,", + &p)) != 0) + break; + + free(listp[1]); + listp[1] = (char *)p; + } + free(cfg); + return (ret); } /* * config_rename -- - * Update the URI name. + * Update the URI name. */ static int config_rename(WT_SESSION *session, char **urip, const char *name) { - WT_DECL_RET; - size_t len; - char *buf, *p; - - /* Allocate room. */ - len = strlen(*urip) + strlen(name) + 10; - if ((buf = malloc(len)) == NULL) - return (util_err(session, errno, NULL)); - - /* - * Find the separating colon characters, but note the trailing one may - * not be there. - */ - if ((p = strchr(*urip, ':')) == NULL) { - free(buf); - return (format(session)); - } - *p = '\0'; - p = strchr(p + 1, ':'); - if ((ret = __wt_snprintf( - buf, len, "%s:%s%s", *urip, name, p == NULL ? "" : p)) != 0) { - free(buf); - return (util_err(session, ret, NULL)); - } - *urip = buf; - - return (0); + WT_DECL_RET; + size_t len; + char *buf, *p; + + /* Allocate room. */ + len = strlen(*urip) + strlen(name) + 10; + if ((buf = malloc(len)) == NULL) + return (util_err(session, errno, NULL)); + + /* + * Find the separating colon characters, but note the trailing one may not be there. + */ + if ((p = strchr(*urip, ':')) == NULL) { + free(buf); + return (format(session)); + } + *p = '\0'; + p = strchr(p + 1, ':'); + if ((ret = __wt_snprintf(buf, len, "%s:%s%s", *urip, name, p == NULL ? "" : p)) != 0) { + free(buf); + return (util_err(session, ret, NULL)); + } + *urip = buf; + + return (0); } /* * format -- - * The input doesn't match the dump format. + * The input doesn't match the dump format. */ static int format(WT_SESSION *session) { - return (util_err( - session, 0, "input does not match WiredTiger dump format")); + return (util_err(session, 0, "input does not match WiredTiger dump format")); } /* * insert -- - * Read and insert data. + * Read and insert data. */ static int insert(WT_CURSOR *cursor, const char *name) { - ULINE key, value; - WT_DECL_RET; - WT_SESSION *session; - uint64_t insert_count; - bool eof; - - session = cursor->session; - - memset(&key, 0, sizeof(key)); - memset(&value, 0, sizeof(value)); - - /* Read key/value pairs and insert them into the file. */ - for (insert_count = 0;;) { - /* - * Three modes: in row-store, we always read a key and use it, - * in column-store, we might read it (a dump), we might read - * and ignore it (a dump with "append" set), or not read it at - * all (flat-text load). - */ - if ((ret = util_read_line(session, &key, true, &eof)) != 0) - goto err; - if (eof) - break; - if (!append) - cursor->set_key(cursor, key.mem); - - if ((ret = util_read_line(session, &value, false, &eof)) != 0) - goto err; - cursor->set_value(cursor, value.mem); - - if ((ret = cursor->insert(cursor)) != 0) { - ret = util_err(session, ret, "%s: cursor.insert", name); - goto err; - } - - /* Report on progress every 100 inserts. */ - if (verbose && ++insert_count % 100 == 0) { - printf("\r\t%s: %" PRIu64, name, insert_count); - fflush(stdout); - } - } - - if (verbose) - printf("\r\t%s: %" PRIu64 "\n", name, insert_count); - -err: free(key.mem); - free(value.mem); - - return (ret); + ULINE key, value; + WT_DECL_RET; + WT_SESSION *session; + uint64_t insert_count; + bool eof; + + session = cursor->session; + + memset(&key, 0, sizeof(key)); + memset(&value, 0, sizeof(value)); + + /* Read key/value pairs and insert them into the file. */ + for (insert_count = 0;;) { + /* + * Three modes: in row-store, we always read a key and use it, in column-store, we might + * read it (a dump), we might read and ignore it (a dump with "append" set), or not read it + * at all (flat-text load). + */ + if ((ret = util_read_line(session, &key, true, &eof)) != 0) + goto err; + if (eof) + break; + if (!append) + cursor->set_key(cursor, key.mem); + + if ((ret = util_read_line(session, &value, false, &eof)) != 0) + goto err; + cursor->set_value(cursor, value.mem); + + if ((ret = cursor->insert(cursor)) != 0) { + ret = util_err(session, ret, "%s: cursor.insert", name); + goto err; + } + + /* Report on progress every 100 inserts. */ + if (verbose && ++insert_count % 100 == 0) { + printf("\r\t%s: %" PRIu64, name, insert_count); + fflush(stdout); + } + } + + if (verbose) + printf("\r\t%s: %" PRIu64 "\n", name, insert_count); + +err: + free(key.mem); + free(value.mem); + + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "load [-as] [-f input-file] [-r name] [object configuration ...]\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "load [-as] [-f input-file] [-r name] [object configuration ...]\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_load.h b/src/third_party/wiredtiger/src/utilities/util_load.h index 6056157c829..215c5754c1a 100644 --- a/src/third_party/wiredtiger/src/utilities/util_load.h +++ b/src/third_party/wiredtiger/src/utilities/util_load.h @@ -10,21 +10,21 @@ * A list of configuration strings. */ typedef struct { - char **list; /* array of alternating (uri, config) values */ - int entry; /* next entry available in list */ - int max_entry; /* how many allocated in list */ + char **list; /* array of alternating (uri, config) values */ + int entry; /* next entry available in list */ + int max_entry; /* how many allocated in list */ } CONFIG_LIST; -int config_exec(WT_SESSION *, char **); -int config_list_add(WT_SESSION *, CONFIG_LIST *, char *); -void config_list_free(CONFIG_LIST *); -int config_reorder(WT_SESSION *, char **); -int config_update(WT_SESSION *, char **); +int config_exec(WT_SESSION *, char **); +int config_list_add(WT_SESSION *, CONFIG_LIST *, char *); +void config_list_free(CONFIG_LIST *); +int config_reorder(WT_SESSION *, char **); +int config_update(WT_SESSION *, char **); /* Flags for util_load_json */ /* AUTOMATIC FLAG VALUE GENERATION START */ -#define LOAD_JSON_APPEND 0x1u /* append (ignore record number keys) */ -#define LOAD_JSON_NO_OVERWRITE 0x2u /* don't overwrite existing data */ +#define LOAD_JSON_APPEND 0x1u /* append (ignore record number keys) */ +#define LOAD_JSON_NO_OVERWRITE 0x2u /* don't overwrite existing data */ /* AUTOMATIC FLAG VALUE GENERATION STOP */ -int util_load_json(WT_SESSION *, const char *, uint32_t); +int util_load_json(WT_SESSION *, const char *, uint32_t); diff --git a/src/third_party/wiredtiger/src/utilities/util_load_json.c b/src/third_party/wiredtiger/src/utilities/util_load_json.c index 555704e3822..2e97c7aed0e 100644 --- a/src/third_party/wiredtiger/src/utilities/util_load_json.c +++ b/src/third_party/wiredtiger/src/utilities/util_load_json.c @@ -26,589 +26,558 @@ * The raw key/value string is collected in the kvraw field. */ typedef struct { - WT_SESSION *session; /* associated session */ - ULINE line; /* current line */ - const char *p; /* points to cur position in line.mem */ - bool ateof; /* current token is EOF */ - bool peeking; /* peeking at next token */ - int toktype; /* next token, defined by __wt_json_token() */ - const char *tokstart; /* next token start (points into line.mem) */ - size_t toklen; /* next token length */ - char *kvraw; /* multiple line raw content collected so far */ - size_t kvrawstart; /* pos on cur line that JSON key/value starts */ - const char *filename; /* filename for error reporting */ - int linenum; /* line number for error reporting */ + WT_SESSION *session; /* associated session */ + ULINE line; /* current line */ + const char *p; /* points to cur position in line.mem */ + bool ateof; /* current token is EOF */ + bool peeking; /* peeking at next token */ + int toktype; /* next token, defined by __wt_json_token() */ + const char *tokstart; /* next token start (points into line.mem) */ + size_t toklen; /* next token length */ + char *kvraw; /* multiple line raw content collected so far */ + size_t kvrawstart; /* pos on cur line that JSON key/value starts */ + const char *filename; /* filename for error reporting */ + int linenum; /* line number for error reporting */ } JSON_INPUT_STATE; -static int json_column_group_index(WT_SESSION *, JSON_INPUT_STATE *, - CONFIG_LIST *, int); +static int json_column_group_index(WT_SESSION *, JSON_INPUT_STATE *, CONFIG_LIST *, int); static int json_data(WT_SESSION *, JSON_INPUT_STATE *, CONFIG_LIST *, uint32_t); static int json_expect(WT_SESSION *, JSON_INPUT_STATE *, int); static int json_peek(WT_SESSION *, JSON_INPUT_STATE *); static int json_skip(WT_SESSION *, JSON_INPUT_STATE *, const char **); -static int json_kvraw_append( - WT_SESSION *, JSON_INPUT_STATE *, const char *, size_t); +static int json_kvraw_append(WT_SESSION *, JSON_INPUT_STATE *, const char *, size_t); static int json_strdup(WT_SESSION *, JSON_INPUT_STATE *, char **); static int json_top_level(WT_SESSION *, JSON_INPUT_STATE *, uint32_t); -#define JSON_STRING_MATCH(ins, match) \ - ((ins)->toklen - 2 == strlen(match) && \ - strncmp((ins)->tokstart + 1, (match), (ins)->toklen - 2) == 0) +#define JSON_STRING_MATCH(ins, match) \ + ((ins)->toklen - 2 == strlen(match) && \ + strncmp((ins)->tokstart + 1, (match), (ins)->toklen - 2) == 0) -#define JSON_INPUT_POS(ins) \ - ((size_t)((ins)->p - (const char *)(ins)->line.mem)) +#define JSON_INPUT_POS(ins) ((size_t)((ins)->p - (const char *)(ins)->line.mem)) -#define JSON_EXPECT(session, ins, tok) do { \ - if (json_expect(session, ins, tok)) \ - goto err; \ -} while (0) +#define JSON_EXPECT(session, ins, tok) \ + do { \ + if (json_expect(session, ins, tok)) \ + goto err; \ + } while (0) /* * json_column_group_index -- - * Parse a column group or index entry from JSON input. + * Parse a column group or index entry from JSON input. */ static int -json_column_group_index(WT_SESSION *session, - JSON_INPUT_STATE *ins, CONFIG_LIST *clp, int idx) +json_column_group_index(WT_SESSION *session, JSON_INPUT_STATE *ins, CONFIG_LIST *clp, int idx) { - WT_DECL_RET; - char *config, *p, *uri; - bool isconfig; - - uri = NULL; - config = NULL; - - while (json_peek(session, ins) == '{') { - JSON_EXPECT(session, ins, '{'); - JSON_EXPECT(session, ins, 's'); - isconfig = JSON_STRING_MATCH(ins, "config"); - if (!isconfig && !JSON_STRING_MATCH(ins, "uri")) - goto err; - JSON_EXPECT(session, ins, ':'); - JSON_EXPECT(session, ins, 's'); - - if ((ret = json_strdup(session, ins, &p)) != 0) { - ret = util_err(session, ret, NULL); - goto err; - } - if (isconfig) - config = p; - else - uri = p; - - isconfig = !isconfig; - JSON_EXPECT(session, ins, ','); - JSON_EXPECT(session, ins, 's'); - if (!JSON_STRING_MATCH(ins, isconfig ? "config" : "uri")) - goto err; - JSON_EXPECT(session, ins, ':'); - JSON_EXPECT(session, ins, 's'); - - if ((ret = json_strdup(session, ins, &p)) != 0) { - ret = util_err(session, ret, NULL); - goto err; - } - if (isconfig) - config = p; - else - uri = p; - JSON_EXPECT(session, ins, '}'); - if ((idx && strncmp(uri, "index:", 6) != 0) || - (!idx && strncmp(uri, "colgroup:", 9) != 0)) { - ret = util_err(session, EINVAL, - "%s: misplaced colgroup or index", uri); - goto err; - } - if ((ret = config_list_add(session, clp, uri)) != 0 || - (ret = config_list_add(session, clp, config)) != 0) - goto err; - - if (json_peek(session, ins) != ',') - break; - JSON_EXPECT(session, ins, ','); - if (json_peek(session, ins) != '{') - goto err; - } - if (0) { -err: if (ret == 0) - ret = EINVAL; - } - return (ret); + WT_DECL_RET; + char *config, *p, *uri; + bool isconfig; + + uri = NULL; + config = NULL; + + while (json_peek(session, ins) == '{') { + JSON_EXPECT(session, ins, '{'); + JSON_EXPECT(session, ins, 's'); + isconfig = JSON_STRING_MATCH(ins, "config"); + if (!isconfig && !JSON_STRING_MATCH(ins, "uri")) + goto err; + JSON_EXPECT(session, ins, ':'); + JSON_EXPECT(session, ins, 's'); + + if ((ret = json_strdup(session, ins, &p)) != 0) { + ret = util_err(session, ret, NULL); + goto err; + } + if (isconfig) + config = p; + else + uri = p; + + isconfig = !isconfig; + JSON_EXPECT(session, ins, ','); + JSON_EXPECT(session, ins, 's'); + if (!JSON_STRING_MATCH(ins, isconfig ? "config" : "uri")) + goto err; + JSON_EXPECT(session, ins, ':'); + JSON_EXPECT(session, ins, 's'); + + if ((ret = json_strdup(session, ins, &p)) != 0) { + ret = util_err(session, ret, NULL); + goto err; + } + if (isconfig) + config = p; + else + uri = p; + JSON_EXPECT(session, ins, '}'); + if ((idx && strncmp(uri, "index:", 6) != 0) || + (!idx && strncmp(uri, "colgroup:", 9) != 0)) { + ret = util_err(session, EINVAL, "%s: misplaced colgroup or index", uri); + goto err; + } + if ((ret = config_list_add(session, clp, uri)) != 0 || + (ret = config_list_add(session, clp, config)) != 0) + goto err; + + if (json_peek(session, ins) != ',') + break; + JSON_EXPECT(session, ins, ','); + if (json_peek(session, ins) != '{') + goto err; + } + if (0) { +err: + if (ret == 0) + ret = EINVAL; + } + return (ret); } /* * json_kvraw_append -- - * Append to the kvraw buffer, which is used to collect all the - * raw key/value pairs from JSON input. + * Append to the kvraw buffer, which is used to collect all the raw key/value pairs from JSON + * input. */ static int -json_kvraw_append(WT_SESSION *session, - JSON_INPUT_STATE *ins, const char *str, size_t len) +json_kvraw_append(WT_SESSION *session, JSON_INPUT_STATE *ins, const char *str, size_t len) { - WT_DECL_RET; - size_t needsize; - char *tmp; - - if (len > 0) { - needsize = strlen(ins->kvraw) + len + 2; - if ((tmp = malloc(needsize)) == NULL) - return (util_err(session, errno, NULL)); - WT_ERR(__wt_snprintf( - tmp, needsize, "%s %.*s", ins->kvraw, (int)len, str)); - free(ins->kvraw); - ins->kvraw = tmp; - } - return (0); - -err: free(tmp); - return (util_err(session, ret, NULL)); + WT_DECL_RET; + size_t needsize; + char *tmp; + + if (len > 0) { + needsize = strlen(ins->kvraw) + len + 2; + if ((tmp = malloc(needsize)) == NULL) + return (util_err(session, errno, NULL)); + WT_ERR(__wt_snprintf(tmp, needsize, "%s %.*s", ins->kvraw, (int)len, str)); + free(ins->kvraw); + ins->kvraw = tmp; + } + return (0); + +err: + free(tmp); + return (util_err(session, ret, NULL)); } /* * json_strdup -- - * Return a string, with no escapes or other JSON-isms, from the - * JSON string at the current input position. + * Return a string, with no escapes or other JSON-isms, from the JSON string at the current + * input position. */ static int json_strdup(WT_SESSION *session, JSON_INPUT_STATE *ins, char **resultp) { - WT_DECL_RET; - size_t srclen; - ssize_t resultlen; - char *result, *resultcpy; - const char *src; - - result = NULL; - src = ins->tokstart + 1; /*strip "" from token */ - srclen = ins->toklen - 2; - if ((resultlen = __wt_json_strlen(src, srclen)) < 0) { - ret = util_err(session, EINVAL, "Invalid config string"); - goto err; - } - resultlen += 1; - if ((result = malloc((size_t)resultlen)) == NULL) { - ret = util_err(session, errno, NULL); - goto err; - } - *resultp = result; - resultcpy = result; - if ((ret = __wt_json_strncpy( - session, &resultcpy, (size_t)resultlen, src, srclen)) != 0) { - ret = util_err(session, ret, NULL); - goto err; - } - - if (0) { -err: if (ret == 0) - ret = EINVAL; - free(result); - *resultp = NULL; - } - return (ret); + WT_DECL_RET; + size_t srclen; + ssize_t resultlen; + char *result, *resultcpy; + const char *src; + + result = NULL; + src = ins->tokstart + 1; /*strip "" from token */ + srclen = ins->toklen - 2; + if ((resultlen = __wt_json_strlen(src, srclen)) < 0) { + ret = util_err(session, EINVAL, "Invalid config string"); + goto err; + } + resultlen += 1; + if ((result = malloc((size_t)resultlen)) == NULL) { + ret = util_err(session, errno, NULL); + goto err; + } + *resultp = result; + resultcpy = result; + if ((ret = __wt_json_strncpy(session, &resultcpy, (size_t)resultlen, src, srclen)) != 0) { + ret = util_err(session, ret, NULL); + goto err; + } + + if (0) { +err: + if (ret == 0) + ret = EINVAL; + free(result); + *resultp = NULL; + } + return (ret); } /* * json_data -- - * Parse the data portion of the JSON input, and insert all - * values. + * Parse the data portion of the JSON input, and insert all values. */ static int -json_data(WT_SESSION *session, - JSON_INPUT_STATE *ins, CONFIG_LIST *clp, uint32_t flags) +json_data(WT_SESSION *session, JSON_INPUT_STATE *ins, CONFIG_LIST *clp, uint32_t flags) { - WT_CURSOR *cursor; - WT_DECL_RET; - size_t gotnolen, keystrlen; - uint64_t gotno, recno; - int nfield, nkeys, toktype, tret; - char config[64], *endp, *uri; - const char *keyformat; - bool isrec; - - cursor = NULL; - uri = NULL; - - /* Reorder and check the list. */ - if ((ret = config_reorder(session, clp->list)) != 0) - goto err; - - /* Update config based on command-line configuration. */ - if ((ret = config_update(session, clp->list)) != 0) - goto err; - - /* Create the items collected. */ - if ((ret = config_exec(session, clp->list)) != 0) - goto err; - - uri = clp->list[0]; - if ((ret = __wt_snprintf(config, sizeof(config), - "dump=json%s%s", - LF_ISSET(LOAD_JSON_APPEND) ? ",append" : "", - LF_ISSET(LOAD_JSON_NO_OVERWRITE) ? ",overwrite=false" : "")) != 0) { - ret = util_err(session, ret, NULL); - goto err; - } - if ((ret = session->open_cursor( - session, uri, NULL, config, &cursor)) != 0) { - ret = util_err(session, ret, "%s: session.open_cursor", uri); - goto err; - } - keyformat = cursor->key_format; - isrec = WT_STREQ(keyformat, "r"); - for (nkeys = 0; *keyformat; keyformat++) - if (!__wt_isdigit((u_char)*keyformat)) - nkeys++; - - recno = 0; - while (json_peek(session, ins) == '{') { - nfield = 0; - JSON_EXPECT(session, ins, '{'); - if (ins->kvraw == NULL) { - if ((ins->kvraw = malloc(1)) == NULL) { - ret = util_err(session, errno, NULL); - goto err; - } - } - ins->kvraw[0] = '\0'; - ins->kvrawstart = JSON_INPUT_POS(ins); - keystrlen = 0; - while (json_peek(session, ins) == 's') { - JSON_EXPECT(session, ins, 's'); - JSON_EXPECT(session, ins, ':'); - toktype = json_peek(session, ins); - JSON_EXPECT(session, ins, toktype); - if (isrec && nfield == 0) { - /* Verify the dump has recnos in order. */ - recno++; - gotno = __wt_strtouq(ins->tokstart, &endp, 0); - gotnolen = (size_t)(endp - ins->tokstart); - if (recno != gotno || ins->toklen != gotnolen) { - ret = util_err(session, 0, - "%s: recno out of order", uri); - goto err; - } - } - if (++nfield == nkeys) { - size_t curpos = JSON_INPUT_POS(ins); - if ((ret = json_kvraw_append(session, ins, - (char *)ins->line.mem + ins->kvrawstart, - curpos - ins->kvrawstart)) != 0) - goto err; - ins->kvrawstart = curpos; - keystrlen = strlen(ins->kvraw); - } - if (json_peek(session, ins) != ',') - break; - JSON_EXPECT(session, ins, ','); - if (json_peek(session, ins) != 's') - goto err; - } - if (json_kvraw_append( - session, ins, ins->line.mem, JSON_INPUT_POS(ins))) - goto err; - - ins->kvraw[keystrlen] = '\0'; - if (!LF_ISSET(LOAD_JSON_APPEND)) - cursor->set_key(cursor, ins->kvraw); - /* skip over inserted space and comma */ - cursor->set_value(cursor, &ins->kvraw[keystrlen+2]); - if ((ret = cursor->insert(cursor)) != 0) { - ret = util_err(session, ret, "%s: cursor.insert", uri); - goto err; - } - - JSON_EXPECT(session, ins, '}'); - if (json_peek(session, ins) != ',') - break; - JSON_EXPECT(session, ins, ','); - if (json_peek(session, ins) != '{') - goto err; - } - if (0) { -err: if (ret == 0) - ret = EINVAL; - } - /* - * Technically, we don't have to close the cursor because the session - * handle will do it for us, but I'd like to see the flush to disk and - * the close succeed, it's better to fail early when loading files. - */ - if (cursor != NULL && (tret = cursor->close(cursor)) != 0) { - tret = util_err(session, tret, "%s: cursor.close", uri); - if (ret == 0) - ret = tret; - } - if (ret == 0) - ret = util_flush(session, uri); - return (ret); + WT_CURSOR *cursor; + WT_DECL_RET; + size_t gotnolen, keystrlen; + uint64_t gotno, recno; + int nfield, nkeys, toktype, tret; + char config[64], *endp, *uri; + const char *keyformat; + bool isrec; + + cursor = NULL; + uri = NULL; + + /* Reorder and check the list. */ + if ((ret = config_reorder(session, clp->list)) != 0) + goto err; + + /* Update config based on command-line configuration. */ + if ((ret = config_update(session, clp->list)) != 0) + goto err; + + /* Create the items collected. */ + if ((ret = config_exec(session, clp->list)) != 0) + goto err; + + uri = clp->list[0]; + if ((ret = __wt_snprintf(config, sizeof(config), "dump=json%s%s", + LF_ISSET(LOAD_JSON_APPEND) ? ",append" : "", + LF_ISSET(LOAD_JSON_NO_OVERWRITE) ? ",overwrite=false" : "")) != 0) { + ret = util_err(session, ret, NULL); + goto err; + } + if ((ret = session->open_cursor(session, uri, NULL, config, &cursor)) != 0) { + ret = util_err(session, ret, "%s: session.open_cursor", uri); + goto err; + } + keyformat = cursor->key_format; + isrec = WT_STREQ(keyformat, "r"); + for (nkeys = 0; *keyformat; keyformat++) + if (!__wt_isdigit((u_char)*keyformat)) + nkeys++; + + recno = 0; + while (json_peek(session, ins) == '{') { + nfield = 0; + JSON_EXPECT(session, ins, '{'); + if (ins->kvraw == NULL) { + if ((ins->kvraw = malloc(1)) == NULL) { + ret = util_err(session, errno, NULL); + goto err; + } + } + ins->kvraw[0] = '\0'; + ins->kvrawstart = JSON_INPUT_POS(ins); + keystrlen = 0; + while (json_peek(session, ins) == 's') { + JSON_EXPECT(session, ins, 's'); + JSON_EXPECT(session, ins, ':'); + toktype = json_peek(session, ins); + JSON_EXPECT(session, ins, toktype); + if (isrec && nfield == 0) { + /* Verify the dump has recnos in order. */ + recno++; + gotno = __wt_strtouq(ins->tokstart, &endp, 0); + gotnolen = (size_t)(endp - ins->tokstart); + if (recno != gotno || ins->toklen != gotnolen) { + ret = util_err(session, 0, "%s: recno out of order", uri); + goto err; + } + } + if (++nfield == nkeys) { + size_t curpos = JSON_INPUT_POS(ins); + if ((ret = json_kvraw_append(session, ins, (char *)ins->line.mem + ins->kvrawstart, + curpos - ins->kvrawstart)) != 0) + goto err; + ins->kvrawstart = curpos; + keystrlen = strlen(ins->kvraw); + } + if (json_peek(session, ins) != ',') + break; + JSON_EXPECT(session, ins, ','); + if (json_peek(session, ins) != 's') + goto err; + } + if (json_kvraw_append(session, ins, ins->line.mem, JSON_INPUT_POS(ins))) + goto err; + + ins->kvraw[keystrlen] = '\0'; + if (!LF_ISSET(LOAD_JSON_APPEND)) + cursor->set_key(cursor, ins->kvraw); + /* skip over inserted space and comma */ + cursor->set_value(cursor, &ins->kvraw[keystrlen + 2]); + if ((ret = cursor->insert(cursor)) != 0) { + ret = util_err(session, ret, "%s: cursor.insert", uri); + goto err; + } + + JSON_EXPECT(session, ins, '}'); + if (json_peek(session, ins) != ',') + break; + JSON_EXPECT(session, ins, ','); + if (json_peek(session, ins) != '{') + goto err; + } + if (0) { +err: + if (ret == 0) + ret = EINVAL; + } + /* + * Technically, we don't have to close the cursor because the session handle will do it for us, + * but I'd like to see the flush to disk and the close succeed, it's better to fail early when + * loading files. + */ + if (cursor != NULL && (tret = cursor->close(cursor)) != 0) { + tret = util_err(session, tret, "%s: cursor.close", uri); + if (ret == 0) + ret = tret; + } + if (ret == 0) + ret = util_flush(session, uri); + return (ret); } /* * json_top_level -- - * Parse the top level JSON input. + * Parse the top level JSON input. */ static int json_top_level(WT_SESSION *session, JSON_INPUT_STATE *ins, uint32_t flags) { - CONFIG_LIST cl; - WT_DECL_RET; - static const char *json_markers[] = { - "\"config\"", "\"colgroups\"", "\"indices\"", "\"data\"", NULL }; - uint64_t curversion; - int toktype; - char *config, *tableuri; - bool hasversion; - - memset(&cl, 0, sizeof(cl)); - tableuri = NULL; - hasversion = false; - - JSON_EXPECT(session, ins, '{'); - while (json_peek(session, ins) == 's') { - JSON_EXPECT(session, ins, 's'); - tableuri = realloc(tableuri, ins->toklen); - if ((ret = __wt_snprintf(tableuri, ins->toklen, - "%.*s", (int)(ins->toklen - 2), ins->tokstart + 1)) != 0) { - ret = util_err(session, ret, NULL); - goto err; - } - JSON_EXPECT(session, ins, ':'); - if (!hasversion) { - if (strcmp(tableuri, DUMP_JSON_VERSION_MARKER) != 0) { - ret = util_err(session, ENOTSUP, - "missing \"%s\"", DUMP_JSON_VERSION_MARKER); - goto err; - } - hasversion = true; - JSON_EXPECT(session, ins, 's'); - if ((ret = util_str2num(session, - ins->tokstart + 1, false, &curversion)) != 0) - goto err; - if (curversion > DUMP_JSON_SUPPORTED_VERSION) { - ret = util_err(session, ENOTSUP, - "unsupported JSON dump version \"%.*s\"", - (int)(ins->toklen - 1), ins->tokstart + 1); - goto err; - } - JSON_EXPECT(session, ins, ','); - continue; - } - - /* - * Allow any ordering of 'config', 'colgroups', - * 'indices' before 'data', which must appear last. - * The non-'data' items build up a list of entries - * that created in our session before the data is - * inserted. - */ - for (;;) { - if (json_skip(session, ins, json_markers) != 0) - goto err; - JSON_EXPECT(session, ins, 's'); - if (JSON_STRING_MATCH(ins, "config")) { - JSON_EXPECT(session, ins, ':'); - JSON_EXPECT(session, ins, 's'); - if ((ret = - json_strdup(session, ins, &config)) != 0) { - ret = util_err(session, ret, NULL); - goto err; - } - if ((ret = config_list_add( - session, &cl, tableuri)) != 0) - goto err; - if ((ret = config_list_add( - session, &cl, config)) != 0) - goto err; - tableuri = NULL; - } else if (JSON_STRING_MATCH(ins, "colgroups")) { - JSON_EXPECT(session, ins, ':'); - JSON_EXPECT(session, ins, '['); - if ((ret = json_column_group_index( - session, ins, &cl, 0)) != 0) - goto err; - JSON_EXPECT(session, ins, ']'); - } else if (JSON_STRING_MATCH(ins, "indices")) { - JSON_EXPECT(session, ins, ':'); - JSON_EXPECT(session, ins, '['); - if ((ret = json_column_group_index( - session, ins, &cl, 1)) != 0) - goto err; - JSON_EXPECT(session, ins, ']'); - } else if (JSON_STRING_MATCH(ins, "data")) { - JSON_EXPECT(session, ins, ':'); - JSON_EXPECT(session, ins, '['); - if ((ret = json_data(session, ins, &cl, - flags)) != 0) - goto err; - config_list_free(&cl); - free(ins->kvraw); - ins->kvraw = NULL; - config_list_free(&cl); - break; - } - else - goto err; - } - - while ((toktype = json_peek(session, ins)) == '}' || - toktype == ']') - JSON_EXPECT(session, ins, toktype); - if (toktype == 0) /* Check EOF. */ - break; - if (toktype == ',') { - JSON_EXPECT(session, ins, ','); - if (json_peek(session, ins) != 's') - goto err; - continue; - } - } - JSON_EXPECT(session, ins, 0); - - if (0) { -err: if (ret == 0) - ret = EINVAL; - } - config_list_free(&cl); - free(tableuri); - return (ret); + CONFIG_LIST cl; + WT_DECL_RET; + static const char *json_markers[] = { + "\"config\"", "\"colgroups\"", "\"indices\"", "\"data\"", NULL}; + uint64_t curversion; + int toktype; + char *config, *tableuri; + bool hasversion; + + memset(&cl, 0, sizeof(cl)); + tableuri = NULL; + hasversion = false; + + JSON_EXPECT(session, ins, '{'); + while (json_peek(session, ins) == 's') { + JSON_EXPECT(session, ins, 's'); + tableuri = realloc(tableuri, ins->toklen); + if ((ret = __wt_snprintf( + tableuri, ins->toklen, "%.*s", (int)(ins->toklen - 2), ins->tokstart + 1)) != 0) { + ret = util_err(session, ret, NULL); + goto err; + } + JSON_EXPECT(session, ins, ':'); + if (!hasversion) { + if (strcmp(tableuri, DUMP_JSON_VERSION_MARKER) != 0) { + ret = util_err(session, ENOTSUP, "missing \"%s\"", DUMP_JSON_VERSION_MARKER); + goto err; + } + hasversion = true; + JSON_EXPECT(session, ins, 's'); + if ((ret = util_str2num(session, ins->tokstart + 1, false, &curversion)) != 0) + goto err; + if (curversion > DUMP_JSON_SUPPORTED_VERSION) { + ret = util_err(session, ENOTSUP, "unsupported JSON dump version \"%.*s\"", + (int)(ins->toklen - 1), ins->tokstart + 1); + goto err; + } + JSON_EXPECT(session, ins, ','); + continue; + } + + /* + * Allow any ordering of 'config', 'colgroups', + * 'indices' before 'data', which must appear last. + * The non-'data' items build up a list of entries + * that created in our session before the data is + * inserted. + */ + for (;;) { + if (json_skip(session, ins, json_markers) != 0) + goto err; + JSON_EXPECT(session, ins, 's'); + if (JSON_STRING_MATCH(ins, "config")) { + JSON_EXPECT(session, ins, ':'); + JSON_EXPECT(session, ins, 's'); + if ((ret = json_strdup(session, ins, &config)) != 0) { + ret = util_err(session, ret, NULL); + goto err; + } + if ((ret = config_list_add(session, &cl, tableuri)) != 0) + goto err; + if ((ret = config_list_add(session, &cl, config)) != 0) + goto err; + tableuri = NULL; + } else if (JSON_STRING_MATCH(ins, "colgroups")) { + JSON_EXPECT(session, ins, ':'); + JSON_EXPECT(session, ins, '['); + if ((ret = json_column_group_index(session, ins, &cl, 0)) != 0) + goto err; + JSON_EXPECT(session, ins, ']'); + } else if (JSON_STRING_MATCH(ins, "indices")) { + JSON_EXPECT(session, ins, ':'); + JSON_EXPECT(session, ins, '['); + if ((ret = json_column_group_index(session, ins, &cl, 1)) != 0) + goto err; + JSON_EXPECT(session, ins, ']'); + } else if (JSON_STRING_MATCH(ins, "data")) { + JSON_EXPECT(session, ins, ':'); + JSON_EXPECT(session, ins, '['); + if ((ret = json_data(session, ins, &cl, flags)) != 0) + goto err; + config_list_free(&cl); + free(ins->kvraw); + ins->kvraw = NULL; + config_list_free(&cl); + break; + } else + goto err; + } + + while ((toktype = json_peek(session, ins)) == '}' || toktype == ']') + JSON_EXPECT(session, ins, toktype); + if (toktype == 0) /* Check EOF. */ + break; + if (toktype == ',') { + JSON_EXPECT(session, ins, ','); + if (json_peek(session, ins) != 's') + goto err; + continue; + } + } + JSON_EXPECT(session, ins, 0); + + if (0) { +err: + if (ret == 0) + ret = EINVAL; + } + config_list_free(&cl); + free(tableuri); + return (ret); } /* * json_peek -- - * Set the input state to the next available token in the input - * and return its token type, a code defined by __wt_json_token(). + * Set the input state to the next available token in the input and return its token type, a + * code defined by __wt_json_token(). */ static int json_peek(WT_SESSION *session, JSON_INPUT_STATE *ins) { - WT_DECL_RET; - - if (!ins->peeking) { - while (!ins->ateof) { - while (__wt_isspace((u_char)*ins->p)) - ins->p++; - if (*ins->p) - break; - if (ins->kvraw != NULL) { - if (json_kvraw_append(session, ins, - (char *)ins->line.mem + ins->kvrawstart, - strlen(ins->line.mem) - ins->kvrawstart)) { - ret = -1; - goto err; - } - ins->kvrawstart = 0; - } - if (util_read_line( - session, &ins->line, true, &ins->ateof)) { - ins->toktype = -1; - ret = -1; - goto err; - } - ins->linenum++; - ins->p = (const char *)ins->line.mem; - } - if (ins->ateof) - ins->toktype = 0; - else if (__wt_json_token(session, ins->p, - &ins->toktype, &ins->tokstart, - &ins->toklen) != 0) - ins->toktype = -1; - ins->peeking = true; - } - if (0) { - err: if (ret == 0) - ret = -1; - } - return (ret == 0 ? ins->toktype : -1); + WT_DECL_RET; + + if (!ins->peeking) { + while (!ins->ateof) { + while (__wt_isspace((u_char)*ins->p)) + ins->p++; + if (*ins->p) + break; + if (ins->kvraw != NULL) { + if (json_kvraw_append(session, ins, (char *)ins->line.mem + ins->kvrawstart, + strlen(ins->line.mem) - ins->kvrawstart)) { + ret = -1; + goto err; + } + ins->kvrawstart = 0; + } + if (util_read_line(session, &ins->line, true, &ins->ateof)) { + ins->toktype = -1; + ret = -1; + goto err; + } + ins->linenum++; + ins->p = (const char *)ins->line.mem; + } + if (ins->ateof) + ins->toktype = 0; + else if (__wt_json_token(session, ins->p, &ins->toktype, &ins->tokstart, &ins->toklen) != 0) + ins->toktype = -1; + ins->peeking = true; + } + if (0) { +err: + if (ret == 0) + ret = -1; + } + return (ret == 0 ? ins->toktype : -1); } /* * json_expect -- - * Ensure that the type of the next token in the input matches - * the wanted value, and advance past it. The values of the - * input state will be set so specific string or integer values - * can be pulled out after this call. + * Ensure that the type of the next token in the input matches the wanted value, and advance + * past it. The values of the input state will be set so specific string or integer values can + * be pulled out after this call. */ static int json_expect(WT_SESSION *session, JSON_INPUT_STATE *ins, int wanttok) { - if (json_peek(session, ins) < 0) - return (1); - ins->p += ins->toklen; - ins->peeking = false; - if (ins->toktype != wanttok) { - fprintf(stderr, - "%s: %d: %" WT_SIZET_FMT ": expected %s, got %s\n", - ins->filename, - ins->linenum, - JSON_INPUT_POS(ins) + 1, - __wt_json_tokname(wanttok), - __wt_json_tokname(ins->toktype)); - return (1); - } - return (0); + if (json_peek(session, ins) < 0) + return (1); + ins->p += ins->toklen; + ins->peeking = false; + if (ins->toktype != wanttok) { + fprintf(stderr, "%s: %d: %" WT_SIZET_FMT ": expected %s, got %s\n", ins->filename, + ins->linenum, JSON_INPUT_POS(ins) + 1, __wt_json_tokname(wanttok), + __wt_json_tokname(ins->toktype)); + return (1); + } + return (0); } /* * json_skip -- - * Skip over JSON input until one of the specified strings appears. - * The tokenizer will be set to point to the beginning of - * that string. + * Skip over JSON input until one of the specified strings appears. The tokenizer will be set to + * point to the beginning of that string. */ static int json_skip(WT_SESSION *session, JSON_INPUT_STATE *ins, const char **matches) { - const char *hit; - const char **match; - - WT_ASSERT((WT_SESSION_IMPL *)session, ins->kvraw == NULL); - hit = NULL; - while (!ins->ateof) { - for (match = matches; *match != NULL; match++) - if ((hit = strstr(ins->p, *match)) != NULL) - goto out; - if (util_read_line(session, &ins->line, true, &ins->ateof) - != 0) { - ins->toktype = -1; - return (1); - } - ins->linenum++; - ins->p = (const char *)ins->line.mem; - } + const char *hit; + const char **match; + + WT_ASSERT((WT_SESSION_IMPL *)session, ins->kvraw == NULL); + hit = NULL; + while (!ins->ateof) { + for (match = matches; *match != NULL; match++) + if ((hit = strstr(ins->p, *match)) != NULL) + goto out; + if (util_read_line(session, &ins->line, true, &ins->ateof) != 0) { + ins->toktype = -1; + return (1); + } + ins->linenum++; + ins->p = (const char *)ins->line.mem; + } out: - if (hit == NULL) - return (1); - - /* Set to this token. */ - ins->p = hit; - ins->peeking = false; - ins->toktype = 0; - (void)json_peek(session, ins); - return (0); + if (hit == NULL) + return (1); + + /* Set to this token. */ + ins->p = hit; + ins->peeking = false; + ins->toktype = 0; + (void)json_peek(session, ins); + return (0); } /* * load_json -- - * Load from the JSON format produced by 'wt dump -j'. + * Load from the JSON format produced by 'wt dump -j'. */ int util_load_json(WT_SESSION *session, const char *filename, uint32_t flags) { - JSON_INPUT_STATE instate; - WT_DECL_RET; - - memset(&instate, 0, sizeof(instate)); - instate.session = session; - if ((ret = util_read_line( - session, &instate.line, false, &instate.ateof)) == 0) { - instate.p = (const char *)instate.line.mem; - instate.linenum = 1; - instate.filename = filename; - - ret = json_top_level(session, &instate, flags); - } - - free(instate.line.mem); - free(instate.kvraw); - return (ret); + JSON_INPUT_STATE instate; + WT_DECL_RET; + + memset(&instate, 0, sizeof(instate)); + instate.session = session; + if ((ret = util_read_line(session, &instate.line, false, &instate.ateof)) == 0) { + instate.p = (const char *)instate.line.mem; + instate.linenum = 1; + instate.filename = filename; + + ret = json_top_level(session, &instate, flags); + } + + free(instate.line.mem); + free(instate.kvraw); + return (ret); } diff --git a/src/third_party/wiredtiger/src/utilities/util_loadtext.c b/src/third_party/wiredtiger/src/utilities/util_loadtext.c index f1e3c9a3e87..1d4414b47b5 100644 --- a/src/third_party/wiredtiger/src/utilities/util_loadtext.c +++ b/src/third_party/wiredtiger/src/utilities/util_loadtext.c @@ -15,156 +15,150 @@ static int usage(void); int util_loadtext(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char *uri; - - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "f:")) != EOF) - switch (ch) { - case 'f': /* input file */ - if (freopen(__wt_optarg, "r", stdin) == NULL) - return (util_err( - session, errno, "%s: reopen", __wt_optarg)); - break; - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining argument is the uri. */ - if (argc != 1) - return (usage()); - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); - - ret = text(session, uri); - - free(uri); - return (ret); + WT_DECL_RET; + int ch; + char *uri; + + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "f:")) != EOF) + switch (ch) { + case 'f': /* input file */ + if (freopen(__wt_optarg, "r", stdin) == NULL) + return (util_err(session, errno, "%s: reopen", __wt_optarg)); + break; + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining argument is the uri. */ + if (argc != 1) + return (usage()); + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); + + ret = text(session, uri); + + free(uri); + return (ret); } /* * text -- - * Load flat-text into a file/table. + * Load flat-text into a file/table. */ static int text(WT_SESSION *session, const char *uri) { - WT_CURSOR *cursor; - WT_DECL_RET; - int tret; - bool readkey; - - /* - * Open the cursor, configured to append new records (in the case of - * column-store objects), or to overwrite existing strings (in the - * case of row-store objects). The two flags are mutually exclusive, - * but the library doesn't currently care that we set both of them. - */ - if ((ret = session->open_cursor( - session, uri, NULL, "append,overwrite", &cursor)) != 0) - return (util_err(session, ret, "%s: session.open_cursor", uri)); - - /* - * We're about to load strings, make sure the formats match. - * - * Row-store tables have key/value pairs, column-store tables only have - * values. - */ - if (!WT_STREQ(cursor->value_format, "S") || - (!WT_STREQ(cursor->key_format, "S") && - !WT_STREQ(cursor->key_format, "r"))) - return (util_err(session, EINVAL, - "the loadtext command can only load objects configured " - "for record number or string keys, and string values")); - readkey = !WT_STREQ(cursor->key_format, "r"); - - /* Insert the records */ - ret = insert(cursor, uri, readkey); - - /* - * Technically, we don't have to close the cursor because the session - * handle will do it for us, but I'd like to see the flush to disk and - * the close succeed, it's better to fail early when loading files. - */ - if ((tret = cursor->close(cursor)) != 0) { - tret = util_err(session, tret, "%s: cursor.close", uri); - if (ret == 0) - ret = tret; - } - if (ret == 0) - ret = util_flush(session, uri); - - return (ret == 0 ? 0 : 1); + WT_CURSOR *cursor; + WT_DECL_RET; + int tret; + bool readkey; + + /* + * Open the cursor, configured to append new records (in the case of column-store objects), or + * to overwrite existing strings (in the case of row-store objects). The two flags are mutually + * exclusive, but the library doesn't currently care that we set both of them. + */ + if ((ret = session->open_cursor(session, uri, NULL, "append,overwrite", &cursor)) != 0) + return (util_err(session, ret, "%s: session.open_cursor", uri)); + + /* + * We're about to load strings, make sure the formats match. + * + * Row-store tables have key/value pairs, column-store tables only have + * values. + */ + if (!WT_STREQ(cursor->value_format, "S") || + (!WT_STREQ(cursor->key_format, "S") && !WT_STREQ(cursor->key_format, "r"))) + return (util_err(session, EINVAL, + "the loadtext command can only load objects configured " + "for record number or string keys, and string values")); + readkey = !WT_STREQ(cursor->key_format, "r"); + + /* Insert the records */ + ret = insert(cursor, uri, readkey); + + /* + * Technically, we don't have to close the cursor because the session handle will do it for us, + * but I'd like to see the flush to disk and the close succeed, it's better to fail early when + * loading files. + */ + if ((tret = cursor->close(cursor)) != 0) { + tret = util_err(session, tret, "%s: cursor.close", uri); + if (ret == 0) + ret = tret; + } + if (ret == 0) + ret = util_flush(session, uri); + + return (ret == 0 ? 0 : 1); } /* * insert -- - * Read and insert data. + * Read and insert data. */ static int insert(WT_CURSOR *cursor, const char *name, bool readkey) { - ULINE key, value; - WT_DECL_RET; - WT_SESSION *session; - uint64_t insert_count; - bool eof; - - session = cursor->session; - - memset(&key, 0, sizeof(key)); - memset(&value, 0, sizeof(value)); - - /* Read key/value pairs and insert them into the file. */ - for (insert_count = 0;;) { - /* - * Three modes: in row-store, we always read a key and use it, - * in column-store, we might read it (a dump), we might read - * and ignore it (a dump with "append" set), or not read it at - * all (flat-text load). - */ - if (readkey) { - if (util_read_line(session, &key, true, &eof)) - return (1); - if (eof) - break; - cursor->set_key(cursor, key.mem); - } - if (util_read_line(session, &value, !readkey, &eof)) - return (1); - if (eof) - break; - cursor->set_value(cursor, value.mem); - - if ((ret = cursor->insert(cursor)) != 0) - return ( - util_err(session, ret, "%s: cursor.insert", name)); - - /* Report on progress every 100 inserts. */ - if (verbose && ++insert_count % 100 == 0) { - printf("\r\t%s: %" PRIu64, name, insert_count); - fflush(stdout); - } - } - free(key.mem); - free(value.mem); - - if (verbose) - printf("\r\t%s: %" PRIu64 "\n", name, insert_count); - - return (0); + ULINE key, value; + WT_DECL_RET; + WT_SESSION *session; + uint64_t insert_count; + bool eof; + + session = cursor->session; + + memset(&key, 0, sizeof(key)); + memset(&value, 0, sizeof(value)); + + /* Read key/value pairs and insert them into the file. */ + for (insert_count = 0;;) { + /* + * Three modes: in row-store, we always read a key and use it, in column-store, we might + * read it (a dump), we might read and ignore it (a dump with "append" set), or not read it + * at all (flat-text load). + */ + if (readkey) { + if (util_read_line(session, &key, true, &eof)) + return (1); + if (eof) + break; + cursor->set_key(cursor, key.mem); + } + if (util_read_line(session, &value, !readkey, &eof)) + return (1); + if (eof) + break; + cursor->set_value(cursor, value.mem); + + if ((ret = cursor->insert(cursor)) != 0) + return (util_err(session, ret, "%s: cursor.insert", name)); + + /* Report on progress every 100 inserts. */ + if (verbose && ++insert_count % 100 == 0) { + printf("\r\t%s: %" PRIu64, name, insert_count); + fflush(stdout); + } + } + free(key.mem); + free(value.mem); + + if (verbose) + printf("\r\t%s: %" PRIu64 "\n", name, insert_count); + + return (0); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "loadtext [-f input-file] uri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "loadtext [-f input-file] uri\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_main.c b/src/third_party/wiredtiger/src/utilities/util_main.c index fb2b1990166..4f609cdeeef 100644 --- a/src/third_party/wiredtiger/src/utilities/util_main.c +++ b/src/third_party/wiredtiger/src/utilities/util_main.c @@ -8,350 +8,395 @@ #include "util.h" -const char *home = "."; /* Home directory */ -const char *progname; /* Program name */ - /* Global arguments */ +const char *home = "."; /* Home directory */ +const char *progname; /* Program name */ + /* Global arguments */ const char *usage_prefix = "[-LRSVv] [-C config] [-E secretkey] [-h home]"; -bool verbose = false; /* Verbose flag */ +bool verbose = false; /* Verbose flag */ -static const char *command; /* Command name */ +static const char *command; /* Command name */ -#define REC_ERROR "log=(recover=error)" -#define REC_LOGOFF "log=(enabled=false)" -#define REC_RECOVER "log=(recover=on)" -#define REC_SALVAGE "log=(recover=salvage)" +#define READONLY "readonly=true" +#define REC_ERROR "log=(recover=error)" +#define REC_LOGOFF "log=(enabled=false)" +#define REC_RECOVER "log=(recover=on)" +#define REC_SALVAGE "log=(recover=salvage)" static void usage(void) { - fprintf(stderr, - "WiredTiger Data Engine (version %d.%d)\n", - WIREDTIGER_VERSION_MAJOR, WIREDTIGER_VERSION_MINOR); - fprintf(stderr, - "global options:\n" - "\t" "-C\t" "wiredtiger_open configuration\n" - "\t" "-E\t" "secret encryption key\n" - "\t" "-h\t" "database directory\n" - "\t" "-L\t" "turn logging off for debug-mode\n" - "\t" "-R\t" "run recovery (if recovery configured)\n" - "\t" "-S\t" "run salvage recovery (if recovery configured)\n" - "\t" "-V\t" "display library version and exit\n" - "\t" "-v\t" "verbose\n"); - fprintf(stderr, - "commands:\n" - "\t" "alter\t alter an object\n" - "\t" "backup\t database backup\n" - "\t" "compact\t compact an object\n" - "\t" "copyright copyright information\n" - "\t" "create\t create an object\n" - "\t" "downgrade downgrade a database\n" - "\t" "drop\t drop an object\n" - "\t" "dump\t dump an object\n" - /* - * Import is not documented. - * "\t" "import\t import an object\n" - */ - "\t" "list\t list database objects\n" - "\t" "load\t load an object\n" - "\t" "loadtext load an object from a text file\n" - "\t" "printlog display the database log\n" - "\t" "read\t read values from an object\n" - "\t" "rebalance rebalance an object\n" - "\t" "rename\t rename an object\n" - "\t" "salvage\t salvage a file\n" - "\t" "stat\t display statistics for an object\n" - "\t" "truncate truncate an object, removing all content\n" - "\t" "upgrade\t upgrade an object\n" - "\t" "verify\t verify an object\n" - "\t" "write\t write values to an object\n"); + fprintf(stderr, "WiredTiger Data Engine (version %d.%d)\n", WIREDTIGER_VERSION_MAJOR, + WIREDTIGER_VERSION_MINOR); + fprintf(stderr, + "global options:\n" + "\t" + "-C\t" + "wiredtiger_open configuration\n" + "\t" + "-E\t" + "secret encryption key\n" + "\t" + "-h\t" + "database directory\n" + "\t" + "-L\t" + "turn logging off for debug-mode\n" + "\t" + "-R\t" + "run recovery (if recovery configured)\n" + "\t" + "-S\t" + "run salvage recovery (if recovery configured)\n" + "\t" + "-V\t" + "display library version and exit\n" + "\t" + "-v\t" + "verbose\n"); + fprintf(stderr, + "commands:\n" + "\t" + "alter\t alter an object\n" + "\t" + "backup\t database backup\n" + "\t" + "compact\t compact an object\n" + "\t" + "copyright copyright information\n" + "\t" + "create\t create an object\n" + "\t" + "downgrade downgrade a database\n" + "\t" + "drop\t drop an object\n" + "\t" + "dump\t dump an object\n" + /* + * Import is not documented. + * "\t" "import\t import an object\n" + */ + "\t" + "list\t list database objects\n" + "\t" + "load\t load an object\n" + "\t" + "loadtext load an object from a text file\n" + "\t" + "printlog display the database log\n" + "\t" + "read\t read values from an object\n" + "\t" + "rebalance rebalance an object\n" + "\t" + "rename\t rename an object\n" + "\t" + "salvage\t salvage a file\n" + "\t" + "stat\t display statistics for an object\n" + "\t" + "truncate truncate an object, removing all content\n" + "\t" + "upgrade\t upgrade an object\n" + "\t" + "verify\t verify an object\n" + "\t" + "write\t write values to an object\n"); } int main(int argc, char *argv[]) { - WT_CONNECTION *conn; - WT_DECL_RET; - WT_SESSION *session; - size_t len; - int ch, major_v, minor_v, tret, (*func)(WT_SESSION *, int, char *[]); - const char *cmd_config, *config, *p1, *p2, *p3, *rec_config; - char *p, *secretkey; - bool logoff, recover, salvage; + WT_CONNECTION *conn; + WT_DECL_RET; + WT_SESSION *session; + size_t len; + int ch, major_v, minor_v, tret, (*func)(WT_SESSION *, int, char *[]); + char *p, *secretkey; + const char *cmd_config, *config, *p1, *p2, *p3, *readonly_config, *rec_config; + bool logoff, readonly, recover, salvage; - conn = NULL; - p = NULL; + conn = NULL; + p = NULL; - /* Get the program name. */ - if ((progname = strrchr(argv[0], '/')) == NULL) - progname = argv[0]; - else - ++progname; - command = ""; + /* Get the program name. */ + if ((progname = strrchr(argv[0], '/')) == NULL) + progname = argv[0]; + else + ++progname; + command = ""; - /* Check the version against the library build. */ - (void)wiredtiger_version(&major_v, & minor_v, NULL); - if (major_v != WIREDTIGER_VERSION_MAJOR || - minor_v != WIREDTIGER_VERSION_MINOR) { - fprintf(stderr, - "%s: program build version %d.%d does not match " - "library build version %d.%d\n", - progname, - WIREDTIGER_VERSION_MAJOR, WIREDTIGER_VERSION_MINOR, - major_v, minor_v); - return (EXIT_FAILURE); - } + /* Check the version against the library build. */ + (void)wiredtiger_version(&major_v, &minor_v, NULL); + if (major_v != WIREDTIGER_VERSION_MAJOR || minor_v != WIREDTIGER_VERSION_MINOR) { + fprintf(stderr, + "%s: program build version %d.%d does not match " + "library build version %d.%d\n", + progname, WIREDTIGER_VERSION_MAJOR, WIREDTIGER_VERSION_MINOR, major_v, minor_v); + return (EXIT_FAILURE); + } - cmd_config = config = secretkey = NULL; - /* - * We default to returning an error if recovery needs to be run. - * Generally we expect this to be run after a clean shutdown. - * The printlog command disables logging entirely. If recovery is - * needed, the user can specify -R to run recovery. - */ - rec_config = REC_ERROR; - logoff = recover = salvage = false; - /* Check for standard options. */ - while ((ch = __wt_getopt(progname, argc, argv, "C:E:h:LRSVv")) != EOF) - switch (ch) { - case 'C': /* wiredtiger_open config */ - cmd_config = __wt_optarg; - break; - case 'E': /* secret key */ - free(secretkey); /* lint: set more than once */ - if ((secretkey = strdup(__wt_optarg)) == NULL) { - (void)util_err(NULL, errno, NULL); - goto err; - } - memset(__wt_optarg, 0, strlen(__wt_optarg)); - break; - case 'h': /* home directory */ - home = __wt_optarg; - break; - case 'L': /* no logging */ - rec_config = REC_LOGOFF; - logoff = true; - break; - case 'R': /* recovery */ - rec_config = REC_RECOVER; - recover = true; - break; - case 'S': /* salvage */ - rec_config = REC_SALVAGE; - salvage = true; - break; - case 'V': /* version */ - printf("%s\n", wiredtiger_version(NULL, NULL, NULL)); - goto done; - case 'v': /* verbose */ - verbose = true; - break; - case '?': - default: - usage(); - goto err; - } - if ((logoff && recover) || (logoff && salvage) || - (recover && salvage)) { - fprintf(stderr, "Only one of -L, -R, and -S is allowed.\n"); - goto err; - } - argc -= __wt_optind; - argv += __wt_optind; + cmd_config = config = readonly_config = secretkey = NULL; + /* + * We default to returning an error if recovery needs to be run. Generally we expect this to be + * run after a clean shutdown. The printlog command disables logging entirely. If recovery is + * needed, the user can specify -R to run recovery. + */ + rec_config = REC_ERROR; + logoff = readonly = recover = salvage = false; + /* Check for standard options. */ + while ((ch = __wt_getopt(progname, argc, argv, "C:E:h:LRSVv")) != EOF) + switch (ch) { + case 'C': /* wiredtiger_open config */ + cmd_config = __wt_optarg; + break; + case 'E': /* secret key */ + free(secretkey); /* lint: set more than once */ + if ((secretkey = strdup(__wt_optarg)) == NULL) { + (void)util_err(NULL, errno, NULL); + goto err; + } + memset(__wt_optarg, 0, strlen(__wt_optarg)); + break; + case 'h': /* home directory */ + home = __wt_optarg; + break; + case 'L': /* no logging */ + rec_config = REC_LOGOFF; + logoff = true; + break; + case 'R': /* recovery */ + rec_config = REC_RECOVER; + recover = true; + break; + case 'S': /* salvage */ + rec_config = REC_SALVAGE; + salvage = true; + break; + case 'V': /* version */ + printf("%s\n", wiredtiger_version(NULL, NULL, NULL)); + goto done; + case 'v': /* verbose */ + verbose = true; + break; + case '?': + default: + usage(); + goto err; + } + if ((logoff && recover) || (logoff && salvage) || (recover && salvage)) { + fprintf(stderr, "Only one of -L, -R, and -S is allowed.\n"); + goto err; + } + argc -= __wt_optind; + argv += __wt_optind; - /* The next argument is the command name. */ - if (argc < 1) { - usage(); - goto err; - } - command = argv[0]; + /* The next argument is the command name. */ + if (argc < 1) { + usage(); + goto err; + } + command = argv[0]; - /* Reset getopt. */ - __wt_optreset = __wt_optind = 1; + /* Reset getopt. */ + __wt_optreset = __wt_optind = 1; + func = NULL; + switch (command[0]) { + case 'a': + if (strcmp(command, "alter") == 0) + func = util_alter; + break; + case 'b': + if (strcmp(command, "backup") == 0) + func = util_backup; + break; + case 'c': + if (strcmp(command, "compact") == 0) + func = util_compact; + else if (strcmp(command, "copyright") == 0) { + util_copyright(); + goto done; + } else if (strcmp(command, "create") == 0) { + func = util_create; + config = "create"; + } + break; + case 'd': + if (strcmp(command, "downgrade") == 0) + func = util_downgrade; + else if (strcmp(command, "drop") == 0) + func = util_drop; + else if (strcmp(command, "dump") == 0) { + func = util_dump; + readonly_config = READONLY; + } + break; + case 'i': + if (strcmp(command, "import") == 0) + func = util_import; + break; + case 'l': + if (strcmp(command, "list") == 0) { + func = util_list; + readonly_config = READONLY; + } else if (strcmp(command, "load") == 0) { + func = util_load; + config = "create"; + } else if (strcmp(command, "loadtext") == 0) { + func = util_loadtext; + config = "create"; + } + break; + case 'p': + if (strcmp(command, "printlog") == 0) { + func = util_printlog; + rec_config = REC_LOGOFF; + readonly_config = READONLY; + } + break; + case 'r': + if (strcmp(command, "read") == 0) { + func = util_read; + readonly_config = READONLY; + } else if (strcmp(command, "rebalance") == 0) + func = util_rebalance; + else if (strcmp(command, "rename") == 0) + func = util_rename; + break; + case 's': + if (strcmp(command, "salvage") == 0) + func = util_salvage; + else if (strcmp(command, "stat") == 0) { + func = util_stat; + config = "statistics=(all)"; + readonly_config = READONLY; + } + break; + case 't': + if (strcmp(command, "truncate") == 0) + func = util_truncate; + break; + case 'u': + if (strcmp(command, "upgrade") == 0) + func = util_upgrade; + break; + case 'v': + if (strcmp(command, "verify") == 0) { + func = util_verify; + readonly_config = READONLY; + } + break; + case 'w': + if (strcmp(command, "write") == 0) + func = util_write; + break; + default: + break; + } + if (func == NULL) { + usage(); + goto err; + } - func = NULL; - switch (command[0]) { - case 'a': - if (strcmp(command, "alter") == 0) - func = util_alter; - break; - case 'b': - if (strcmp(command, "backup") == 0) - func = util_backup; - break; - case 'c': - if (strcmp(command, "compact") == 0) - func = util_compact; - else if (strcmp(command, "copyright") == 0) { - util_copyright(); - goto done; - } else if (strcmp(command, "create") == 0) { - func = util_create; - config = "create"; - } - break; - case 'd': - if (strcmp(command, "downgrade") == 0) - func = util_downgrade; - else if (strcmp(command, "drop") == 0) - func = util_drop; - else if (strcmp(command, "dump") == 0) - func = util_dump; - break; - case 'i': - if (strcmp(command, "import") == 0) - func = util_import; - break; - case 'l': - if (strcmp(command, "list") == 0) - func = util_list; - else if (strcmp(command, "load") == 0) { - func = util_load; - config = "create"; - } else if (strcmp(command, "loadtext") == 0) { - func = util_loadtext; - config = "create"; - } - break; - case 'p': - if (strcmp(command, "printlog") == 0) { - func = util_printlog; - rec_config = REC_LOGOFF; - } - break; - case 'r': - if (strcmp(command, "read") == 0) - func = util_read; - else if (strcmp(command, "rebalance") == 0) - func = util_rebalance; - else if (strcmp(command, "rename") == 0) - func = util_rename; - break; - case 's': - if (strcmp(command, "salvage") == 0) - func = util_salvage; - else if (strcmp(command, "stat") == 0) { - func = util_stat; - config = "statistics=(all)"; - } - break; - case 't' : - if (strcmp(command, "truncate") == 0) - func = util_truncate; - break; - case 'u': - if (strcmp(command, "upgrade") == 0) - func = util_upgrade; - break; - case 'v': - if (strcmp(command, "verify") == 0) - func = util_verify; - break; - case 'w': - if (strcmp(command, "write") == 0) - func = util_write; - break; - default: - break; - } - if (func == NULL) { - usage(); - goto err; - } + /* + * If the user has specified recovery or salvage disable readonly mode, as they are both not + * readonly operations. + */ + if (recover || salvage) + readonly_config = NULL; - /* Build the configuration string. */ - len = 10; /* some slop */ - p1 = p2 = p3 = ""; - len += strlen("error_prefix=wt"); - if (config != NULL) - len += strlen(config); - if (cmd_config != NULL) - len += strlen(cmd_config); - if (secretkey != NULL) { - len += strlen(secretkey) + 30; - p1 = ",encryption=(secretkey="; - p2 = secretkey; - p3 = ")"; - } - len += strlen(rec_config); - if ((p = malloc(len)) == NULL) { - (void)util_err(NULL, errno, NULL); - goto err; - } - if ((ret = __wt_snprintf(p, len, "error_prefix=wt,%s,%s,%s%s%s%s", - config == NULL ? "" : config, - cmd_config == NULL ? "" : cmd_config, - rec_config, p1, p2, p3)) != 0) { - (void)util_err(NULL, ret, NULL); - goto err; - } - config = p; + /* Build the configuration string. */ + len = 10; /* some slop */ + p1 = p2 = p3 = ""; + len += strlen("error_prefix=wt"); + if (config != NULL) + len += strlen(config); + if (cmd_config != NULL) + len += strlen(cmd_config); + if (readonly_config != NULL) + len += strlen(readonly_config); + if (secretkey != NULL) { + len += strlen(secretkey) + 30; + p1 = ",encryption=(secretkey="; + p2 = secretkey; + p3 = ")"; + } + len += strlen(rec_config); + if ((p = malloc(len)) == NULL) { + (void)util_err(NULL, errno, NULL); + goto err; + } + if ((ret = __wt_snprintf(p, len, "error_prefix=wt,%s,%s,%s,%s%s%s%s", + config == NULL ? "" : config, cmd_config == NULL ? "" : cmd_config, + readonly_config == NULL ? "" : readonly_config, rec_config, p1, p2, p3)) != 0) { + (void)util_err(NULL, ret, NULL); + goto err; + } + config = p; - /* Open the database and a session. */ - if ((ret = wiredtiger_open(home, - verbose ? verbose_handler : NULL, config, &conn)) != 0) { - (void)util_err(NULL, ret, NULL); - goto err; - } - if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) { - (void)util_err(NULL, ret, NULL); - goto err; - } + /* Open the database and a session. */ + if ((ret = wiredtiger_open(home, verbose ? verbose_handler : NULL, config, &conn)) != 0) { + (void)util_err(NULL, ret, NULL); + goto err; + } + if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0) { + (void)util_err(NULL, ret, NULL); + goto err; + } - /* Call the function. */ - ret = func(session, argc, argv); + /* Call the function. */ + ret = func(session, argc, argv); - if (0) { -err: ret = 1; - } + if (0) { +err: + ret = 1; + } done: - /* Close the database. */ - if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0) - ret = tret; + /* Close the database. */ + if (conn != NULL && (tret = conn->close(conn, NULL)) != 0 && ret == 0) + ret = tret; - free(p); - free(secretkey); + free(p); + free(secretkey); - return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE); + return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE); } /* * util_uri -- - * Build a name. + * Build a name. */ char * util_uri(WT_SESSION *session, const char *s, const char *type) { - WT_DECL_RET; - size_t len; - char *name; + WT_DECL_RET; + size_t len; + char *name; - if (WT_PREFIX_MATCH(s, "backup:") || - WT_PREFIX_MATCH(s, "config:") || - WT_PREFIX_MATCH(s, "statistics:")) { - fprintf(stderr, - "%s: %s: unsupported object type: %s\n", - progname, command, s); - return (NULL); - } + if (WT_PREFIX_MATCH(s, "backup:") || WT_PREFIX_MATCH(s, "config:") || + WT_PREFIX_MATCH(s, "statistics:")) { + fprintf(stderr, "%s: %s: unsupported object type: %s\n", progname, command, s); + return (NULL); + } - len = strlen(type) + strlen(s) + 2; - if ((name = calloc(len, 1)) == NULL) { - (void)util_err(session, errno, NULL); - return (NULL); - } + len = strlen(type) + strlen(s) + 2; + if ((name = calloc(len, 1)) == NULL) { + (void)util_err(session, errno, NULL); + return (NULL); + } - /* - * If the string has a URI prefix, use it verbatim, otherwise prepend - * the default type for the operation. - */ - if (strchr(s, ':') != NULL) - WT_ERR(__wt_snprintf(name, len, "%s", s)); - else - WT_ERR(__wt_snprintf(name, len, "%s:%s", type, s)); - return (name); + /* + * If the string has a URI prefix, use it verbatim, otherwise prepend the default type for the + * operation. + */ + if (strchr(s, ':') != NULL) + WT_ERR(__wt_snprintf(name, len, "%s", s)); + else + WT_ERR(__wt_snprintf(name, len, "%s:%s", type, s)); + return (name); -err: free(name); - (void)util_err(session, ret, NULL); - return (NULL); +err: + free(name); + (void)util_err(session, ret, NULL); + return (NULL); } diff --git a/src/third_party/wiredtiger/src/utilities/util_misc.c b/src/third_party/wiredtiger/src/utilities/util_misc.c index a691cf227f6..2c4358e64ef 100644 --- a/src/third_party/wiredtiger/src/utilities/util_misc.c +++ b/src/third_party/wiredtiger/src/utilities/util_misc.c @@ -11,151 +11,144 @@ int util_cerr(WT_CURSOR *cursor, const char *op, int ret) { - return ( - util_err(cursor->session, ret, "%s: cursor.%s", cursor->uri, op)); + return (util_err(cursor->session, ret, "%s: cursor.%s", cursor->uri, op)); } /* * util_err -- - * Report an error. + * Report an error. */ int util_err(WT_SESSION *session, int e, const char *fmt, ...) { - va_list ap; - - (void)fprintf(stderr, "%s: ", progname); - if (fmt != NULL) { - va_start(ap, fmt); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - if (e != 0) - (void)fprintf(stderr, ": "); - } - if (e != 0) - (void)fprintf(stderr, "%s", session == NULL ? - wiredtiger_strerror(e) : session->strerror(session, e)); - (void)fprintf(stderr, "\n"); - return (1); + va_list ap; + + (void)fprintf(stderr, "%s: ", progname); + if (fmt != NULL) { + va_start(ap, fmt); + (void)vfprintf(stderr, fmt, ap); + va_end(ap); + if (e != 0) + (void)fprintf(stderr, ": "); + } + if (e != 0) + (void)fprintf( + stderr, "%s", session == NULL ? wiredtiger_strerror(e) : session->strerror(session, e)); + (void)fprintf(stderr, "\n"); + return (1); } /* * util_read_line -- - * Read a line from stdin into a ULINE. + * Read a line from stdin into a ULINE. */ int util_read_line(WT_SESSION *session, ULINE *l, bool eof_expected, bool *eofp) { - static uint64_t line = 0; - size_t len; - int ch; - - ++line; - *eofp = false; - - if (l->memsize == 0) { - if ((l->mem = realloc(l->mem, l->memsize + 1024)) == NULL) - return (util_err(session, errno, NULL)); - l->memsize = 1024; - } - for (len = 0;; ++len) { - if ((ch = getchar()) == EOF) { - if (len == 0) { - if (eof_expected) { - *eofp = true; - return (0); - } - return (util_err(session, 0, - "line %" PRIu64 ": unexpected end-of-file", - line)); - } - return (util_err(session, 0, - "line %" PRIu64 ": no newline terminator", line)); - } - if (ch == '\n') - break; - /* - * We nul-terminate the string so it's easier to convert the - * line into a record number, that means we always need one - * extra byte at the end. - */ - if (len >= l->memsize - 1) { - if ((l->mem = - realloc(l->mem, l->memsize + 1024)) == NULL) - return (util_err(session, errno, NULL)); - l->memsize += 1024; - } - ((uint8_t *)l->mem)[len] = (uint8_t)ch; - } - - ((uint8_t *)l->mem)[len] = '\0'; /* nul-terminate */ - - return (0); + static uint64_t line = 0; + size_t len; + int ch; + + ++line; + *eofp = false; + + if (l->memsize == 0) { + if ((l->mem = realloc(l->mem, l->memsize + 1024)) == NULL) + return (util_err(session, errno, NULL)); + l->memsize = 1024; + } + for (len = 0;; ++len) { + if ((ch = getchar()) == EOF) { + if (len == 0) { + if (eof_expected) { + *eofp = true; + return (0); + } + return (util_err(session, 0, "line %" PRIu64 ": unexpected end-of-file", line)); + } + return (util_err(session, 0, "line %" PRIu64 ": no newline terminator", line)); + } + if (ch == '\n') + break; + /* + * We nul-terminate the string so it's easier to convert the line into a record number, that + * means we always need one extra byte at the end. + */ + if (len >= l->memsize - 1) { + if ((l->mem = realloc(l->mem, l->memsize + 1024)) == NULL) + return (util_err(session, errno, NULL)); + l->memsize += 1024; + } + ((uint8_t *)l->mem)[len] = (uint8_t)ch; + } + + ((uint8_t *)l->mem)[len] = '\0'; /* nul-terminate */ + + return (0); } /* * util_str2num -- - * Convert a string to a number. + * Convert a string to a number. */ int util_str2num(WT_SESSION *session, const char *p, bool endnul, uint64_t *vp) { - uint64_t v; - char *endptr; - - /* - * strtouq takes lots of things like hex values, signs and so on and so - * forth -- none of them are OK with us. Check the string starts with - * digit, that turns off the special processing. - */ - if (!__wt_isdigit((u_char)p[0])) - goto format; - - errno = 0; - v = __wt_strtouq(p, &endptr, 0); - if (v == ULLONG_MAX && errno == ERANGE) - return (util_err(session, ERANGE, "%s: invalid number", p)); - - /* - * In most cases we expect the number to be a string and end with a - * nul byte (and we want to confirm that because it's a user-entered - * command-line argument), but we allow the caller to configure that - * test off. - */ - if (endnul && endptr[0] != '\0') -format: return (util_err(session, EINVAL, "%s: invalid number", p)); - - *vp = v; - return (0); + uint64_t v; + char *endptr; + + /* + * strtouq takes lots of things like hex values, signs and so on and so forth -- none of them + * are OK with us. Check the string starts with digit, that turns off the special processing. + */ + if (!__wt_isdigit((u_char)p[0])) + goto format; + + errno = 0; + v = __wt_strtouq(p, &endptr, 0); + if (v == ULLONG_MAX && errno == ERANGE) + return (util_err(session, ERANGE, "%s: invalid number", p)); + + /* + * In most cases we expect the number to be a string and end with a nul byte (and we want to + * confirm that because it's a user-entered command-line argument), but we allow the caller to + * configure that test off. + */ + if (endnul && endptr[0] != '\0') +format: + return (util_err(session, EINVAL, "%s: invalid number", p)); + + *vp = v; + return (0); } /* * util_flush -- - * Flush the file successfully, or drop it. + * Flush the file successfully, or drop it. */ int util_flush(WT_SESSION *session, const char *uri) { - WT_DECL_RET; - size_t len; - char *buf; - - len = strlen(uri) + 100; - if ((buf = malloc(len)) == NULL) - return (util_err(session, errno, NULL)); - - if ((ret = __wt_snprintf(buf, len, "target=(\"%s\")", uri)) != 0) { - free(buf); - return (util_err(session, ret, NULL)); - } - ret = session->checkpoint(session, buf); - free(buf); - - if (ret == 0) - return (0); - - (void)util_err(session, ret, "%s: session.checkpoint", uri); - if ((ret = session->drop(session, uri, NULL)) != 0) - (void)util_err(session, ret, "%s: session.drop", uri); - return (1); + WT_DECL_RET; + size_t len; + char *buf; + + len = strlen(uri) + 100; + if ((buf = malloc(len)) == NULL) + return (util_err(session, errno, NULL)); + + if ((ret = __wt_snprintf(buf, len, "target=(\"%s\")", uri)) != 0) { + free(buf); + return (util_err(session, ret, NULL)); + } + ret = session->checkpoint(session, buf); + free(buf); + + if (ret == 0) + return (0); + + (void)util_err(session, ret, "%s: session.checkpoint", uri); + if ((ret = session->drop(session, uri, NULL)) != 0) + (void)util_err(session, ret, "%s: session.drop", uri); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_printlog.c b/src/third_party/wiredtiger/src/utilities/util_printlog.c index 9f7e79ae5ed..ede4b0464b0 100644 --- a/src/third_party/wiredtiger/src/utilities/util_printlog.c +++ b/src/third_party/wiredtiger/src/utilities/util_printlog.c @@ -13,43 +13,43 @@ static int usage(void); int util_printlog(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - uint32_t flags; - int ch; - char *ofile; - - flags = 0; - ofile = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "f:x")) != EOF) - switch (ch) { - case 'f': /* output file */ - ofile = __wt_optarg; - break; - case 'x': /* hex output */ - LF_SET(WT_TXN_PRINTLOG_HEX); - break; - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - - /* There should not be any more arguments. */ - if (argc != 0) - return (usage()); - - if ((ret = __wt_txn_printlog(session, ofile, flags)) != 0) - (void)util_err(session, ret, "printlog"); - - return (ret); + WT_DECL_RET; + uint32_t flags; + int ch; + char *ofile; + + flags = 0; + ofile = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "f:x")) != EOF) + switch (ch) { + case 'f': /* output file */ + ofile = __wt_optarg; + break; + case 'x': /* hex output */ + LF_SET(WT_TXN_PRINTLOG_HEX); + break; + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + + /* There should not be any more arguments. */ + if (argc != 0) + return (usage()); + + if ((ret = __wt_txn_printlog(session, ofile, flags)) != 0) + (void)util_err(session, ret, "printlog"); + + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "printlog [-x] [-f output-file]\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "printlog [-x] [-f output-file]\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_read.c b/src/third_party/wiredtiger/src/utilities/util_read.c index e62587a0105..24bfaff5209 100644 --- a/src/third_party/wiredtiger/src/utilities/util_read.c +++ b/src/third_party/wiredtiger/src/utilities/util_read.c @@ -13,98 +13,94 @@ static int usage(void); int util_read(WT_SESSION *session, int argc, char *argv[]) { - WT_CURSOR *cursor; - WT_DECL_RET; - uint64_t recno; - int ch; - char *uri, *value; - bool rkey, rval; + WT_CURSOR *cursor; + WT_DECL_RET; + uint64_t recno; + int ch; + char *uri, *value; + bool rkey, rval; - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) - switch (ch) { - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) + switch (ch) { + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; - /* The remaining arguments are a uri followed by a list of keys. */ - if (argc < 2) - return (usage()); - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); + /* The remaining arguments are a uri followed by a list of keys. */ + if (argc < 2) + return (usage()); + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); - /* - * Open the object; free allocated memory immediately to simplify - * future error handling. - */ - if ((ret = - session->open_cursor(session, uri, NULL, NULL, &cursor)) != 0) - (void)util_err(session, ret, "%s: session.open_cursor", uri); - free(uri); - if (ret != 0) - return (ret); + /* + * Open the object; free allocated memory immediately to simplify future error handling. + */ + if ((ret = session->open_cursor(session, uri, NULL, NULL, &cursor)) != 0) + (void)util_err(session, ret, "%s: session.open_cursor", uri); + free(uri); + if (ret != 0) + return (ret); - /* - * A simple search only makes sense if the key format is a string or a - * record number, and the value format is a single string. - */ - if (!WT_STREQ(cursor->key_format, "r") && - !WT_STREQ(cursor->key_format, "S")) { - fprintf(stderr, - "%s: read command only possible when the key format is " - "a record number or string\n", - progname); - return (1); - } - rkey = WT_STREQ(cursor->key_format, "r"); - if (!WT_STREQ(cursor->value_format, "S")) { - fprintf(stderr, - "%s: read command only possible when the value format is " - "a string\n", - progname); - return (1); - } + /* + * A simple search only makes sense if the key format is a string or a record number, and the + * value format is a single string. + */ + if (!WT_STREQ(cursor->key_format, "r") && !WT_STREQ(cursor->key_format, "S")) { + fprintf(stderr, + "%s: read command only possible when the key format is " + "a record number or string\n", + progname); + return (1); + } + rkey = WT_STREQ(cursor->key_format, "r"); + if (!WT_STREQ(cursor->value_format, "S")) { + fprintf(stderr, + "%s: read command only possible when the value format is " + "a string\n", + progname); + return (1); + } - /* - * Run through the keys, returning non-zero on error or if any requested - * key isn't found. - */ - for (rval = false; *++argv != NULL;) { - if (rkey) { - if (util_str2num(session, *argv, true, &recno)) - return (1); - cursor->set_key(cursor, recno); - } else - cursor->set_key(cursor, *argv); + /* + * Run through the keys, returning non-zero on error or if any requested key isn't found. + */ + for (rval = false; *++argv != NULL;) { + if (rkey) { + if (util_str2num(session, *argv, true, &recno)) + return (1); + cursor->set_key(cursor, recno); + } else + cursor->set_key(cursor, *argv); - switch (ret = cursor->search(cursor)) { - case 0: - if ((ret = cursor->get_value(cursor, &value)) != 0) - return (util_cerr(cursor, "get_value", ret)); - if (printf("%s\n", value) < 0) - return (util_err(session, EIO, NULL)); - break; - case WT_NOTFOUND: - (void)util_err(session, 0, "%s: not found", *argv); - rval = true; - break; - default: - return (util_cerr(cursor, "search", ret)); - } - } + switch (ret = cursor->search(cursor)) { + case 0: + if ((ret = cursor->get_value(cursor, &value)) != 0) + return (util_cerr(cursor, "get_value", ret)); + if (printf("%s\n", value) < 0) + return (util_err(session, EIO, NULL)); + break; + case WT_NOTFOUND: + (void)util_err(session, 0, "%s: not found", *argv); + rval = true; + break; + default: + return (util_cerr(cursor, "search", ret)); + } + } - return (rval ? 1 : 0); + return (rval ? 1 : 0); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "read uri key ...\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "read uri key ...\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_rebalance.c b/src/third_party/wiredtiger/src/utilities/util_rebalance.c index ee52b59f7d7..f6954cf33d5 100644 --- a/src/third_party/wiredtiger/src/utilities/util_rebalance.c +++ b/src/third_party/wiredtiger/src/utilities/util_rebalance.c @@ -13,47 +13,46 @@ static int usage(void); int util_rebalance(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char *uri; - - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) - switch (ch) { - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining argument is the table name. */ - if (argc != 1) - return (usage()); - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); - - if ((ret = session->rebalance(session, uri, NULL)) != 0) - (void)util_err(session, ret, "session.rebalance: %s", uri); - else { - /* - * Verbose configures a progress counter, move to the next - * line. - */ - if (verbose) - printf("\n"); - } - - free(uri); - return (ret); + WT_DECL_RET; + int ch; + char *uri; + + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) + switch (ch) { + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining argument is the table name. */ + if (argc != 1) + return (usage()); + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); + + if ((ret = session->rebalance(session, uri, NULL)) != 0) + (void)util_err(session, ret, "session.rebalance: %s", uri); + else { + /* + * Verbose configures a progress counter, move to the next line. + */ + if (verbose) + printf("\n"); + } + + free(uri); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "rebalance uri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "rebalance uri\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_rename.c b/src/third_party/wiredtiger/src/utilities/util_rename.c index ec6d4523ce3..26b9eb8eccc 100644 --- a/src/third_party/wiredtiger/src/utilities/util_rename.c +++ b/src/third_party/wiredtiger/src/utilities/util_rename.c @@ -13,41 +13,40 @@ static int usage(void); int util_rename(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char *uri, *newuri; - - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) - switch (ch) { - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining arguments are the object uri and new name. */ - if (argc != 2) - return (usage()); - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); - newuri = argv[1]; - - if ((ret = session->rename(session, uri, newuri, NULL)) != 0) - (void)util_err( - session, ret, "session.rename: %s, %s", uri, newuri); - - free(uri); - return (ret); + WT_DECL_RET; + int ch; + char *uri, *newuri; + + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) + switch (ch) { + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining arguments are the object uri and new name. */ + if (argc != 2) + return (usage()); + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); + newuri = argv[1]; + + if ((ret = session->rename(session, uri, newuri, NULL)) != 0) + (void)util_err(session, ret, "session.rename: %s, %s", uri, newuri); + + free(uri); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "rename uri newuri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "rename uri newuri\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_salvage.c b/src/third_party/wiredtiger/src/utilities/util_salvage.c index ba8d2aaea60..9d8db88329a 100644 --- a/src/third_party/wiredtiger/src/utilities/util_salvage.c +++ b/src/third_party/wiredtiger/src/utilities/util_salvage.c @@ -13,52 +13,51 @@ static int usage(void); int util_salvage(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - const char *force; - char *uri; - - force = NULL; - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "F")) != EOF) - switch (ch) { - case 'F': - force = "force"; - break; - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining argument is the file name. */ - if (argc != 1) - return (usage()); - if ((uri = util_uri(session, *argv, "file")) == NULL) - return (1); - - if ((ret = session->salvage(session, uri, force)) != 0) - (void)util_err(session, ret, "session.salvage: %s", uri); - else { - /* - * Verbose configures a progress counter, move to the next - * line. - */ - if (verbose) - printf("\n"); - } - - free(uri); - return (ret); + WT_DECL_RET; + int ch; + char *uri; + const char *force; + + force = NULL; + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "F")) != EOF) + switch (ch) { + case 'F': + force = "force"; + break; + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining argument is the file name. */ + if (argc != 1) + return (usage()); + if ((uri = util_uri(session, *argv, "file")) == NULL) + return (1); + + if ((ret = session->salvage(session, uri, force)) != 0) + (void)util_err(session, ret, "session.salvage: %s", uri); + else { + /* + * Verbose configures a progress counter, move to the next line. + */ + if (verbose) + printf("\n"); + } + + free(uri); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "salvage [-F] uri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "salvage [-F] uri\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_stat.c b/src/third_party/wiredtiger/src/utilities/util_stat.c index b722a35a884..908c524c00d 100644 --- a/src/third_party/wiredtiger/src/utilities/util_stat.c +++ b/src/third_party/wiredtiger/src/utilities/util_stat.c @@ -13,106 +13,103 @@ static int usage(void); int util_stat(WT_SESSION *session, int argc, char *argv[]) { - WT_CURSOR *cursor; - WT_DECL_RET; - size_t urilen; - int ch; - const char *config, *desc, *pval; - char *objname, *uri; - bool objname_free; + WT_CURSOR *cursor; + WT_DECL_RET; + size_t urilen; + int ch; + char *objname, *uri; + const char *config, *desc, *pval; + bool objname_free; - objname_free = false; - objname = uri = NULL; - config = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "af")) != EOF) - switch (ch) { - case 'a': - /* - * Historically, the -a option meant include all of the - * statistics; because we are opening the database with - * statistics=(all), that is now the default, allow the - * option for compatibility. - */ - config = NULL; - break; - case 'f': - config = "statistics=(fast)"; - break; - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; + objname_free = false; + objname = uri = NULL; + config = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "af")) != EOF) + switch (ch) { + case 'a': + /* + * Historically, the -a option meant include all of the statistics; because we are + * opening the database with statistics=(all), that is now the default, allow the option + * for compatibility. + */ + config = NULL; + break; + case 'f': + config = "statistics=(fast)"; + break; + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; - /* - * If there are no arguments, the statistics cursor operates on the - * connection, otherwise, the optional remaining argument is a file - * or LSM name. - */ - switch (argc) { - case 0: - objname = (char *)""; - break; - case 1: - if ((objname = util_uri(session, *argv, "table")) == NULL) - return (1); - objname_free = true; - break; - default: - return (usage()); - } + /* + * If there are no arguments, the statistics cursor operates on the connection, otherwise, the + * optional remaining argument is a file or LSM name. + */ + switch (argc) { + case 0: + objname = (char *)""; + break; + case 1: + if ((objname = util_uri(session, *argv, "table")) == NULL) + return (1); + objname_free = true; + break; + default: + return (usage()); + } - urilen = strlen("statistics:") + strlen(objname) + 1; - if ((uri = calloc(urilen, 1)) == NULL) { - fprintf(stderr, "%s: %s\n", progname, strerror(errno)); - goto err; - } - if ((ret = __wt_snprintf(uri, urilen, "statistics:%s", objname)) != 0) { - fprintf(stderr, "%s: %s\n", progname, strerror(ret)); - goto err; - } + urilen = strlen("statistics:") + strlen(objname) + 1; + if ((uri = calloc(urilen, 1)) == NULL) { + fprintf(stderr, "%s: %s\n", progname, strerror(errno)); + goto err; + } + if ((ret = __wt_snprintf(uri, urilen, "statistics:%s", objname)) != 0) { + fprintf(stderr, "%s: %s\n", progname, strerror(ret)); + goto err; + } - if ((ret = - session->open_cursor(session, uri, NULL, config, &cursor)) != 0) { - fprintf(stderr, "%s: cursor open(%s) failed: %s\n", - progname, uri, session->strerror(session, ret)); - goto err; - } + if ((ret = session->open_cursor(session, uri, NULL, config, &cursor)) != 0) { + fprintf(stderr, "%s: cursor open(%s) failed: %s\n", progname, uri, + session->strerror(session, ret)); + goto err; + } - /* List the statistics. */ - while ( - (ret = cursor->next(cursor)) == 0 && - (ret = cursor->get_value(cursor, &desc, &pval, NULL)) == 0) - if (printf("%s=%s\n", desc, pval) < 0) { - (void)util_err(session, errno, "printf"); - goto err; - } - if (ret == WT_NOTFOUND) - ret = 0; + /* List the statistics. */ + while ((ret = cursor->next(cursor)) == 0 && + (ret = cursor->get_value(cursor, &desc, &pval, NULL)) == 0) + if (printf("%s=%s\n", desc, pval) < 0) { + (void)util_err(session, errno, "printf"); + goto err; + } + if (ret == WT_NOTFOUND) + ret = 0; - if (ret != 0) { - fprintf(stderr, "%s: cursor get(%s) failed: %s\n", - progname, objname, session->strerror(session, ret)); - goto err; - } + if (ret != 0) { + fprintf(stderr, "%s: cursor get(%s) failed: %s\n", progname, objname, + session->strerror(session, ret)); + goto err; + } - if (0) { -err: ret = 1; - } - if (objname_free) - free(objname); - free(uri); + if (0) { +err: + ret = 1; + } + if (objname_free) + free(objname); + free(uri); - return (ret); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "stat [-f] [uri]\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "stat [-f] [uri]\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_truncate.c b/src/third_party/wiredtiger/src/utilities/util_truncate.c index 82289fd7d05..0eb4eafd29e 100644 --- a/src/third_party/wiredtiger/src/utilities/util_truncate.c +++ b/src/third_party/wiredtiger/src/utilities/util_truncate.c @@ -13,40 +13,40 @@ static int usage(void); int util_truncate(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char *uri; - - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) - switch (ch) { - case '?': - default: - return (usage()); - } - - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining argument is the uri. */ - if (argc != 1) - return (usage()); - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); - - if ((ret = session->truncate(session, uri, NULL, NULL, NULL)) != 0) - (void)util_err(session, ret, "session.truncate: %s", uri); - - free(uri); - return (ret); + WT_DECL_RET; + int ch; + char *uri; + + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) + switch (ch) { + case '?': + default: + return (usage()); + } + + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining argument is the uri. */ + if (argc != 1) + return (usage()); + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); + + if ((ret = session->truncate(session, uri, NULL, NULL, NULL)) != 0) + (void)util_err(session, ret, "session.truncate: %s", uri); + + free(uri); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "truncate uri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "truncate uri\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_upgrade.c b/src/third_party/wiredtiger/src/utilities/util_upgrade.c index a1deffa3c63..ff142c3927c 100644 --- a/src/third_party/wiredtiger/src/utilities/util_upgrade.c +++ b/src/third_party/wiredtiger/src/utilities/util_upgrade.c @@ -13,47 +13,46 @@ static int usage(void); int util_upgrade(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - int ch; - char *uri; - - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) - switch (ch) { - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; - - /* The remaining argument is the table name. */ - if (argc != 1) - return (usage()); - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); - - if ((ret = session->upgrade(session, uri, NULL)) != 0) - (void)util_err(session, ret, "session.upgrade: %s", uri); - else { - /* - * Verbose configures a progress counter, move to the next - * line. - */ - if (verbose) - printf("\n"); - } - - free(uri); - return (ret); + WT_DECL_RET; + int ch; + char *uri; + + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "")) != EOF) + switch (ch) { + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; + + /* The remaining argument is the table name. */ + if (argc != 1) + return (usage()); + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); + + if ((ret = session->upgrade(session, uri, NULL)) != 0) + (void)util_err(session, ret, "session.upgrade: %s", uri); + else { + /* + * Verbose configures a progress counter, move to the next line. + */ + if (verbose) + printf("\n"); + } + + free(uri); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "upgrade uri\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "upgrade uri\n", + progname, usage_prefix); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_verbose.c b/src/third_party/wiredtiger/src/utilities/util_verbose.c index 253d0062189..04aaf29cf73 100644 --- a/src/third_party/wiredtiger/src/utilities/util_verbose.c +++ b/src/third_party/wiredtiger/src/utilities/util_verbose.c @@ -10,53 +10,49 @@ /* * __handle_error_verbose -- - * Verbose WT_EVENT_HANDLER->handle_error implementation: send to stderr. + * Verbose WT_EVENT_HANDLER->handle_error implementation: send to stderr. */ static int -__handle_error_verbose(WT_EVENT_HANDLER *handler, - WT_SESSION *session, int error, const char *errmsg) +__handle_error_verbose( + WT_EVENT_HANDLER *handler, WT_SESSION *session, int error, const char *errmsg) { - WT_UNUSED(handler); - WT_UNUSED(session); - WT_UNUSED(error); + WT_UNUSED(handler); + WT_UNUSED(session); + WT_UNUSED(error); - return (fprintf(stderr, "%s\n", errmsg) < 0 ? EIO : 0); + return (fprintf(stderr, "%s\n", errmsg) < 0 ? EIO : 0); } /* * __handle_message_verbose -- - * Verbose WT_EVENT_HANDLER->handle_message implementation: send to stdout. + * Verbose WT_EVENT_HANDLER->handle_message implementation: send to stdout. */ static int -__handle_message_verbose(WT_EVENT_HANDLER *handler, - WT_SESSION *session, const char *message) +__handle_message_verbose(WT_EVENT_HANDLER *handler, WT_SESSION *session, const char *message) { - WT_UNUSED(handler); - WT_UNUSED(session); + WT_UNUSED(handler); + WT_UNUSED(session); - return (printf("%s\n", message) < 0 ? EIO : 0); + return (printf("%s\n", message) < 0 ? EIO : 0); } /* * __handle_progress_verbose -- - * Default WT_EVENT_HANDLER->handle_progress implementation: ignore. + * Default WT_EVENT_HANDLER->handle_progress implementation: ignore. */ static int -__handle_progress_verbose(WT_EVENT_HANDLER *handler, - WT_SESSION *session, const char *operation, uint64_t progress) +__handle_progress_verbose( + WT_EVENT_HANDLER *handler, WT_SESSION *session, const char *operation, uint64_t progress) { - WT_UNUSED(handler); - WT_UNUSED(session); + WT_UNUSED(handler); + WT_UNUSED(session); - return ( - printf("\r\t%s %-20" PRIu64, operation, progress) < 0 ? EIO : 0); + return (printf("\r\t%s %-20" PRIu64, operation, progress) < 0 ? EIO : 0); } static WT_EVENT_HANDLER __event_handler_verbose = { - __handle_error_verbose, - __handle_message_verbose, - __handle_progress_verbose, - NULL /* Close handler. */ + __handle_error_verbose, __handle_message_verbose, __handle_progress_verbose, + NULL /* Close handler. */ }; diff --git a/src/third_party/wiredtiger/src/utilities/util_verify.c b/src/third_party/wiredtiger/src/utilities/util_verify.c index 8c09768a310..773da1e85a1 100644 --- a/src/third_party/wiredtiger/src/utilities/util_verify.c +++ b/src/third_party/wiredtiger/src/utilities/util_verify.c @@ -13,102 +13,92 @@ static int usage(void); int util_verify(WT_SESSION *session, int argc, char *argv[]) { - WT_DECL_RET; - size_t size; - int ch; - char *config, *dump_offsets, *uri; - bool dump_address, dump_blocks, dump_layout, dump_pages; + WT_DECL_RET; + size_t size; + int ch; + char *config, *dump_offsets, *uri; + bool dump_address, dump_blocks, dump_layout, dump_pages; - dump_address = dump_blocks = dump_layout = dump_pages = false; - config = dump_offsets = uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "d:")) != EOF) - switch (ch) { - case 'd': - if (strcmp(__wt_optarg, "dump_address") == 0) - dump_address = true; - else if (strcmp(__wt_optarg, "dump_blocks") == 0) - dump_blocks = true; - else if (strcmp(__wt_optarg, "dump_layout") == 0) - dump_layout = true; - else if ( - WT_PREFIX_MATCH(__wt_optarg, "dump_offsets=")) { - if (dump_offsets != NULL) { - fprintf(stderr, - "%s: only a single 'dump_offsets' " - "argument supported\n", progname); - return (usage()); - } - dump_offsets = - __wt_optarg + strlen("dump_offsets="); - } else if (strcmp(__wt_optarg, "dump_pages") == 0) - dump_pages = true; - else - return (usage()); - break; - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; + dump_address = dump_blocks = dump_layout = dump_pages = false; + config = dump_offsets = uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "d:")) != EOF) + switch (ch) { + case 'd': + if (strcmp(__wt_optarg, "dump_address") == 0) + dump_address = true; + else if (strcmp(__wt_optarg, "dump_blocks") == 0) + dump_blocks = true; + else if (strcmp(__wt_optarg, "dump_layout") == 0) + dump_layout = true; + else if (WT_PREFIX_MATCH(__wt_optarg, "dump_offsets=")) { + if (dump_offsets != NULL) { + fprintf(stderr, + "%s: only a single 'dump_offsets' " + "argument supported\n", + progname); + return (usage()); + } + dump_offsets = __wt_optarg + strlen("dump_offsets="); + } else if (strcmp(__wt_optarg, "dump_pages") == 0) + dump_pages = true; + else + return (usage()); + break; + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; - /* The remaining argument is the table name. */ - if (argc != 1) - return (usage()); - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); + /* The remaining argument is the table name. */ + if (argc != 1) + return (usage()); + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); - /* Build the configuration string as necessary. */ - if (dump_address || - dump_blocks || dump_layout || dump_offsets != NULL || dump_pages) { - size = - strlen("dump_address,") + - strlen("dump_blocks,") + - strlen("dump_layout,") + - strlen("dump_pages,") + - strlen("dump_offsets[],") + - (dump_offsets == NULL ? 0 : strlen(dump_offsets)) + 20; - if ((config = malloc(size)) == NULL) { - ret = util_err(session, errno, NULL); - goto err; - } - if ((ret = __wt_snprintf(config, size, - "%s%s%s%s%s%s%s", - dump_address ? "dump_address," : "", - dump_blocks ? "dump_blocks," : "", - dump_layout ? "dump_layout," : "", - dump_offsets != NULL ? "dump_offsets=[" : "", - dump_offsets != NULL ? dump_offsets : "", - dump_offsets != NULL ? "]," : "", - dump_pages ? "dump_pages," : "")) != 0) { - (void)util_err(session, ret, NULL); - goto err; - } - } - if ((ret = session->verify(session, uri, config)) != 0) - (void)util_err(session, ret, "session.verify: %s", uri); - else { - /* - * Verbose configures a progress counter, move to the next - * line. - */ - if (verbose) - printf("\n"); - } + /* Build the configuration string as necessary. */ + if (dump_address || dump_blocks || dump_layout || dump_offsets != NULL || dump_pages) { + size = strlen("dump_address,") + strlen("dump_blocks,") + strlen("dump_layout,") + + strlen("dump_pages,") + strlen("dump_offsets[],") + + (dump_offsets == NULL ? 0 : strlen(dump_offsets)) + 20; + if ((config = malloc(size)) == NULL) { + ret = util_err(session, errno, NULL); + goto err; + } + if ((ret = __wt_snprintf(config, size, "%s%s%s%s%s%s%s", + dump_address ? "dump_address," : "", dump_blocks ? "dump_blocks," : "", + dump_layout ? "dump_layout," : "", dump_offsets != NULL ? "dump_offsets=[" : "", + dump_offsets != NULL ? dump_offsets : "", dump_offsets != NULL ? "]," : "", + dump_pages ? "dump_pages," : "")) != 0) { + (void)util_err(session, ret, NULL); + goto err; + } + } + if ((ret = session->verify(session, uri, config)) != 0) + (void)util_err(session, ret, "session.verify: %s", uri); + else { + /* + * Verbose configures a progress counter, move to the next line. + */ + if (verbose) + printf("\n"); + } -err: free(config); - free(uri); - return (ret); +err: + free(config); + free(uri); + return (ret); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "verify %s\n", - progname, usage_prefix, - "[-d dump_address | dump_blocks | dump_layout | " - "dump_offsets=#,# | dump_pages] uri"); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "verify %s\n", + progname, usage_prefix, + "[-d dump_address | dump_blocks | dump_layout | " + "dump_offsets=#,# | dump_pages] uri"); + return (1); } diff --git a/src/third_party/wiredtiger/src/utilities/util_write.c b/src/third_party/wiredtiger/src/utilities/util_write.c index 399acd9fb0c..7101ab585c3 100644 --- a/src/third_party/wiredtiger/src/utilities/util_write.c +++ b/src/third_party/wiredtiger/src/utilities/util_write.c @@ -13,107 +13,102 @@ static int usage(void); int util_write(WT_SESSION *session, int argc, char *argv[]) { - WT_CURSOR *cursor; - WT_DECL_RET; - uint64_t recno; - int ch; - char *uri, config[100]; - bool append, overwrite, rkey; + WT_CURSOR *cursor; + WT_DECL_RET; + uint64_t recno; + int ch; + char *uri, config[100]; + bool append, overwrite, rkey; - append = overwrite = false; - uri = NULL; - while ((ch = __wt_getopt(progname, argc, argv, "ao")) != EOF) - switch (ch) { - case 'a': - append = true; - break; - case 'o': - overwrite = true; - break; - case '?': - default: - return (usage()); - } - argc -= __wt_optind; - argv += __wt_optind; + append = overwrite = false; + uri = NULL; + while ((ch = __wt_getopt(progname, argc, argv, "ao")) != EOF) + switch (ch) { + case 'a': + append = true; + break; + case 'o': + overwrite = true; + break; + case '?': + default: + return (usage()); + } + argc -= __wt_optind; + argv += __wt_optind; - /* - * The remaining arguments are a uri followed by a list of values (if - * append is set), or key/value pairs (if append is not set). - */ - if (append) { - if (argc < 2) - return (usage()); - } else - if (argc < 3 || ((argc - 1) % 2 != 0)) - return (usage()); - if ((uri = util_uri(session, *argv, "table")) == NULL) - return (1); + /* + * The remaining arguments are a uri followed by a list of values (if append is set), or + * key/value pairs (if append is not set). + */ + if (append) { + if (argc < 2) + return (usage()); + } else if (argc < 3 || ((argc - 1) % 2 != 0)) + return (usage()); + if ((uri = util_uri(session, *argv, "table")) == NULL) + return (1); - /* - * Open the object; free allocated memory immediately to simplify - * future error handling. - */ - if ((ret = __wt_snprintf(config, sizeof(config), "%s,%s", - append ? "append=true" : "", - overwrite ? "overwrite=true" : "")) != 0) { - free(uri); - return (util_err(session, ret, NULL)); - } - if ((ret = - session->open_cursor(session, uri, NULL, config, &cursor)) != 0) - (void)util_err(session, ret, "%s: session.open_cursor", uri); - free(uri); - if (ret != 0) - return (ret); + /* + * Open the object; free allocated memory immediately to simplify future error handling. + */ + if ((ret = __wt_snprintf(config, sizeof(config), "%s,%s", append ? "append=true" : "", + overwrite ? "overwrite=true" : "")) != 0) { + free(uri); + return (util_err(session, ret, NULL)); + } + if ((ret = session->open_cursor(session, uri, NULL, config, &cursor)) != 0) + (void)util_err(session, ret, "%s: session.open_cursor", uri); + free(uri); + if (ret != 0) + return (ret); - /* - * A simple search only makes sense if the key format is a string or a - * record number, and the value format is a single string. - */ - if (!WT_STREQ(cursor->key_format, "r") && - !WT_STREQ(cursor->key_format, "S")) { - fprintf(stderr, - "%s: write command only possible when the key format is " - "a record number or string\n", - progname); - return (1); - } - rkey = WT_STREQ(cursor->key_format, "r"); - if (!WT_STREQ(cursor->value_format, "S")) { - fprintf(stderr, - "%s: write command only possible when the value format is " - "a string\n", - progname); - return (1); - } + /* + * A simple search only makes sense if the key format is a string or a record number, and the + * value format is a single string. + */ + if (!WT_STREQ(cursor->key_format, "r") && !WT_STREQ(cursor->key_format, "S")) { + fprintf(stderr, + "%s: write command only possible when the key format is " + "a record number or string\n", + progname); + return (1); + } + rkey = WT_STREQ(cursor->key_format, "r"); + if (!WT_STREQ(cursor->value_format, "S")) { + fprintf(stderr, + "%s: write command only possible when the value format is " + "a string\n", + progname); + return (1); + } - /* Run through the values or key/value pairs. */ - while (*++argv != NULL) { - if (!append) { - if (rkey) { - if (util_str2num(session, *argv, true, &recno)) - return (1); - cursor->set_key(cursor, recno); - } else - cursor->set_key(cursor, *argv); - ++argv; - } - cursor->set_value(cursor, *argv); + /* Run through the values or key/value pairs. */ + while (*++argv != NULL) { + if (!append) { + if (rkey) { + if (util_str2num(session, *argv, true, &recno)) + return (1); + cursor->set_key(cursor, recno); + } else + cursor->set_key(cursor, *argv); + ++argv; + } + cursor->set_value(cursor, *argv); - if ((ret = cursor->insert(cursor)) != 0) - return (util_cerr(cursor, "search", ret)); - } + if ((ret = cursor->insert(cursor)) != 0) + return (util_cerr(cursor, "search", ret)); + } - return (0); + return (0); } static int usage(void) { - (void)fprintf(stderr, - "usage: %s %s " - "write [-ao] uri key ...\n", - progname, usage_prefix); - return (1); + (void)fprintf(stderr, + "usage: %s %s " + "write [-ao] uri key ...\n", + progname, usage_prefix); + return (1); } |