summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2015-03-20 10:49:41 -0400
committerKeith Bostic <keith@wiredtiger.com>2015-03-20 10:49:41 -0400
commite9bd34719860356f9bcac88a9d8ca6848aeb7855 (patch)
tree149e215ce95ec57dc74042ef5b957a1fcb66697b /src
parent94d3e1ff61eeff4801a64cc6f753eeb7a8eb9650 (diff)
downloadmongo-e9bd34719860356f9bcac88a9d8ca6848aeb7855.tar.gz
Add tests for illegal block compressors.
Diffstat (limited to 'src')
-rw-r--r--src/btree/bt_handle.c52
-rw-r--r--src/config/config_def.c8
-rw-r--r--src/conn/conn_api.c25
-rw-r--r--src/include/extern.h1
4 files changed, 56 insertions, 30 deletions
diff --git a/src/btree/bt_handle.c b/src/btree/bt_handle.c
index b4115117ad5..ff3ff09a7eb 100644
--- a/src/btree/bt_handle.c
+++ b/src/btree/bt_handle.c
@@ -177,6 +177,41 @@ __wt_btree_close(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;
+
+ 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 block 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));
+}
+
+/*
* __btree_conf --
* Configure a WT_BTREE structure.
*/
@@ -185,15 +220,12 @@ __btree_conf(WT_SESSION_IMPL *session, WT_CKPT *ckpt)
{
WT_BTREE *btree;
WT_CONFIG_ITEM cval, metadata;
- WT_CONNECTION_IMPL *conn;
- WT_NAMED_COMPRESSOR *ncomp;
int64_t maj_version, min_version;
uint32_t bitcnt;
int fixed;
const char **cfg;
btree = S2BT(session);
- conn = S2C(session);
cfg = btree->dhandle->cfg;
/* Dump out format information. */
@@ -307,17 +339,9 @@ __btree_conf(WT_SESSION_IMPL *session, WT_CKPT *ckpt)
}
WT_RET(__wt_config_gets_none(session, cfg, "block_compressor", &cval));
- if (cval.len > 0) {
- TAILQ_FOREACH(ncomp, &conn->compqh, q)
- if (WT_STRING_MATCH(ncomp->name, cval.str, cval.len)) {
- btree->compressor = ncomp->compressor;
- break;
- }
- if (btree->compressor == NULL)
- WT_RET_MSG(session, EINVAL,
- "unknown block compressor '%.*s'",
- (int)cval.len, cval.str);
- }
+ if (cval.len > 0)
+ WT_RET(
+ __compressor_confchk(session, &cval, &btree->compressor));
/* Initialize locks. */
WT_RET(__wt_rwlock_alloc(
diff --git a/src/config/config_def.c b/src/config/config_def.c
index 65955240847..83d9401fd5c 100644
--- a/src/config/config_def.c
+++ b/src/config/config_def.c
@@ -142,7 +142,9 @@ static const WT_CONFIG_CHECK confchk_file_meta[] = {
{ "block_allocation", "string",
NULL, "choices=[\"first\",\"best\"]",
NULL },
- { "block_compressor", "string", NULL, NULL, NULL },
+ { "block_compressor", "string",
+ __wt_compressor_confchk, NULL,
+ NULL },
{ "cache_resident", "boolean", NULL, NULL, NULL },
{ "checkpoint", "string", NULL, NULL, NULL },
{ "checkpoint_lsn", "string", NULL, NULL, NULL },
@@ -242,7 +244,9 @@ static const WT_CONFIG_CHECK confchk_session_create[] = {
{ "block_allocation", "string",
NULL, "choices=[\"first\",\"best\"]",
NULL },
- { "block_compressor", "string", NULL, NULL, NULL },
+ { "block_compressor", "string",
+ __wt_compressor_confchk, NULL,
+ NULL },
{ "cache_resident", "boolean", NULL, NULL, NULL },
{ "checksum", "string",
NULL, "choices=[\"on\",\"off\",\"uncompressed\"]",
diff --git a/src/conn/conn_api.c b/src/conn/conn_api.c
index 6880387753a..2b09fcec3dc 100644
--- a/src/conn/conn_api.c
+++ b/src/conn/conn_api.c
@@ -70,24 +70,23 @@ ext_collator_config(WT_EXTENSION_API *wt_api, WT_SESSION *wt_session,
*/
static int
__collator_confchk(
- WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cname, WT_NAMED_COLLATOR **ncollp)
+ WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cname, WT_COLLATOR **collatorp)
{
WT_CONNECTION_IMPL *conn;
WT_NAMED_COLLATOR *ncoll;
- if (ncollp != NULL)
- *ncollp = NULL;
+ if (collatorp != NULL)
+ *collatorp = NULL;
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);
- if (ncollp != NULL)
- *ncollp = ncoll;
- return (0);
+ 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);
}
/*
@@ -110,14 +109,12 @@ __wt_collator_config(WT_SESSION_IMPL *session, const char *uri,
WT_COLLATOR **collatorp, int *ownp)
{
WT_COLLATOR *collator;
- WT_NAMED_COLLATOR *ncoll;
*collatorp = NULL;
*ownp = 0;
- WT_RET(__collator_confchk(session, cname, &ncoll));
+ WT_RET(__collator_confchk(session, cname, &collator));
- collator = ncoll->collator;
if (collator->customize != NULL)
WT_RET(collator->customize(collator,
&session->iface, uri, metadata, collatorp));
diff --git a/src/include/extern.h b/src/include/extern.h
index 5c2fe8f952d..11e26e8480d 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -120,6 +120,7 @@ extern void __wt_free_ref( WT_SESSION_IMPL *session, WT_PAGE *page, WT_REF *ref,
extern void __wt_free_ref_index(WT_SESSION_IMPL *session, WT_PAGE *page, WT_PAGE_INDEX *pindex, int free_pages);
extern int __wt_btree_open(WT_SESSION_IMPL *session, const char *op_cfg[]);
extern int __wt_btree_close(WT_SESSION_IMPL *session);
+extern int __wt_compressor_confchk(WT_SESSION_IMPL *session, WT_CONFIG_ITEM *cval);
extern void __wt_root_ref_init(WT_REF *root_ref, WT_PAGE *root, int is_recno);
extern int __wt_btree_tree_open( WT_SESSION_IMPL *session, const uint8_t *addr, size_t addr_size);
extern int __wt_btree_new_leaf_page(WT_SESSION_IMPL *session, WT_PAGE **pagep);