mirror of
https://github.com/MariaDB/server.git
synced 2025-02-02 12:01:42 +01:00
Addresses #350
Tests on more c_get flags ... git-svn-id: file:///svn/tokudb@2275 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
e1b999bec5
commit
56b15cd8c6
2 changed files with 309 additions and 51 deletions
|
@ -59,3 +59,14 @@ static inline uint32_t myrandom (void) {
|
|||
rstate = (279470275ull*(uint64_t)rstate)%4294967291ull;
|
||||
return rstate;
|
||||
}
|
||||
|
||||
int int_dbt_cmp(DB *db, const DBT *a, const DBT *b) {
|
||||
assert(db && a && b);
|
||||
assert(a->size == sizeof(int));
|
||||
assert(b->size == sizeof(int));
|
||||
|
||||
int x = *(int *) a->data;
|
||||
int y = *(int *) b->data;
|
||||
|
||||
return x - y;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,8 @@ void put(BOOL success, char txn, int _key, int _data) {
|
|||
else CKERR2s(r, DB_LOCK_DEADLOCK, DB_LOCK_NOTGRANTED);
|
||||
}
|
||||
|
||||
void cget(BOOL success, BOOL find, char txn, int _key, int _data) {
|
||||
void cget(BOOL success, BOOL find, char txn, int _key, int _data,
|
||||
int _key_expect, int _data_expect, u_int32_t flags) {
|
||||
assert(txns[(int)txn] && cursors[(int)txn]);
|
||||
|
||||
int r;
|
||||
|
@ -48,9 +49,13 @@ void cget(BOOL success, BOOL find, char txn, int _key, int _data) {
|
|||
r = cursors[(int)txn]->c_get(cursors[(int)txn],
|
||||
dbt_init(&key, &_key, sizeof(int)),
|
||||
dbt_init(&data, &_data, sizeof(int)),
|
||||
DB_SET);
|
||||
flags);
|
||||
if (success) {
|
||||
if (find) CKERR(r);
|
||||
if (find) {
|
||||
CKERR(r);
|
||||
assert(*(int *)key.data == _key_expect);
|
||||
assert(*(int *)data.data == _data_expect);
|
||||
}
|
||||
else CKERR2(r, DB_NOTFOUND);
|
||||
}
|
||||
else CKERR2s(r, DB_LOCK_DEADLOCK, DB_LOCK_NOTGRANTED);
|
||||
|
@ -133,6 +138,10 @@ void setup_dbs(u_int32_t dup_flags) {
|
|||
r = db->set_flags(db, dup_flags);
|
||||
CKERR(r);
|
||||
}
|
||||
r = db->set_bt_compare( db, int_dbt_cmp);
|
||||
CKERR(r);
|
||||
r = db->set_dup_compare(db, int_dbt_cmp);
|
||||
CKERR(r);
|
||||
|
||||
char a;
|
||||
for (a = 'a'; a <= 'z'; a++) init_txn(a);
|
||||
|
@ -159,75 +168,313 @@ void close_dbs(void) {
|
|||
dbenv = NULL;
|
||||
}
|
||||
|
||||
|
||||
void test_abort(u_int32_t dup_flags) {
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 1, 1);
|
||||
early_abort('a');
|
||||
cget(TRUE, FALSE, 'b', 1, 1, 0, 0, DB_SET);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_SET);
|
||||
cget(TRUE, FALSE, 'b', 1, 1, 0, 0, DB_SET);
|
||||
put(FALSE, 'a', 1, 1);
|
||||
early_commit('b');
|
||||
put(TRUE, 'a', 1, 1);
|
||||
cget(TRUE, TRUE, 'a', 1, 1, 1, 1, DB_SET);
|
||||
cget(TRUE, FALSE, 'a', 2, 1, 1, 1, DB_SET);
|
||||
cget(FALSE, TRUE, 'c', 1, 1, 0, 0, DB_SET);
|
||||
early_abort('a');
|
||||
cget(TRUE, FALSE, 'c', 1, 1, 0, 0, DB_SET);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
}
|
||||
|
||||
void test_both(u_int32_t dup_flags, u_int32_t db_flags) {
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, db_flags);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, db_flags);
|
||||
cget(TRUE, FALSE, 'a', 2, 1, 0, 0, db_flags);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, db_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, db_flags);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, db_flags);
|
||||
cget(TRUE, FALSE, 'b', 2, 1, 0, 0, db_flags);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, db_flags);
|
||||
cget(TRUE, FALSE, 'b', 1, 1, 0, 0, db_flags);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, db_flags);
|
||||
cget(TRUE, FALSE, 'b', 1, 1, 0, 0, db_flags);
|
||||
put(FALSE, 'a', 1, 1);
|
||||
early_commit('b');
|
||||
put(TRUE, 'a', 1, 1);
|
||||
cget(TRUE, TRUE, 'a', 1, 1, 1, 1, db_flags);
|
||||
cget(TRUE, FALSE, 'a', 2, 1, 0, 0, db_flags);
|
||||
cget(FALSE, TRUE, 'c', 1, 1, 0, 0, db_flags);
|
||||
early_commit('a');
|
||||
cget(TRUE, TRUE, 'c', 1, 1, 1, 1, db_flags);
|
||||
close_dbs();
|
||||
}
|
||||
|
||||
|
||||
void test_last(u_int32_t dup_flags) {
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 0, 0, 0, 0, DB_LAST);
|
||||
put(FALSE, 'b', 2, 1);
|
||||
put(TRUE, 'a', 2, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 2, 1, DB_LAST);
|
||||
early_commit('a');
|
||||
put(TRUE, 'b', 2, 1);
|
||||
close_dbs();
|
||||
/* ****************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 1, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 1, 1, DB_LAST);
|
||||
put(FALSE, 'b', 2, 1);
|
||||
put(TRUE, 'b', -1, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 1, 1, DB_LAST);
|
||||
close_dbs();
|
||||
/* ****************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 1, 1);
|
||||
put(TRUE, 'a', 3, 1);
|
||||
put(TRUE, 'a', 6, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 6, 1, DB_LAST);
|
||||
put(TRUE, 'b', 2, 1);
|
||||
put(TRUE, 'b', 4, 1);
|
||||
put(FALSE, 'b', 7, 1);
|
||||
put(TRUE, 'b', -1, 1);
|
||||
close_dbs();
|
||||
/* ****************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 1, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 1, 1, DB_LAST);
|
||||
put(dup_flags != 0, 'b', 1, 0);
|
||||
close_dbs();
|
||||
}
|
||||
|
||||
void test_first(u_int32_t dup_flags) {
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 0, 0, 0, 0, DB_FIRST);
|
||||
put(FALSE, 'b', 2, 1);
|
||||
put(TRUE, 'a', 2, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 2, 1, DB_FIRST);
|
||||
early_commit('a');
|
||||
put(TRUE, 'b', 2, 1);
|
||||
close_dbs();
|
||||
/* ****************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 1, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 1, 1, DB_FIRST);
|
||||
put(TRUE, 'b', 2, 1);
|
||||
put(FALSE, 'b', -1, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 1, 1, DB_FIRST);
|
||||
close_dbs();
|
||||
/* ****************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 1, 1);
|
||||
put(TRUE, 'a', 3, 1);
|
||||
put(TRUE, 'a', 6, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 1, 1, DB_FIRST);
|
||||
put(TRUE, 'b', 2, 1);
|
||||
put(TRUE, 'b', 4, 1);
|
||||
put(TRUE, 'b', 7, 1);
|
||||
put(FALSE, 'b', -1, 1);
|
||||
close_dbs();
|
||||
/* ****************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 1, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 1, 1, DB_FIRST);
|
||||
put(dup_flags != 0, 'b', 1, 2);
|
||||
close_dbs();
|
||||
}
|
||||
|
||||
void test_set_range(u_int32_t dup_flags) {
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_SET_RANGE);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_SET_RANGE);
|
||||
cget(TRUE, FALSE, 'a', 2, 1, 0, 0, DB_SET_RANGE);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_SET_RANGE);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_SET_RANGE);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_SET_RANGE);
|
||||
cget(TRUE, FALSE, 'b', 2, 1, 0, 0, DB_SET_RANGE);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_SET_RANGE);
|
||||
cget(TRUE, FALSE, 'b', 1, 1, 0, 0, DB_SET_RANGE);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_SET_RANGE);
|
||||
cget(TRUE, FALSE, 'b', 5, 5, 0, 0, DB_SET_RANGE);
|
||||
put(FALSE, 'a', 7, 6);
|
||||
put(FALSE, 'a', 5, 5);
|
||||
put(TRUE, 'a', 4, 4);
|
||||
put(TRUE, 'b', -1, 4);
|
||||
put(FALSE, 'b', 2, 4);
|
||||
put(FALSE, 'a', 5, 4);
|
||||
early_commit('b');
|
||||
put(TRUE, 'a', 7, 6);
|
||||
put(TRUE, 'a', 5, 5);
|
||||
put(TRUE, 'a', 4, 4);
|
||||
put(TRUE, 'a', 5, 4);
|
||||
cget(TRUE, TRUE, 'a', 1, 1, 4, 4, DB_SET_RANGE);
|
||||
cget(TRUE, TRUE, 'a', 2, 1, 4, 4, DB_SET_RANGE);
|
||||
cget(FALSE, TRUE, 'c', 6, 6, 7, 6, DB_SET_RANGE);
|
||||
early_commit('a');
|
||||
cget(TRUE, TRUE, 'c', 6, 6, 7, 6, DB_SET_RANGE);
|
||||
close_dbs();
|
||||
}
|
||||
|
||||
void test_both_range(u_int32_t dup_flags) {
|
||||
if (dup_flags == 0) {
|
||||
test_both(dup_flags, DB_GET_BOTH_RANGE);
|
||||
return;
|
||||
}
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_GET_BOTH_RANGE);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_GET_BOTH_RANGE);
|
||||
cget(TRUE, FALSE, 'a', 2, 1, 0, 0, DB_GET_BOTH_RANGE);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_GET_BOTH_RANGE);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_GET_BOTH_RANGE);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_GET_BOTH_RANGE);
|
||||
cget(TRUE, FALSE, 'b', 2, 1, 0, 0, DB_GET_BOTH_RANGE);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_GET_BOTH_RANGE);
|
||||
cget(TRUE, FALSE, 'b', 1, 1, 0, 0, DB_GET_BOTH_RANGE);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 0, 0, DB_GET_BOTH_RANGE);
|
||||
cget(TRUE, FALSE, 'b', 5, 5, 0, 0, DB_GET_BOTH_RANGE);
|
||||
put(TRUE, 'a', 5, 0);
|
||||
put(FALSE, 'a', 5, 5);
|
||||
put(FALSE, 'a', 5, 6);
|
||||
put(TRUE, 'a', 6, 0);
|
||||
put(TRUE, 'b', 1, 0);
|
||||
early_commit('b');
|
||||
put(TRUE, 'a', 5, 0);
|
||||
put(TRUE, 'a', 5, 5);
|
||||
put(TRUE, 'a', 5, 6);
|
||||
put(TRUE, 'a', 6, 0);
|
||||
cget(TRUE, FALSE, 'a', 1, 1, 4, 4, DB_GET_BOTH_RANGE);
|
||||
cget(TRUE, TRUE, 'a', 1, 0, 1, 0, DB_GET_BOTH_RANGE);
|
||||
cget(FALSE, TRUE, 'c', 5, 5, 5, 5, DB_GET_BOTH_RANGE);
|
||||
early_commit('a');
|
||||
cget(TRUE, TRUE, 'c', 5, 5, 5, 5, DB_GET_BOTH_RANGE);
|
||||
close_dbs();
|
||||
}
|
||||
|
||||
void test_next(u_int32_t dup_flags, u_int32_t next_type) {
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 2, 1);
|
||||
put(TRUE, 'a', 5, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 2, 1, next_type);
|
||||
put(FALSE, 'b', 2, 1);
|
||||
put(TRUE, 'b', 4, 1);
|
||||
put(FALSE, 'b', -1, 1);
|
||||
cget(FALSE, TRUE, 'a', 0, 0, 4, 1, next_type);
|
||||
early_commit('b');
|
||||
/* We need to keep going from here
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 4, 1, next_type);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 5, 1, next_type);
|
||||
*/
|
||||
close_dbs();
|
||||
/* ****************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 1, 1);
|
||||
put(TRUE, 'a', 3, 1);
|
||||
put(TRUE, 'a', 6, 1);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 1, 1, next_type);
|
||||
cget(TRUE, TRUE, 'a', 0, 0, 3, 1, next_type);
|
||||
put(FALSE, 'b', 2, 1);
|
||||
put(TRUE, 'b', 4, 1);
|
||||
put(TRUE, 'b', 7, 1);
|
||||
put(FALSE, 'b', -1, 1);
|
||||
close_dbs();
|
||||
}
|
||||
|
||||
void test(u_int32_t dup_flags) {
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1);
|
||||
early_abort('a');
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 1, 1);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1);
|
||||
cget(TRUE, FALSE, 'a', 2, 1);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1);
|
||||
cget(TRUE, FALSE, 'a', 1, 1);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1);
|
||||
cget(TRUE, FALSE, 'b', 2, 1);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1);
|
||||
cget(TRUE, FALSE, 'b', 1, 1);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1);
|
||||
cget(TRUE, FALSE, 'b', 1, 1);
|
||||
put(FALSE, 'a', 1, 1);
|
||||
early_commit('b');
|
||||
put(TRUE, 'a', 1, 1);
|
||||
cget(TRUE, TRUE, 'a', 1, 1);
|
||||
cget(TRUE, FALSE, 'a', 2, 1);
|
||||
cget(FALSE, TRUE, 'c', 1, 1);
|
||||
early_commit('a');
|
||||
cget(TRUE, TRUE, 'c', 1, 1);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
put(TRUE, 'a', 1, 1);
|
||||
early_abort('a');
|
||||
cget(TRUE, FALSE, 'b', 1, 1);
|
||||
close_dbs();
|
||||
/* ********************************************************************** */
|
||||
setup_dbs(dup_flags);
|
||||
cget(TRUE, FALSE, 'a', 1, 1);
|
||||
cget(TRUE, FALSE, 'b', 1, 1);
|
||||
put(FALSE, 'a', 1, 1);
|
||||
early_commit('b');
|
||||
put(TRUE, 'a', 1, 1);
|
||||
cget(TRUE, TRUE, 'a', 1, 1);
|
||||
cget(TRUE, FALSE, 'a', 2, 1);
|
||||
cget(FALSE, TRUE, 'c', 1, 1);
|
||||
early_abort('a');
|
||||
cget(TRUE, FALSE, 'c', 1, 1);
|
||||
close_dbs();
|
||||
test_both(dup_flags, DB_SET);
|
||||
test_both(dup_flags, DB_GET_BOTH);
|
||||
/* ********************************************************************** */
|
||||
test_first(dup_flags);
|
||||
/* ********************************************************************** */
|
||||
test_last(dup_flags);
|
||||
/* ********************************************************************** */
|
||||
test_set_range(dup_flags);
|
||||
/* ********************************************************************** */
|
||||
test_both_range(dup_flags);
|
||||
/* ********************************************************************** */
|
||||
test_next(dup_flags, DB_NEXT);
|
||||
test_next(dup_flags, DB_NEXT_NODUP);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
test(0);
|
||||
test(DB_DUP | DB_DUPSORT);
|
||||
/*
|
||||
test_abort(0);
|
||||
test_abort(DB_DUP | DB_DUPSORT);
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue