From a91ed13ba84474382b3e89f63053c196faed3bf0 Mon Sep 17 00:00:00 2001 From: Zardosht Kasheff Date: Tue, 16 Apr 2013 23:59:37 -0400 Subject: [PATCH] [t:3266], add tests that verify setting a descriptor during a checkpoint works git-svn-id: file:///svn/toku/tokudb@29160 c7de825b-a66e-492c-adef-691d508d4ae1 --- src/tests/test_trans_desc_during_chkpt.c | 94 +++++++++++++++++++++++ src/tests/test_trans_desc_during_chkpt2.c | 94 +++++++++++++++++++++++ src/tests/test_trans_desc_during_chkpt3.c | 94 +++++++++++++++++++++++ src/tests/test_trans_desc_during_chkpt4.c | 94 +++++++++++++++++++++++ 4 files changed, 376 insertions(+) create mode 100644 src/tests/test_trans_desc_during_chkpt.c create mode 100644 src/tests/test_trans_desc_during_chkpt2.c create mode 100644 src/tests/test_trans_desc_during_chkpt3.c create mode 100644 src/tests/test_trans_desc_during_chkpt4.c diff --git a/src/tests/test_trans_desc_during_chkpt.c b/src/tests/test_trans_desc_during_chkpt.c new file mode 100644 index 00000000000..e9756f141ab --- /dev/null +++ b/src/tests/test_trans_desc_during_chkpt.c @@ -0,0 +1,94 @@ +// test that an update calls back into the update function + +#include "test.h" + +const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE; + +DB_ENV *env; + +u_int32_t four_byte_desc = 101; +u_int64_t eight_byte_desc = 10101; + + +static void assert_desc_four (DB* db) { + assert(db->descriptor->dbt.size == sizeof(four_byte_desc)); + assert(*(u_int32_t *)(db->descriptor->dbt.data) == four_byte_desc); +} +static void assert_desc_eight (DB* db) { + assert(db->descriptor->dbt.size == sizeof(eight_byte_desc)); + assert(*(u_int32_t *)(db->descriptor->dbt.data) == eight_byte_desc); +} + +static void checkpoint_callback_1(void * extra) { + assert(extra == NULL); + DB* db = NULL; + + DBT change_descriptor; + memset(&change_descriptor, 0, sizeof(change_descriptor)); + change_descriptor.size = sizeof(eight_byte_desc); + change_descriptor.data = &eight_byte_desc; + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_four(db); + IN_TXN_COMMIT(env, NULL, txn_change, 0, { + CHK(db->change_descriptor(db, txn_change, &change_descriptor, 0)); + assert_desc_eight(db); + }); + assert_desc_eight(db); + CHK(db->close(db,0)); +} + +static void setup (void) { + CHK(system("rm -rf " ENVDIR)); + CHK(toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO)); + CHK(db_env_create(&env, 0)); + db_env_set_checkpoint_callback(checkpoint_callback_1, NULL); + env->set_errfile(env, stderr); + CHK(env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO)); +} + +static void cleanup (void) { + CHK(env->close(env, 0)); +} + +static void run_test(void) { + DB* db = NULL; + + DBT orig_desc; + memset(&orig_desc, 0, sizeof(orig_desc)); + orig_desc.size = sizeof(four_byte_desc); + orig_desc.data = &four_byte_desc; + // verify we can only set a descriptor with version 1 + IN_TXN_COMMIT(env, NULL, txn_create, 0, { + CHK(db_create(&db, env, 0)); + assert(db->descriptor == NULL); + CHK(db->open(db, txn_create, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666)); + CHK(db->change_descriptor(db, txn_create, &orig_desc, 0)); + assert_desc_four(db); + }); + assert_desc_four(db); + CHK(db->close(db,0)); + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_four(db); + CHK(db->close(db,0)); + + CHK(env->txn_checkpoint(env, 0, 0, 0)); + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_eight(db); + CHK(db->close(db,0)); + + db = NULL; +} + +int test_main (int argc, char * const argv[]) { + parse_args(argc, argv); + setup(); + run_test(); + cleanup(); + return 0; +} diff --git a/src/tests/test_trans_desc_during_chkpt2.c b/src/tests/test_trans_desc_during_chkpt2.c new file mode 100644 index 00000000000..f87baceed54 --- /dev/null +++ b/src/tests/test_trans_desc_during_chkpt2.c @@ -0,0 +1,94 @@ +// test that an update calls back into the update function + +#include "test.h" + +const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE; + +DB_ENV *env; + +u_int32_t four_byte_desc = 101; +u_int64_t eight_byte_desc = 10101; + + +static void assert_desc_four (DB* db) { + assert(db->descriptor->dbt.size == sizeof(four_byte_desc)); + assert(*(u_int32_t *)(db->descriptor->dbt.data) == four_byte_desc); +} +static void assert_desc_eight (DB* db) { + assert(db->descriptor->dbt.size == sizeof(eight_byte_desc)); + assert(*(u_int32_t *)(db->descriptor->dbt.data) == eight_byte_desc); +} + +static void checkpoint_callback_1(void * extra) { + assert(extra == NULL); + DB* db = NULL; + + DBT change_descriptor; + memset(&change_descriptor, 0, sizeof(change_descriptor)); + change_descriptor.size = sizeof(eight_byte_desc); + change_descriptor.data = &eight_byte_desc; + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_four(db); + IN_TXN_ABORT(env, NULL, txn_change, 0, { + CHK(db->change_descriptor(db, txn_change, &change_descriptor, 0)); + assert_desc_eight(db); + }); + assert_desc_four(db); + CHK(db->close(db,0)); +} + +static void setup (void) { + CHK(system("rm -rf " ENVDIR)); + CHK(toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO)); + CHK(db_env_create(&env, 0)); + db_env_set_checkpoint_callback(checkpoint_callback_1, NULL); + env->set_errfile(env, stderr); + CHK(env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO)); +} + +static void cleanup (void) { + CHK(env->close(env, 0)); +} + +static void run_test(void) { + DB* db = NULL; + + DBT orig_desc; + memset(&orig_desc, 0, sizeof(orig_desc)); + orig_desc.size = sizeof(four_byte_desc); + orig_desc.data = &four_byte_desc; + // verify we can only set a descriptor with version 1 + IN_TXN_COMMIT(env, NULL, txn_create, 0, { + CHK(db_create(&db, env, 0)); + assert(db->descriptor == NULL); + CHK(db->open(db, txn_create, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666)); + CHK(db->change_descriptor(db, txn_create, &orig_desc, 0)); + assert_desc_four(db); + }); + assert_desc_four(db); + CHK(db->close(db,0)); + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_four(db); + CHK(db->close(db,0)); + + CHK(env->txn_checkpoint(env, 0, 0, 0)); + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_four(db); + CHK(db->close(db,0)); + + db = NULL; +} + +int test_main (int argc, char * const argv[]) { + parse_args(argc, argv); + setup(); + run_test(); + cleanup(); + return 0; +} diff --git a/src/tests/test_trans_desc_during_chkpt3.c b/src/tests/test_trans_desc_during_chkpt3.c new file mode 100644 index 00000000000..26de035e6c0 --- /dev/null +++ b/src/tests/test_trans_desc_during_chkpt3.c @@ -0,0 +1,94 @@ +// test that an update calls back into the update function + +#include "test.h" + +const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE; + +DB_ENV *env; + +u_int32_t four_byte_desc = 101; +u_int64_t eight_byte_desc = 10101; + + +static void assert_desc_four (DB* db) { + assert(db->descriptor->dbt.size == sizeof(four_byte_desc)); + assert(*(u_int32_t *)(db->descriptor->dbt.data) == four_byte_desc); +} +static void assert_desc_eight (DB* db) { + assert(db->descriptor->dbt.size == sizeof(eight_byte_desc)); + assert(*(u_int32_t *)(db->descriptor->dbt.data) == eight_byte_desc); +} + +static void checkpoint_callback_1(void * extra) { + assert(extra == NULL); + DB* db = NULL; + + DBT change_descriptor; + memset(&change_descriptor, 0, sizeof(change_descriptor)); + change_descriptor.size = sizeof(eight_byte_desc); + change_descriptor.data = &eight_byte_desc; + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_four(db); + IN_TXN_COMMIT(env, NULL, txn_change, 0, { + CHK(db->change_descriptor(db, txn_change, &change_descriptor, 0)); + assert_desc_eight(db); + }); + assert_desc_eight(db); + CHK(db->close(db,0)); +} + +static void setup (void) { + CHK(system("rm -rf " ENVDIR)); + CHK(toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO)); + CHK(db_env_create(&env, 0)); + db_env_set_checkpoint_callback2(checkpoint_callback_1, NULL); + env->set_errfile(env, stderr); + CHK(env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO)); +} + +static void cleanup (void) { + CHK(env->close(env, 0)); +} + +static void run_test(void) { + DB* db = NULL; + + DBT orig_desc; + memset(&orig_desc, 0, sizeof(orig_desc)); + orig_desc.size = sizeof(four_byte_desc); + orig_desc.data = &four_byte_desc; + // verify we can only set a descriptor with version 1 + IN_TXN_COMMIT(env, NULL, txn_create, 0, { + CHK(db_create(&db, env, 0)); + assert(db->descriptor == NULL); + CHK(db->open(db, txn_create, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666)); + CHK(db->change_descriptor(db, txn_create, &orig_desc, 0)); + assert_desc_four(db); + }); + assert_desc_four(db); + CHK(db->close(db,0)); + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_four(db); + CHK(db->close(db,0)); + + CHK(env->txn_checkpoint(env, 0, 0, 0)); + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_eight(db); + CHK(db->close(db,0)); + + db = NULL; +} + +int test_main (int argc, char * const argv[]) { + parse_args(argc, argv); + setup(); + run_test(); + cleanup(); + return 0; +} diff --git a/src/tests/test_trans_desc_during_chkpt4.c b/src/tests/test_trans_desc_during_chkpt4.c new file mode 100644 index 00000000000..f87baceed54 --- /dev/null +++ b/src/tests/test_trans_desc_during_chkpt4.c @@ -0,0 +1,94 @@ +// test that an update calls back into the update function + +#include "test.h" + +const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE; + +DB_ENV *env; + +u_int32_t four_byte_desc = 101; +u_int64_t eight_byte_desc = 10101; + + +static void assert_desc_four (DB* db) { + assert(db->descriptor->dbt.size == sizeof(four_byte_desc)); + assert(*(u_int32_t *)(db->descriptor->dbt.data) == four_byte_desc); +} +static void assert_desc_eight (DB* db) { + assert(db->descriptor->dbt.size == sizeof(eight_byte_desc)); + assert(*(u_int32_t *)(db->descriptor->dbt.data) == eight_byte_desc); +} + +static void checkpoint_callback_1(void * extra) { + assert(extra == NULL); + DB* db = NULL; + + DBT change_descriptor; + memset(&change_descriptor, 0, sizeof(change_descriptor)); + change_descriptor.size = sizeof(eight_byte_desc); + change_descriptor.data = &eight_byte_desc; + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_four(db); + IN_TXN_ABORT(env, NULL, txn_change, 0, { + CHK(db->change_descriptor(db, txn_change, &change_descriptor, 0)); + assert_desc_eight(db); + }); + assert_desc_four(db); + CHK(db->close(db,0)); +} + +static void setup (void) { + CHK(system("rm -rf " ENVDIR)); + CHK(toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO)); + CHK(db_env_create(&env, 0)); + db_env_set_checkpoint_callback(checkpoint_callback_1, NULL); + env->set_errfile(env, stderr); + CHK(env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO)); +} + +static void cleanup (void) { + CHK(env->close(env, 0)); +} + +static void run_test(void) { + DB* db = NULL; + + DBT orig_desc; + memset(&orig_desc, 0, sizeof(orig_desc)); + orig_desc.size = sizeof(four_byte_desc); + orig_desc.data = &four_byte_desc; + // verify we can only set a descriptor with version 1 + IN_TXN_COMMIT(env, NULL, txn_create, 0, { + CHK(db_create(&db, env, 0)); + assert(db->descriptor == NULL); + CHK(db->open(db, txn_create, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666)); + CHK(db->change_descriptor(db, txn_create, &orig_desc, 0)); + assert_desc_four(db); + }); + assert_desc_four(db); + CHK(db->close(db,0)); + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_four(db); + CHK(db->close(db,0)); + + CHK(env->txn_checkpoint(env, 0, 0, 0)); + + CHK(db_create(&db, env, 0)); + CHK(db->open(db, NULL, "foo.db", NULL, DB_BTREE, 0, 0666)); + assert_desc_four(db); + CHK(db->close(db,0)); + + db = NULL; +} + +int test_main (int argc, char * const argv[]) { + parse_args(argc, argv); + setup(); + run_test(); + cleanup(); + return 0; +}