summaryrefslogtreecommitdiff
path: root/test/format
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2015-12-17 12:29:08 -0500
committerKeith Bostic <keith@wiredtiger.com>2015-12-17 12:29:08 -0500
commit1df86bfb7aee39ee716e1c9f9a61fd10b51c3008 (patch)
treef9101be4e7ff989943928dfca81734a20f504763 /test/format
parent1dc735833671840d83dff4b8c47bcf4e9ed0b24c (diff)
downloadmongo-1df86bfb7aee39ee716e1c9f9a61fd10b51c3008.tar.gz
WT-2287: Add support for a WT_SESSION.rebalance method that rebuilds the
underlying btree, correcting any imbalance.
Diffstat (limited to 'test/format')
-rw-r--r--test/format/Makefile.am2
-rw-r--r--test/format/config.c2
-rw-r--r--test/format/config.h6
-rw-r--r--test/format/format.h5
-rw-r--r--test/format/rebalance.c84
-rw-r--r--test/format/t.c5
-rw-r--r--test/format/wts.c26
7 files changed, 125 insertions, 5 deletions
diff --git a/test/format/Makefile.am b/test/format/Makefile.am
index 17cbd53222b..8a2e2b49e4b 100644
--- a/test/format/Makefile.am
+++ b/test/format/Makefile.am
@@ -9,7 +9,7 @@ noinst_PROGRAMS = t
noinst_SCRIPTS = s_dumpcmp
t_SOURCES =\
config.h format.h backup.c bulk.c compact.c config.c lrt.c ops.c \
- salvage.c t.c util.c wts.c
+ rebalance.c salvage.c t.c util.c wts.c
if HAVE_BERKELEY_DB
t_SOURCES += bdb.c
diff --git a/test/format/config.c b/test/format/config.c
index 7aa4575efbd..8651aa9d086 100644
--- a/test/format/config.c
+++ b/test/format/config.c
@@ -331,6 +331,8 @@ config_in_memory(void)
g.c_compression = 0;
if (!config_is_perm("logging"))
g.c_logging = 0;
+ if (!config_is_perm("rebalance"))
+ g.c_rebalance = 0;
if (!config_is_perm("salvage"))
g.c_salvage = 0;
if (!config_is_perm("verify"))
diff --git a/test/format/config.h b/test/format/config.h
index a259217690c..6f97af66719 100644
--- a/test/format/config.h
+++ b/test/format/config.h
@@ -263,8 +263,12 @@ static CONFIG c[] = {
"the number of runs",
C_IGNORE, 0, UINT_MAX, UINT_MAX, &g.c_runs, NULL },
+ { "rebalance",
+ "rebalance testing", /* 100% */
+ C_BOOL, 100, 1, 0, &g.c_rebalance, NULL },
+
{ "salvage",
- "verify integrity via salvage", /* 100% */
+ "salvage testing", /* 100% */
C_BOOL, 100, 1, 0, &g.c_salvage, NULL },
{ "split_pct",
diff --git a/test/format/format.h b/test/format/format.h
index 88300c28292..e15de473e59 100644
--- a/test/format/format.h
+++ b/test/format/format.h
@@ -122,6 +122,8 @@ typedef struct {
char *helium_mount; /* Helium volume */
+ char *wiredtiger_open_config; /* Database open config */
+
#ifdef HAVE_BERKELEY_DB
void *bdb; /* BDB comparison handle */
void *dbc; /* BDB cursor handle */
@@ -216,6 +218,7 @@ typedef struct {
uint32_t c_reverse;
uint32_t c_rows;
uint32_t c_runs;
+ uint32_t c_rebalance;
uint32_t c_salvage;
uint32_t c_split_pct;
uint32_t c_statistics;
@@ -328,6 +331,8 @@ void wts_load(void);
void wts_open(const char *, int, WT_CONNECTION **);
void wts_ops(int);
void wts_read_scan(void);
+void wts_rebalance(void);
+void wts_reopen(void);
void wts_salvage(void);
void wts_stats(void);
void wts_verify(const char *);
diff --git a/test/format/rebalance.c b/test/format/rebalance.c
new file mode 100644
index 00000000000..477368c36db
--- /dev/null
+++ b/test/format/rebalance.c
@@ -0,0 +1,84 @@
+/*-
+ * Public Domain 2014-2015 MongoDB, Inc.
+ * Public Domain 2008-2014 WiredTiger, Inc.
+ *
+ * This is free and unencumbered software released into the public domain.
+ *
+ * Anyone is free to copy, modify, publish, use, compile, sell, or
+ * distribute this software, either in source code form or as a compiled
+ * binary, for any purpose, commercial or non-commercial, and by any
+ * means.
+ *
+ * In jurisdictions that recognize copyright laws, the author or authors
+ * of this software dedicate any and all copyright interest in the
+ * software to the public domain. We make this dedication for the benefit
+ * of the public at large and to the detriment of our heirs and
+ * successors. We intend this dedication to be an overt act of
+ * relinquishment in perpetuity of all present and future rights to this
+ * software under copyright law.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "format.h"
+
+void
+wts_rebalance(void)
+{
+ WT_CONNECTION *conn;
+ WT_SESSION *session;
+ int ret;
+ char cmd[1024];
+
+ if (g.c_rebalance == 0)
+ return;
+
+ track("rebalance", 0ULL, NULL);
+
+ /* Dump the current object. */
+ (void)snprintf(cmd, sizeof(cmd),
+ "../../wt -h %s dump -f %s/rebalance.orig %s",
+ g.home, g.home, g.uri);
+ if ((ret = system(cmd)) != 0)
+ die(ret, "command failed: %s", cmd);
+
+ /* Rebalance, then verify the object. */
+ wts_reopen();
+ conn = g.wts_conn;
+ if ((ret = conn->open_session(conn, NULL, NULL, &session)) != 0)
+ die(ret, "connection.open_session");
+ if (g.logging != 0)
+ (void)g.wt_api->msg_printf(g.wt_api, session,
+ "=============== rebalance start ===============");
+
+ if ((ret = session->rebalance(session, g.uri, NULL)) != 0)
+ die(ret, "session.rebalance: %s: %s", g.uri);
+
+ if (g.logging != 0)
+ (void)g.wt_api->msg_printf(g.wt_api, session,
+ "=============== rebalance stop ===============");
+ if ((ret = session->close(session, NULL)) != 0)
+ die(ret, "session.close");
+
+ wts_verify("post-rebalance verify");
+ wts_close();
+
+ (void)snprintf(cmd, sizeof(cmd),
+ "../../wt -h %s dump -f %s/rebalance.new %s",
+ g.home, g.home, g.uri);
+ if ((ret = system(cmd)) != 0)
+ die(ret, "command failed: %s", cmd);
+
+ /* Compare the old/new versions of the object. */
+ (void)snprintf(cmd, sizeof(cmd),
+ "cmp %s/rebalance.orig %s/rebalance.new > /dev/null",
+ g.home, g.home);
+ if ((ret = system(cmd)) != 0)
+ die(ret, "command failed: %s", cmd);
+}
diff --git a/test/format/t.c b/test/format/t.c
index 603706e0ba1..9687c3c6dba 100644
--- a/test/format/t.c
+++ b/test/format/t.c
@@ -238,6 +238,11 @@ main(int argc, char *argv[])
wts_close();
/*
+ * Rebalance testing.
+ */
+ wts_rebalance();
+
+ /*
* If single-threaded, we can dump and compare the WiredTiger
* and Berkeley DB data sets.
*/
diff --git a/test/format/wts.c b/test/format/wts.c
index c1ea469d7b5..98cb2daa7b9 100644
--- a/test/format/wts.c
+++ b/test/format/wts.c
@@ -132,12 +132,16 @@ wts_open(const char *home, int set_api, WT_CONNECTION **connp)
{
WT_CONNECTION *conn;
int ret;
- char config[4096], *end, *p;
+ char *config, *end, *p;
*connp = NULL;
- p = config;
- end = config + sizeof(config);
+#define WIREDTIGER_OPEN_CONFIG_LEN (4 * 1024)
+ if ((g.wiredtiger_open_config =
+ calloc(WIREDTIGER_OPEN_CONFIG_LEN, sizeof(char))) == NULL)
+ die(ENOMEM, "calloc");
+ config = p = g.wiredtiger_open_config;
+ end = config + WIREDTIGER_OPEN_CONFIG_LEN;
p += snprintf(p, REMAIN(p, end),
"create,checkpoint_sync=false,cache_size=%" PRIu32 "MB",
@@ -273,6 +277,20 @@ wts_open(const char *home, int set_api, WT_CONNECTION **connp)
}
/*
+ * wts_reopen --
+ * Re-open a connection to a WiredTiger database.
+ */
+void
+wts_reopen(void)
+{
+ int ret;
+
+ if ((ret = wiredtiger_open(g.home,
+ &event_handler, g.wiredtiger_open_config, &g.wts_conn)) != 0)
+ die(ret, "wiredtiger_open: %s", g.home);
+}
+
+/*
* wts_create --
* Create the underlying store.
*/
@@ -452,6 +470,8 @@ wts_close(void)
if ((ret = conn->close(conn, config)) != 0)
die(ret, "connection.close");
+ g.wts_conn = NULL;
+ g.wt_api = NULL;
}
void