Commit 290d333b authored by John Esmet's avatar John Esmet

FT-273 Fix a bug where we'd overactively assert that the memcmp magic

bits were inconsistent though the handle was opened without those bits
set. This caused dbremove to always fail.
parent 17dcf62c
......@@ -3028,6 +3028,7 @@ ft_handle_open(FT_HANDLE ft_h, const char *fname_in_env, int is_create, int only
// Ensure that the memcmp magic bits are consistent, if set.
if (ft->cmp.get_memcmp_magic() != toku::comparator::MEMCMP_MAGIC_NONE &&
ft_h->options.memcmp_magic != toku::comparator::MEMCMP_MAGIC_NONE &&
ft_h->options.memcmp_magic != ft->cmp.get_memcmp_magic()) {
r = EINVAL;
goto exit;
......
......@@ -106,7 +106,7 @@ static void test_memcmp_magic(void) {
// Should be ok to set it more than once, even to different things, before opening.
r = db->set_memcmp_magic(db, 1); CKERR(r);
r = db->set_memcmp_magic(db, 2); CKERR(r);
r = db->open(db, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
r = db->open(db, NULL, "db", "db", DB_BTREE, DB_CREATE, 0666); CKERR(r);
// Can't set the memcmp magic after opening.
r = db->set_memcmp_magic(db, 0); CKERR2(r, EINVAL);
......@@ -116,12 +116,17 @@ static void test_memcmp_magic(void) {
r = db_create(&db2, env, 0); CKERR(r);
r = db2->set_memcmp_magic(db2, 3); CKERR(r); // ..we can try setting it to something different
// ..but it should fail to open
r = db2->open(db2, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR2(r, EINVAL);
r = db2->open(db2, NULL, "db", "db", DB_BTREE, DB_CREATE, 0666); CKERR2(r, EINVAL);
r = db2->set_memcmp_magic(db2, 2); CKERR(r);
r = db2->open(db2, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
r = db2->close(db2, 0);
r = db2->open(db2, NULL, "db", "db", DB_BTREE, DB_CREATE, 0666); CKERR(r);
r = db2->close(db2, 0);
r = db->close(db, 0); CKERR(r);
// dbremove opens its own handle internally. ensure that the open
// operation succeeds (and so does dbremove) despite the fact the
// internal open does not set the memcmp magic
r = env->dbremove(env, NULL, "db", "db", 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
}
......@@ -155,7 +160,7 @@ static void test_memcmp_magic_sort_order(void) {
DB *db;
r = db_create(&db, env, 0); CKERR(r);
r = db->set_memcmp_magic(db, magic); CKERR(r);
r = db->open(db, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
r = db->open(db, NULL, "db", "db", DB_BTREE, DB_CREATE, 0666); CKERR(r);
for (int i = 0; i < 10000; i++) {
char buf[1 + sizeof(int)];
......@@ -192,6 +197,11 @@ static void test_memcmp_magic_sort_order(void) {
txn->commit(txn, 0);
r = db->close(db, 0); CKERR(r);
// dbremove opens its own handle internally. ensure that the open
// operation succeeds (and so does dbremove) despite the fact the
// internal open does not set the memcmp magic
r = env->dbremove(env, NULL, "db", "db", 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment