summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2012-06-20 20:43:32 +1000
committerMichael Cahill <michael.cahill@wiredtiger.com>2012-06-20 20:43:32 +1000
commitc3b6b3844d63661e67050485595b6158bb80138a (patch)
treeb9e5fd276733856ca2fd9c342f92bdd7cf082104
parent1cde95e2858baf5a3a9b5c4a7ba94865cbdaf557 (diff)
downloadmongo-c3b6b3844d63661e67050485595b6158bb80138a.tar.gz
Finish the implementation of reconfigure methods: allow flags to be turned off, add support for verbose and cache size.
-rw-r--r--src/btree/bt_cache.c30
-rw-r--r--src/conn/conn_api.c103
-rw-r--r--src/cursor/cur_file.c2
-rw-r--r--src/cursor/cur_std.c65
-rw-r--r--src/cursor/cur_table.c2
-rw-r--r--src/include/error.h5
-rw-r--r--src/include/extern.h1
-rw-r--r--src/include/wiredtiger.in56
8 files changed, 148 insertions, 116 deletions
diff --git a/src/btree/bt_cache.c b/src/btree/bt_cache.c
index 2c7584fd349..ec2b030923a 100644
--- a/src/btree/bt_cache.c
+++ b/src/btree/bt_cache.c
@@ -22,27 +22,19 @@ __wt_cache_config(WT_CONNECTION_IMPL *conn, const char *cfg[])
session = conn->default_session;
cache = conn->cache;
- switch (ret =
- __wt_config_gets(session, cfg, "eviction_target", &cval)) {
- case 0:
+ if ((ret = __wt_config_gets(session, cfg, "cache_size", &cval)) == 0)
+ conn->cache_size = cval.val;
+ WT_RET_NOTFOUND_OK(ret);
+
+ if ((ret =
+ __wt_config_gets(session, cfg, "eviction_target", &cval)) == 0)
cache->eviction_target = (u_int)cval.val;
- break;
- case WT_NOTFOUND:
- break;
- default:
- return (ret);
- }
-
- switch (ret =
- __wt_config_gets(session, cfg, "eviction_trigger", &cval)) {
- case 0:
+ WT_RET_NOTFOUND_OK(ret);
+
+ if ((ret =
+ __wt_config_gets(session, cfg, "eviction_trigger", &cval)) == 0)
cache->eviction_trigger = (u_int)cval.val;
- break;
- case WT_NOTFOUND:
- break;
- default:
- return (ret);
- }
+ WT_RET_NOTFOUND_OK(ret);
return (0);
}
diff --git a/src/conn/conn_api.c b/src/conn/conn_api.c
index 3346232b0aa..c06ca4df6a3 100644
--- a/src/conn/conn_api.c
+++ b/src/conn/conn_api.c
@@ -7,6 +7,8 @@
#include "wt_internal.h"
+static int __conn_verbose_config(WT_SESSION_IMPL *, const char *[]);
+
/*
* api_err_printf --
* Extension API call to print to the error stream.
@@ -340,21 +342,28 @@ err: API_END_NOTFOUND_MAP(session, ret);
}
/*
- * __conn_config --
- * WT_CONNECTION->config method.
+ * __conn_reconfigure --
+ * WT_CONNECTION->reconfigure method.
*/
static int
-__conn_config(WT_CONNECTION *wt_conn, const char *config)
+__conn_reconfigure(WT_CONNECTION *wt_conn, const char *config)
{
WT_CONNECTION_IMPL *conn;
WT_DECL_RET;
WT_SESSION_IMPL *session;
+ const char *raw_cfg[] = { config, NULL };
conn = (WT_CONNECTION_IMPL *)wt_conn;
- CONNECTION_API_CALL(conn, session, config, config, cfg);
+ CONNECTION_API_CALL(conn, session, reconfigure, config, cfg);
+ WT_UNUSED(cfg);
- WT_ERR(__wt_cache_config(conn, cfg));
+ /*
+ * Don't include the default config: only override values the
+ * application sets explicitly.
+ */
+ WT_ERR(__wt_cache_config(conn, raw_cfg));
+ WT_ERR(__conn_verbose_config(session, raw_cfg));
err: API_END(session);
return (ret);
@@ -702,6 +711,54 @@ err: if (conn->lock_fh != NULL) {
}
/*
+ * __conn_verbose_config --
+ * Set verbose configuration.
+ */
+static int
+__conn_verbose_config(WT_SESSION_IMPL *session, const char *cfg[])
+{
+#ifdef HAVE_VERBOSE
+ WT_CONFIG_ITEM cval, sval;
+ WT_CONNECTION_IMPL *conn;
+ WT_DECL_RET;
+ static struct {
+ const char *name;
+ uint32_t flag;
+ } *ft, verbtypes[] = {
+ { "block", WT_VERB_block },
+ { "ckpt", WT_VERB_ckpt },
+ { "evict", WT_VERB_evict },
+ { "evictserver",WT_VERB_evictserver },
+ { "fileops", WT_VERB_fileops },
+ { "hazard", WT_VERB_hazard },
+ { "mutex", WT_VERB_mutex },
+ { "read", WT_VERB_read },
+ { "readserver", WT_VERB_readserver },
+ { "reconcile", WT_VERB_reconcile },
+ { "salvage", WT_VERB_salvage },
+ { "verify", WT_VERB_verify },
+ { "write", WT_VERB_write },
+ { NULL, 0 }
+ };
+
+ conn = S2C(session);
+
+ WT_RET_NOTFOUND_OK(__wt_config_gets(session, cfg, "verbose", &cval));
+ for (ft = verbtypes; ft->name != NULL; ft++) {
+ if ((ret = __wt_config_subgets(
+ session, &cval, ft->name, &sval)) == 0 && sval.val != 0)
+ FLD_SET(conn->verbose, ft->flag);
+ else
+ FLD_CLR(conn->verbose, ft->flag);
+
+ WT_RET_NOTFOUND_OK(ret);
+ }
+#endif
+
+ return (0);
+}
+
+/*
* wiredtiger_open --
* Main library entry point: open a new connection to a WiredTiger
* database.
@@ -717,30 +774,15 @@ wiredtiger_open(const char *home, WT_EVENT_HANDLER *event_handler,
__conn_add_compressor,
__conn_add_extractor,
__conn_close,
- __conn_config,
__conn_get_home,
__conn_is_new,
- __conn_open_session
+ __conn_open_session,
+ __conn_reconfigure
};
static struct {
const char *name;
uint32_t flag;
- } *ft, verbtypes[] = {
- { "block", WT_VERB_block },
- { "ckpt", WT_VERB_ckpt },
- { "evict", WT_VERB_evict },
- { "evictserver",WT_VERB_evictserver },
- { "fileops", WT_VERB_fileops },
- { "hazard", WT_VERB_hazard },
- { "mutex", WT_VERB_mutex },
- { "read", WT_VERB_read },
- { "readserver", WT_VERB_readserver },
- { "reconcile", WT_VERB_reconcile },
- { "salvage", WT_VERB_salvage },
- { "verify", WT_VERB_verify },
- { "write", WT_VERB_write },
- { NULL, 0 }
- }, directio_types[] = {
+ } *ft, directio_types[] = {
{ "data", WT_DIRECTIO_DATA },
{ "log", WT_DIRECTIO_LOG },
{ NULL, 0 }
@@ -799,8 +841,6 @@ wiredtiger_open(const char *home, WT_EVENT_HANDLER *event_handler,
/* Read the environment variable configuration. */
WT_ERR(__conn_config_env(session, cfg));
- WT_ERR(__wt_config_gets(session, cfg, "cache_size", &cval));
- conn->cache_size = cval.val;
WT_ERR(__wt_config_gets(session, cfg, "hazard_max", &cval));
conn->hazard_size = (uint32_t)cval.val;
WT_ERR(__wt_config_gets(session, cfg, "session_max", &cval));
@@ -813,18 +853,7 @@ wiredtiger_open(const char *home, WT_EVENT_HANDLER *event_handler,
F_SET(conn, WT_CONN_TRANSACTIONAL);
/* Configure verbose flags. */
- conn->verbose = 0;
-#ifdef HAVE_VERBOSE
- WT_ERR(__wt_config_gets(session, cfg, "verbose", &cval));
- for (ft = verbtypes; ft->name != NULL; ft++) {
- ret = __wt_config_subgets(session, &cval, ft->name, &sval);
- if (ret == 0) {
- if (sval.val)
- FLD_SET(conn->verbose, ft->flag);
- } else if (ret != WT_NOTFOUND)
- goto err;
- }
-#endif
+ WT_ERR(__conn_verbose_config(session, cfg));
WT_ERR(__wt_config_gets(session, cfg, "logging", &cval));
if (cval.val != 0)
diff --git a/src/cursor/cur_file.c b/src/cursor/cur_file.c
index 64864d57cbc..da7aa592fb6 100644
--- a/src/cursor/cur_file.c
+++ b/src/cursor/cur_file.c
@@ -218,7 +218,7 @@ __wt_curfile_create(WT_SESSION_IMPL *session,
__curfile_update,
__curfile_remove,
__curfile_close,
- __wt_cursor_config,
+ NULL,
{ NULL, NULL }, /* TAILQ_ENTRY q */
0, /* recno key */
{ 0 }, /* recno raw buffer */
diff --git a/src/cursor/cur_std.c b/src/cursor/cur_std.c
index d9ded14f86d..a03dd46e65d 100644
--- a/src/cursor/cur_std.c
+++ b/src/cursor/cur_std.c
@@ -308,55 +308,60 @@ __wt_cursor_close(WT_CURSOR *cursor)
}
/*
- * __cursor_config --
- * Configure a cursor in run-time.
+ * __cursor_runtime_config --
+ * Set runtime-configurable settings.
*/
static int
-__cursor_config(WT_CURSOR *cursor, const char *cfg[])
+__cursor_runtime_config(WT_CURSOR *cursor, const char *cfg[])
{
- WT_CONFIG_ITEM cval;
WT_DECL_RET;
+ WT_CONFIG_ITEM cval;
WT_SESSION_IMPL *session;
session = (WT_SESSION_IMPL *)cursor->session;
/* The append flag is only relevant to column stores. */
- if (WT_CURSOR_RECNO(cursor))
- switch (ret = __wt_config_gets(session, cfg, "append", &cval)) {
- case 0:
- F_SET(cursor, WT_CURSTD_APPEND);
- break;
- case WT_NOTFOUND:
- break;
- default:
- return (ret);
+ if (WT_CURSOR_RECNO(cursor)) {
+ if ((ret =
+ __wt_config_gets(session, cfg, "append", &cval)) == 0) {
+ if (cval.val)
+ F_SET(cursor, WT_CURSTD_APPEND);
+ else
+ F_CLR(cursor, WT_CURSTD_APPEND);
}
+ WT_RET_NOTFOUND_OK(ret);
+ }
- switch (ret = __wt_config_gets(session, cfg, "overwrite", &cval)) {
- case 0:
- F_SET(cursor, WT_CURSTD_OVERWRITE);
- break;
- case WT_NOTFOUND:
- break;
- default:
- return (ret);
+ if ((ret = __wt_config_gets(session, cfg, "overwrite", &cval)) == 0) {
+ if (cval.val)
+ F_SET(cursor, WT_CURSTD_OVERWRITE);
+ else
+ F_CLR(cursor, WT_CURSTD_OVERWRITE);
}
+ WT_RET_NOTFOUND_OK(ret);
return (0);
}
/*
- * __wt_cursor_config --
- * Configure a cursor in run-time.
+ * __cursor_reconfigure --
+ * WT_CURSOR->reconfigure default implementation.
*/
-int
-__wt_cursor_config(WT_CURSOR *cursor, const char *config)
+static int
+__cursor_reconfigure(WT_CURSOR *cursor, const char *config)
{
WT_DECL_RET;
WT_SESSION_IMPL *session;
+ const char *raw_cfg[] = { config, NULL };
+
+ CURSOR_API_CALL(cursor, session, reconfigure, NULL, config, cfg);
- CURSOR_API_CALL(cursor, session, config, NULL, config, cfg);
- WT_ERR(__cursor_config(cursor, cfg));
+ /*
+ * We need to take care here: only override with values that appear in
+ * the config string from the application, not with defaults.
+ */
+ WT_UNUSED(cfg);
+ ret = __cursor_runtime_config(cursor, raw_cfg);
err: API_END(session);
return (ret);
@@ -450,6 +455,8 @@ __wt_cursor_init(WT_CURSOR *cursor,
cursor->equals = __cursor_equals;
if (cursor->search == NULL)
cursor->search = __cursor_search;
+ if (cursor->reconfigure == NULL)
+ cursor->reconfigure = __cursor_reconfigure;
if (cursor->uri == NULL)
WT_RET(__wt_strdup(session, uri, &cursor->uri));
@@ -457,8 +464,8 @@ __wt_cursor_init(WT_CURSOR *cursor,
WT_CLEAR(cursor->key);
WT_CLEAR(cursor->value);
- /* Use a common routine for run-time configuration options. */
- WT_RET(__cursor_config(cursor, cfg));
+ /* Set runtime-configurable settings. */
+ WT_RET(__cursor_runtime_config(cursor, cfg));
WT_RET(__wt_config_gets(session, cfg, "dump", &cval));
if (cval.len != 0) {
diff --git a/src/cursor/cur_table.c b/src/cursor/cur_table.c
index 1df01414f4a..d1e5ef12a80 100644
--- a/src/cursor/cur_table.c
+++ b/src/cursor/cur_table.c
@@ -528,7 +528,7 @@ __wt_curtable_open(WT_SESSION_IMPL *session,
__curtable_update,
__curtable_remove,
__curtable_close,
- __wt_cursor_config,
+ NULL,
{ NULL, NULL }, /* TAILQ_ENTRY q */
0, /* recno key */
{ 0 }, /* raw recno buffer */
diff --git a/src/include/error.h b/src/include/error.h
index c3b02a7da77..dd428d70601 100644
--- a/src/include/error.h
+++ b/src/include/error.h
@@ -57,6 +57,11 @@
__wt_err(session, __ret, __VA_ARGS__); \
return (__ret); \
} while (0)
+#define WT_RET_NOTFOUND_OK(a) do { \
+ int __ret; \
+ if ((__ret = (a)) != 0 && __ret != WT_NOTFOUND) \
+ return (__ret); \
+} while (0)
/* Set "ret" if not already set. */
#define WT_TRET(a) do { \
diff --git a/src/include/extern.h b/src/include/extern.h
index 03409b0f225..a932e722e2b 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -587,7 +587,6 @@ extern void __wt_cursor_set_key(WT_CURSOR *cursor, ...);
extern void __wt_cursor_set_keyv(WT_CURSOR *cursor, uint32_t flags, va_list ap);
extern void __wt_cursor_set_value(WT_CURSOR *cursor, ...);
extern int __wt_cursor_close(WT_CURSOR *cursor);
-extern int __wt_cursor_config(WT_CURSOR *cursor, const char *config);
extern int __wt_cursor_dup(WT_SESSION_IMPL *session,
WT_CURSOR *to_dup,
const char *config,
diff --git a/src/include/wiredtiger.in b/src/include/wiredtiger.in
index 1f086e635d9..6864c353dea 100644
--- a/src/include/wiredtiger.in
+++ b/src/include/wiredtiger.in
@@ -988,34 +988,6 @@ struct __wt_connection {
*/
int __F(close)(WT_CONNECTION *connection, const char *config);
- /*! Reconfigure a connection at run-time.
- *
- * @snippet ex_all.c Reconfigure a connection
- *
- * @param connection the connection handle
- * @configstart{connection.reconfigure, see dist/api_data.py}
- * @config{cache_size, maximum heap memory to allocate for the cache.,an
- * integer between 1MB and 10TB; default \c 100MB.}
- * @config{error_prefix, prefix string for error messages.,a string;
- * default empty.}
- * @config{eviction_target, continue evicting until the cache becomes
- * less full than this (as a percentage). Must be less than \c
- * eviction_trigger.,an integer between 10 and 99; default \c 80.}
- * @config{eviction_trigger, trigger eviction when the cache becomes
- * this full (as a percentage).,an integer between 10 and 99; default \c
- * 95.}
- * @config{verbose, enable messages for various events. Options are
- * given as a list\, such as
- * <code>"verbose=[evictserver\,read]"</code>.,a list\, with values
- * chosen from the following options: \c "block"\, \c "ckpt"\, \c
- * "evict"\, \c "evictserver"\, \c "fileops"\, \c "hazard"\, \c
- * "mutex"\, \c "read"\, \c "readserver"\, \c "reconcile"\, \c
- * "salvage"\, \c "verify"\, \c "write"; default empty.}
- * @configend
- * @errors
- */
- int __F(reconfigure)(WT_CONNECTION *connection, const char *config);
-
/*! The home directory of the connection.
*
* @snippet ex_all.c Get the database home directory
@@ -1050,6 +1022,34 @@ struct __wt_connection {
int __F(open_session)(WT_CONNECTION *connection,
WT_EVENT_HANDLER *errhandler, const char *config,
WT_SESSION **sessionp);
+
+ /*! Reconfigure a connection at run-time.
+ *
+ * @snippet ex_all.c Reconfigure a connection
+ *
+ * @param connection the connection handle
+ * @configstart{connection.reconfigure, see dist/api_data.py}
+ * @config{cache_size, maximum heap memory to allocate for the cache.,an
+ * integer between 1MB and 10TB; default \c 100MB.}
+ * @config{error_prefix, prefix string for error messages.,a string;
+ * default empty.}
+ * @config{eviction_target, continue evicting until the cache becomes
+ * less full than this (as a percentage). Must be less than \c
+ * eviction_trigger.,an integer between 10 and 99; default \c 80.}
+ * @config{eviction_trigger, trigger eviction when the cache becomes
+ * this full (as a percentage).,an integer between 10 and 99; default \c
+ * 95.}
+ * @config{verbose, enable messages for various events. Options are
+ * given as a list\, such as
+ * <code>"verbose=[evictserver\,read]"</code>.,a list\, with values
+ * chosen from the following options: \c "block"\, \c "ckpt"\, \c
+ * "evict"\, \c "evictserver"\, \c "fileops"\, \c "hazard"\, \c
+ * "mutex"\, \c "read"\, \c "readserver"\, \c "reconcile"\, \c
+ * "salvage"\, \c "verify"\, \c "write"; default empty.}
+ * @configend
+ * @errors
+ */
+ int __F(reconfigure)(WT_CONNECTION *connection, const char *config);
};
/*! Open a connection to a database.