Skip to content

Commit 12bf329

Browse files
committed
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.
1 parent 20e92c1 commit 12bf329

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

ft/ft-ops.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,7 @@ ft_handle_open(FT_HANDLE ft_h, const char *fname_in_env, int is_create, int only
30283028

30293029
// Ensure that the memcmp magic bits are consistent, if set.
30303030
if (ft->cmp.get_memcmp_magic() != toku::comparator::MEMCMP_MAGIC_NONE &&
3031+
ft_h->options.memcmp_magic != toku::comparator::MEMCMP_MAGIC_NONE &&
30313032
ft_h->options.memcmp_magic != ft->cmp.get_memcmp_magic()) {
30323033
r = EINVAL;
30333034
goto exit;

src/tests/test_memcmp_magic.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void test_memcmp_magic(void) {
106106
// Should be ok to set it more than once, even to different things, before opening.
107107
r = db->set_memcmp_magic(db, 1); CKERR(r);
108108
r = db->set_memcmp_magic(db, 2); CKERR(r);
109-
r = db->open(db, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
109+
r = db->open(db, NULL, "db", "db", DB_BTREE, DB_CREATE, 0666); CKERR(r);
110110

111111
// Can't set the memcmp magic after opening.
112112
r = db->set_memcmp_magic(db, 0); CKERR2(r, EINVAL);
@@ -116,12 +116,17 @@ static void test_memcmp_magic(void) {
116116
r = db_create(&db2, env, 0); CKERR(r);
117117
r = db2->set_memcmp_magic(db2, 3); CKERR(r); // ..we can try setting it to something different
118118
// ..but it should fail to open
119-
r = db2->open(db2, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR2(r, EINVAL);
119+
r = db2->open(db2, NULL, "db", "db", DB_BTREE, DB_CREATE, 0666); CKERR2(r, EINVAL);
120120
r = db2->set_memcmp_magic(db2, 2); CKERR(r);
121-
r = db2->open(db2, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
122-
r = db2->close(db2, 0);
121+
r = db2->open(db2, NULL, "db", "db", DB_BTREE, DB_CREATE, 0666); CKERR(r);
123122

123+
r = db2->close(db2, 0);
124124
r = db->close(db, 0); CKERR(r);
125+
126+
// dbremove opens its own handle internally. ensure that the open
127+
// operation succeeds (and so does dbremove) despite the fact the
128+
// internal open does not set the memcmp magic
129+
r = env->dbremove(env, NULL, "db", "db", 0); CKERR(r);
125130
r = env->close(env, 0); CKERR(r);
126131
}
127132

@@ -155,7 +160,7 @@ static void test_memcmp_magic_sort_order(void) {
155160
DB *db;
156161
r = db_create(&db, env, 0); CKERR(r);
157162
r = db->set_memcmp_magic(db, magic); CKERR(r);
158-
r = db->open(db, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
163+
r = db->open(db, NULL, "db", "db", DB_BTREE, DB_CREATE, 0666); CKERR(r);
159164

160165
for (int i = 0; i < 10000; i++) {
161166
char buf[1 + sizeof(int)];
@@ -192,6 +197,11 @@ static void test_memcmp_magic_sort_order(void) {
192197
txn->commit(txn, 0);
193198

194199
r = db->close(db, 0); CKERR(r);
200+
201+
// dbremove opens its own handle internally. ensure that the open
202+
// operation succeeds (and so does dbremove) despite the fact the
203+
// internal open does not set the memcmp magic
204+
r = env->dbremove(env, NULL, "db", "db", 0); CKERR(r);
195205
r = env->close(env, 0); CKERR(r);
196206
}
197207

0 commit comments

Comments
 (0)