summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@mongodb.com>2015-02-04 12:09:48 +1100
committerMichael Cahill <michael.cahill@mongodb.com>2015-02-04 12:09:48 +1100
commit222251d1a548f2b17dffdc39d1640a31bd384761 (patch)
treea1ecf5c815aa0eb7809d9e02638c322c4b3fac0a
parentfcd5b44200c4ff2d0ccae7b254c318b0996da567 (diff)
parent4ca235ed265766b9082fc2d133ed5c0d01e49fd9 (diff)
downloadmongo-222251d1a548f2b17dffdc39d1640a31bd384761.tar.gz
Merge pull request #1540 from wiredtiger/huffman-config
Fix huffman config and add huffman tests. #1536
-rw-r--r--src/btree/bt_huffman.c27
-rw-r--r--test/suite/test_huffman01.py76
-rw-r--r--test/suite/test_huffman02.py67
3 files changed, 170 insertions, 0 deletions
diff --git a/src/btree/bt_huffman.c b/src/btree/bt_huffman.c
index c1cf3431c3b..c31b3f2fdf1 100644
--- a/src/btree/bt_huffman.c
+++ b/src/btree/bt_huffman.c
@@ -128,6 +128,30 @@ static const struct __wt_huffman_table __wt_huffman_nytenglish[] = {
static int __wt_huffman_read(WT_SESSION_IMPL *,
WT_CONFIG_ITEM *, struct __wt_huffman_table **, u_int *, u_int *);
+#define WT_HUFFMAN_CONFIG_VALID(str, len) \
+ (WT_STRING_CASE_MATCH("english", (str), (len)) || \
+ WT_PREFIX_MATCH((str), "utf8") || WT_PREFIX_MATCH((str), "utf16"))
+
+/*
+ * __btree_huffman_config --
+ * Verify the key or value strings passed in.
+ */
+static int
+__btree_huffman_config(WT_SESSION_IMPL *session,
+ WT_CONFIG_ITEM *key_conf, WT_CONFIG_ITEM *value_conf)
+{
+ if (key_conf->len != 0 &&
+ !WT_HUFFMAN_CONFIG_VALID(key_conf->str, key_conf->len))
+ WT_RET_MSG(
+ session, EINVAL, "illegal Huffman key configuration");
+ if (value_conf->len != 0 &&
+ !WT_HUFFMAN_CONFIG_VALID(value_conf->str, value_conf->len))
+ WT_RET_MSG(
+ session, EINVAL, "illegal Huffman value configuration");
+ return (0);
+
+}
+
/*
* __wt_btree_huffman_open --
* Configure Huffman encoding for the tree.
@@ -150,6 +174,7 @@ __wt_btree_huffman_open(WT_SESSION_IMPL *session)
__wt_config_gets_none(session, cfg, "huffman_value", &value_conf));
if (key_conf.len == 0 && value_conf.len == 0)
return (0);
+ WT_RET(__btree_huffman_config(session, &key_conf, &value_conf));
switch (btree->type) { /* Check file type compatibility. */
case BTREE_COL_FIX:
@@ -311,6 +336,8 @@ __wt_huffman_read(WT_SESSION_IMPL *session, WT_CONFIG_ITEM *ip,
tp->frequency = (uint32_t)frequency;
}
+ if (ret == EOF)
+ ret = 0;
*entriesp = lineno - 1;
*tablep = table;
diff --git a/test/suite/test_huffman01.py b/test/suite/test_huffman01.py
new file mode 100644
index 00000000000..0c413025e1d
--- /dev/null
+++ b/test/suite/test_huffman01.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+#
+# 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.
+
+import os
+from suite_subprocess import suite_subprocess
+from wtscenario import multiply_scenarios, number_scenarios
+import wiredtiger, wttest
+
+# test_huffman01.py
+# Huffman key and value configurations
+# Basic smoke-test of huffman key and value settings.
+class test_huffman01(wttest.WiredTigerTestCase, suite_subprocess):
+ """
+ Test basic operations
+ """
+ table_name = 'table:test_huff'
+
+ huffkey = [
+ ('none', dict(huffkey='huffman_key=none',kfile=None)),
+ ('english', dict(huffkey='huffman_key=english',kfile=None)),
+ ('English', dict(huffkey='huffman_key=English',kfile=None)),
+ ('utf8', dict(huffkey='huffman_key=utf8t8file',kfile='t8file')),
+ ('utf16', dict(huffkey='huffman_key=utf16t16file',kfile='t16file')),
+ ]
+ huffval = [
+ ('none', dict(huffval=',huffman_value=none',vfile=None)),
+ ('english', dict(huffval=',huffman_value=english',vfile=None)),
+ ('English', dict(huffval=',huffman_value=English',vfile=None)),
+ ('utf8', dict(huffval=',huffman_value=utf8t8file',vfile='t8file')),
+ ('utf16', dict(huffval=',huffman_value=utf16t16file',vfile='t16file')),
+ ]
+ scenarios = number_scenarios(multiply_scenarios('.', huffkey, huffval))
+
+ def test_huffman(self):
+ dir = self.conn.get_home()
+ if self.kfile != None:
+ # For the UTF settings write some made-up frequency information.
+ f = open(dir + '/' + self.kfile, 'w')
+ f.write('48 546233\n49 460946\n')
+ f.close()
+ # if self.vfile != None and not os.path.exists(self.vfile):
+ if self.vfile != None:
+ f = open(dir + '/' + self.vfile, 'w')
+ # For the UTF settings write some made-up frequency information.
+ f.write('50 546233\n51 460946\n')
+ f.close()
+ config=self.huffkey + self.huffval
+ self.session.create(self.table_name, config)
+
+if __name__ == '__main__':
+ wttest.run()
diff --git a/test/suite/test_huffman02.py b/test/suite/test_huffman02.py
new file mode 100644
index 00000000000..d5fd83ab53e
--- /dev/null
+++ b/test/suite/test_huffman02.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+#
+# 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.
+
+import os
+from suite_subprocess import suite_subprocess
+from wtscenario import multiply_scenarios, number_scenarios
+import wiredtiger, wttest
+
+# test_huffman02.py
+# Huffman key and value configurations with bad settings
+class test_huffman02(wttest.WiredTigerTestCase, suite_subprocess):
+ """
+ Test basic operations
+ """
+ table_name = 'table:test_huff'
+
+ huffkey = [
+ ('none', dict(huffkey='huffman_key=none')),
+ ('english', dict(huffkey='huffman_key=english')),
+ ('bad', dict(huffkey='huffman_key=bad')),
+ ]
+ huffval = [
+ ('bad', dict(huffval=',huffman_value=bad')),
+ ]
+ scenarios = number_scenarios(multiply_scenarios('.', huffkey, huffval))
+
+ def test_huffman(self):
+ gotException = False
+ expectMessage = 'illegal Huffman'
+ config=self.huffkey + self.huffval
+ with self.expectedStderrPattern(expectMessage):
+ try:
+ self.pr('expect an error message...')
+ self.session.create(self.table_name, config)
+ except wiredtiger.WiredTigerError as e:
+ gotException = True
+ self.pr('got expected exception: ' + str(e))
+ self.assertTrue(str(e).find('nvalid argument') >= 0)
+ self.assertTrue(gotException, 'expected exception')
+
+if __name__ == '__main__':
+ wttest.run()