summaryrefslogtreecommitdiff
path: root/src/conn
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2015-03-22 19:57:16 -0400
committerKeith Bostic <keith@wiredtiger.com>2015-03-22 19:57:16 -0400
commit77df602059f076d0b42cd29fcaaf1b9e72d783c7 (patch)
tree74bd4bce512ee062f3ec97eca46b20f095c59683 /src/conn
parent49ddcca712db3a50c390f48b518f0835f28bc9d4 (diff)
parentc00b2d00ae9a2de48cd984b3aee3f1e2a608446b (diff)
downloadmongo-77df602059f076d0b42cd29fcaaf1b9e72d783c7.tar.gz
Merge branch 'develop' into base-config-crash
Diffstat (limited to 'src/conn')
-rw-r--r--src/conn/conn_api.c178
-rw-r--r--src/conn/conn_handle.c3
-rw-r--r--src/conn/conn_log.c15
-rw-r--r--src/conn/conn_open.c2
4 files changed, 146 insertions, 52 deletions
diff --git a/src/conn/conn_api.c b/src/conn/conn_api.c
index db23ed9ef02..179f1cbb29f 100644
--- a/src/conn/conn_api.c
+++ b/src/conn/conn_api.c
@@ -65,6 +65,44 @@ ext_collator_config(WT_EXTENSION_API *wt_api, WT_SESSION *wt_session,
}
/*
+ * __collator_confchk --
+ * Check for a valid custom collator.
+ */
+static int
+__collator_confchk(
+ WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cname, WT_COLLATOR **collatorp)
+{
+ WT_CONNECTION_IMPL *conn;
+ WT_NAMED_COLLATOR *ncoll;
+
+ if (collatorp != NULL)
+ *collatorp = NULL;
+
+ if (cname->len == 0 || WT_STRING_MATCH("none", cname->str, cname->len))
+ return (0);
+
+ conn = S2C(session);
+ TAILQ_FOREACH(ncoll, &conn->collqh, q)
+ if (WT_STRING_MATCH(ncoll->name, cname->str, cname->len)) {
+ if (collatorp != NULL)
+ *collatorp = ncoll->collator;
+ return (0);
+ }
+ WT_RET_MSG(session, EINVAL,
+ "unknown collator '%.*s'", (int)cname->len, cname->str);
+}
+
+/*
+ * __wt_collator_confchk --
+ * Check for a valid custom collator (public).
+ */
+int
+__wt_collator_confchk(WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cname)
+{
+ return (__collator_confchk(session, cname, NULL));
+}
+
+/*
* __wt_collator_config --
* Configure a custom collator.
*/
@@ -74,23 +112,14 @@ __wt_collator_config(WT_SESSION_IMPL *session, const char *uri,
WT_COLLATOR **collatorp, int *ownp)
{
WT_COLLATOR *collator;
- WT_CONNECTION_IMPL *conn;
- WT_NAMED_COLLATOR *ncoll;
*collatorp = NULL;
*ownp = 0;
- conn = S2C(session);
-
- TAILQ_FOREACH(ncoll, &conn->collqh, q)
- if (WT_STRING_MATCH(ncoll->name, cname->str, cname->len))
- break;
-
- if (ncoll == NULL)
- WT_RET_MSG(session, EINVAL,
- "unknown collator '%.*s'", (int)cname->len, cname->str);
+ WT_RET(__collator_confchk(session, cname, &collator));
+ if (collator == NULL)
+ return (0);
- collator = ncoll->collator;
if (collator->customize != NULL)
WT_RET(collator->customize(collator,
&session->iface, uri, metadata, collatorp));
@@ -346,6 +375,55 @@ __wt_conn_remove_collator(WT_SESSION_IMPL *session)
}
/*
+ * __compressor_confchk --
+ * Validate the compressor.
+ */
+static int
+__compressor_confchk(
+ WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cval, WT_COMPRESSOR **compressorp)
+{
+ WT_CONNECTION_IMPL *conn;
+ WT_NAMED_COMPRESSOR *ncomp;
+
+ if (compressorp != NULL)
+ *compressorp = NULL;
+
+ if (cval->len == 0 || WT_STRING_MATCH("none", cval->str, cval->len))
+ return (0);
+
+ conn = S2C(session);
+ TAILQ_FOREACH(ncomp, &conn->compqh, q)
+ if (WT_STRING_MATCH(ncomp->name, cval->str, cval->len)) {
+ if (compressorp != NULL)
+ *compressorp = ncomp->compressor;
+ return (0);
+ }
+ WT_RET_MSG(session, EINVAL,
+ "unknown compressor '%.*s'", (int)cval->len, cval->str);
+}
+
+/*
+ * __wt_compressor_confchk --
+ * Validate the compressor (public).
+ */
+int
+__wt_compressor_confchk(WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cval)
+{
+ return (__compressor_confchk(session, cval, NULL));
+}
+
+/*
+ * __wt_compressor_config --
+ * Given a configuration, configure the compressor.
+ */
+int
+__wt_compressor_config(
+ WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cval, WT_COMPRESSOR **compressorp)
+{
+ return (__compressor_confchk(session, cval, compressorp));
+}
+
+/*
* __conn_add_compressor --
* WT_CONNECTION->add_compressor method.
*/
@@ -522,6 +600,44 @@ err: if (nextractor != NULL) {
}
/*
+ * __extractor_confchk --
+ * Check for a valid custom extractor.
+ */
+static int
+__extractor_confchk(
+ WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cname, WT_EXTRACTOR **extractorp)
+{
+ WT_CONNECTION_IMPL *conn;
+ WT_NAMED_EXTRACTOR *nextractor;
+
+ if (extractorp != NULL)
+ *extractorp = NULL;
+
+ if (cname->len == 0 || WT_STRING_MATCH("none", cname->str, cname->len))
+ return (0);
+
+ conn = S2C(session);
+ TAILQ_FOREACH(nextractor, &conn->extractorqh, q)
+ if (WT_STRING_MATCH(nextractor->name, cname->str, cname->len)) {
+ if (extractorp != NULL)
+ *extractorp = nextractor->extractor;
+ return (0);
+ }
+ WT_RET_MSG(session, EINVAL,
+ "unknown extractor '%.*s'", (int)cname->len, cname->str);
+}
+
+/*
+ * __wt_extractor_confchk --
+ * Check for a valid custom extractor (public).
+ */
+int
+__wt_extractor_confchk(WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cname)
+{
+ return (__extractor_confchk(session, cname, NULL));
+}
+
+/*
* __wt_extractor_config --
* Given a configuration, configure the extractor.
*/
@@ -529,38 +645,30 @@ int
__wt_extractor_config(WT_SESSION_IMPL *session,
const char *config, WT_EXTRACTOR **extractorp, int *ownp)
{
- WT_CONNECTION_IMPL *conn;
- WT_CONFIG_ITEM cval;
- WT_NAMED_EXTRACTOR *nextractor;
+ WT_CONFIG_ITEM cname;
+ WT_EXTRACTOR *extractor;
*extractorp = NULL;
*ownp = 0;
- conn = S2C(session);
-
WT_RET_NOTFOUND_OK(
- __wt_config_getones_none(session, config, "extractor", &cval));
- if (cval.len == 0)
+ __wt_config_getones_none(session, config, "extractor", &cname));
+ if (cname.len == 0)
return (0);
- TAILQ_FOREACH(nextractor, &conn->extractorqh, q)
- if (WT_STRING_MATCH(nextractor->name, cval.str, cval.len))
- break;
-
- if (nextractor == NULL)
- WT_RET_MSG(session, EINVAL,
- "unknown extractor '%.*s'", (int)cval.len, cval.str);
+ WT_RET(__extractor_confchk(session, &cname, &extractor));
+ if (extractor == NULL)
+ return (0);
- if (nextractor->extractor->customize != NULL) {
+ if (extractor->customize != NULL) {
WT_RET(__wt_config_getones(session,
- config, "app_metadata", &cval));
- WT_RET(nextractor->extractor->customize(
- nextractor->extractor, &session->iface,
- session->dhandle->name, &cval, extractorp));
+ config, "app_metadata", &cname));
+ WT_RET(extractor->customize(extractor, &session->iface,
+ session->dhandle->name, &cname, extractorp));
}
if (*extractorp == NULL)
- *extractorp = nextractor->extractor;
+ *extractorp = extractor;
else
*ownp = 1;
@@ -987,8 +1095,7 @@ __conn_config_file(WT_SESSION_IMPL *session,
/* Append it to the stack. */
__conn_config_append(cfg, cbuf->data);
-err: if (fh != NULL)
- WT_TRET(__wt_close(session, fh));
+err: WT_TRET(__wt_close(session, &fh));
return (ret);
}
@@ -1217,8 +1324,7 @@ err: /*
* We ignore the connection's lock file handle on error, it will be
* closed when the connection structure is destroyed.
*/
- if (fh != NULL)
- WT_TRET(__wt_close(session, fh));
+ WT_TRET(__wt_close(session, &fh));
__wt_spin_unlock(session, &__wt_process.spinlock);
return (ret);
diff --git a/src/conn/conn_handle.c b/src/conn/conn_handle.c
index 63bb9af5842..b212409be80 100644
--- a/src/conn/conn_handle.c
+++ b/src/conn/conn_handle.c
@@ -116,8 +116,7 @@ __wt_connection_destroy(WT_CONNECTION_IMPL *conn)
* underlying file-close code uses the mutex to guard lists of
* open files.
*/
- if (conn->lock_fh != NULL)
- WT_TRET(__wt_close(session, conn->lock_fh));
+ WT_TRET(__wt_close(session, &conn->lock_fh));
/* Remove from the list of connections. */
__wt_spin_lock(session, &__wt_process.spinlock);
diff --git a/src/conn/conn_log.c b/src/conn/conn_log.c
index 315e93c1875..4b995114b09 100644
--- a/src/conn/conn_log.c
+++ b/src/conn/conn_log.c
@@ -46,7 +46,6 @@ __logmgr_config(WT_SESSION_IMPL *session, const char **cfg, int *runp)
{
WT_CONFIG_ITEM cval;
WT_CONNECTION_IMPL *conn;
- WT_NAMED_COMPRESSOR *ncomp;
conn = S2C(session);
@@ -62,17 +61,7 @@ __logmgr_config(WT_SESSION_IMPL *session, const char **cfg, int *runp)
*/
conn->log_compressor = NULL;
WT_RET(__wt_config_gets_none(session, cfg, "log.compressor", &cval));
- if (cval.len > 0) {
- TAILQ_FOREACH(ncomp, &conn->compqh, q)
- if (WT_STRING_MATCH(ncomp->name, cval.str, cval.len)) {
- conn->log_compressor = ncomp->compressor;
- break;
- }
- if (conn->log_compressor == NULL)
- WT_RET_MSG(session, EINVAL,
- "unknown log compressor '%.*s'",
- (int)cval.len, cval.str);
- }
+ WT_RET(__wt_compressor_config(session, &cval, &conn->log_compressor));
WT_RET(__wt_config_gets(session, cfg, "log.path", &cval));
WT_RET(__wt_strndup(session, cval.str, cval.len, &conn->log_path));
@@ -327,7 +316,7 @@ __log_close_server(void *arg)
WT_ERR(__wt_fsync(session, close_fh));
__wt_spin_lock(session, &log->log_sync_lock);
locked = 1;
- WT_ERR(__wt_close(session, close_fh));
+ WT_ERR(__wt_close(session, &close_fh));
log->sync_lsn = close_end_lsn;
WT_ERR(__wt_cond_signal(session, log->log_sync_cond));
locked = 0;
diff --git a/src/conn/conn_open.c b/src/conn/conn_open.c
index 0a3d35ac0b1..86f62e176ad 100644
--- a/src/conn/conn_open.c
+++ b/src/conn/conn_open.c
@@ -149,7 +149,7 @@ __wt_connection_close(WT_CONNECTION_IMPL *conn)
__wt_errx(session,
"Connection has open file handles: %s", fh->name);
- WT_TRET(__wt_close(session, fh));
+ WT_TRET(__wt_close(session, &fh));
fh = SLIST_FIRST(&conn->fhlh);
}