Commit 85840905 authored by Barry Perlman's avatar Barry Perlman Committed by Yoni Fogel

[t:2892] Replace redundant test with new test that truncates upgraded dictionaries.

git-svn-id: file:///svn/toku/tokudb@26072 c7de825b-a66e-492c-adef-691d508d4ae1
parent d7056f57
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
#ident "Copyright (c) 2010 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2010 Tokutek Inc. All rights reserved."
#ident "$Id$" #ident "$Id$"
// Purpose of this test is to verify that dictionaries created with 4.1.1
// can be properly truncated with TokuDB version 5.x or later.
#include "test.h" #include "test.h"
#include "toku_pthread.h" #include "toku_pthread.h"
#include "toku_atomic.h" #include "toku_atomic.h"
...@@ -31,14 +36,17 @@ char *db_v4_dir_node4k = OLDDATADIR "env_preload.4.1.1.node4k.cleanshutdown"; ...@@ -31,14 +36,17 @@ char *db_v4_dir_node4k = OLDDATADIR "env_preload.4.1.1.node4k.cleanshutdown";
static void upgrade_test_3(DB **dbs) { static void upgrade_test_3(DB **dbs) {
int r; int r = 0;
// open the DBS
{
DBT desc;
dbt_init(&desc, "foo", sizeof("foo"));
char name[MAX_NAME*2]; char name[MAX_NAME*2];
// truncate, verify, close, open, verify again
DBC *cursor;
DB_TXN * txn;
DBT desc;
int idx[MAX_DBS]; int idx[MAX_DBS];
dbt_init(&desc, "foo", sizeof("foo"));
for(int i=0;i<NUM_DBS;i++) { for(int i=0;i<NUM_DBS;i++) {
idx[i] = i; idx[i] = i;
r = db_create(&dbs[i], env, 0); CKERR(r); r = db_create(&dbs[i], env, 0); CKERR(r);
...@@ -46,49 +54,65 @@ static void upgrade_test_3(DB **dbs) { ...@@ -46,49 +54,65 @@ static void upgrade_test_3(DB **dbs) {
dbs[i]->app_private = &idx[i]; dbs[i]->app_private = &idx[i];
snprintf(name, sizeof(name), "db_%04x", i); snprintf(name, sizeof(name), "db_%04x", i);
r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r); r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
r = env->txn_begin(env, NULL, &txn, DB_SERIALIZABLE);
CKERR(r);
// truncate the tree
u_int32_t row_count = 0;
r = dbs[i]->truncate(dbs[i], 0, &row_count, 0); assert(r == 0);
// walk the tree - expect 0 rows
int rowcount = 0;
r = dbs[i]->cursor(dbs[i], txn, &cursor, 0);
CKERR(r);
while (1) {
DBT key, val;
r = cursor->c_get(cursor, dbt_init(&key, 0, 0), dbt_init(&val, 0, 0), DB_NEXT);
if (r == DB_NOTFOUND) break;
rowcount++;
} }
} r = cursor->c_close(cursor);
// insert some rows CKERR(r);
printf("ToDo : insert rows\n"); assert(rowcount == 0);
// close
{
for(int i=0;i<NUM_DBS;i++) {
dbs[i]->close(dbs[i], 0); CKERR(r);
dbs[i] = NULL;
}
}
// open
{
DBT desc;
dbt_init(&desc, "foo", sizeof("foo"));
char name[MAX_NAME*2];
int idx[MAX_DBS]; r = txn->commit(txn, 0);
for(int i=0;i<NUM_DBS;i++) { CKERR(r);
idx[i] = i;
r = db_create(&dbs[i], env, 0); CKERR(r); r = dbs[i]->close(dbs[i], 0); assert(r == 0);
r = dbs[i]->set_descriptor(dbs[i], 1, &desc); CKERR(r);
dbs[i]->app_private = &idx[i]; r = db_create(&dbs[i], env, 0); assert(r == 0);
snprintf(name, sizeof(name), "db_%04x", i); snprintf(name, sizeof(name), "db_%04x", i);
r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r); r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
}
}
// read and verify all rows // open new txn and walk the tree again - expect 0 rows
{
if ( verbose ) {printf("checking");fflush(stdout);} r = env->txn_begin(env, NULL, &txn, DB_SERIALIZABLE);
check_results(env, dbs, NUM_DBS, NUM_ROWS); CKERR(r);
if ( verbose) {printf("\ndone\n");fflush(stdout);}
rowcount = 0;
r = dbs[i]->cursor(dbs[i], txn, &cursor, 0); assert(r == 0);
while (1) {
DBT key, val;
r = cursor->c_get(cursor, dbt_init(&key, 0, 0), dbt_init(&val, 0, 0), DB_NEXT);
if (r == DB_NOTFOUND) break;
rowcount++;
} }
// close r = cursor->c_close(cursor); assert(r == 0);
{ assert(rowcount == 0);
for(int i=0;i<NUM_DBS;i++) {
dbs[i]->close(dbs[i], 0); CKERR(r); r = txn->commit(txn, 0);
CKERR(r);
r = dbs[i]->close(dbs[i], 0);
CKERR(r);
dbs[i] = NULL; dbs[i] = NULL;
} }
}
} }
static void setup(void) { static void setup(void) {
int r; int r;
int len = 256; int len = 256;
...@@ -118,11 +142,10 @@ static void setup(void) { ...@@ -118,11 +142,10 @@ static void setup(void) {
assert(r<len); assert(r<len);
r = system(syscmd); r = system(syscmd);
CKERR(r); CKERR(r);
generate_permute_tables();
} }
static void run_test(void) static void run_test(int checkpoint_period)
{ {
int r; int r;
...@@ -134,7 +157,7 @@ static void run_test(void) ...@@ -134,7 +157,7 @@ static void run_test(void)
int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE; int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE;
r = env->open(env, env_dir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r); r = env->open(env, env_dir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
env->set_errfile(env, stderr); env->set_errfile(env, stderr);
r = env->checkpointing_set_period(env, 60); CKERR(r); r = env->checkpointing_set_period(env, checkpoint_period); CKERR(r);
DB **dbs = (DB**)toku_malloc(sizeof(DB*) * NUM_DBS); DB **dbs = (DB**)toku_malloc(sizeof(DB*) * NUM_DBS);
assert(dbs != NULL); assert(dbs != NULL);
...@@ -153,18 +176,15 @@ static void run_test(void) ...@@ -153,18 +176,15 @@ static void run_test(void)
// ------------ infrastructure ---------- // ------------ infrastructure ----------
static void do_args(int argc, char * const argv[]); static void do_args(int argc, char * const argv[]);
int test_main(int argc, char * const *argv) { int test_main(int argc, char * const *argv) {
do_args(argc, argv); do_args(argc, argv);
littlenode = 0;
setup();
run_test();
if (SRC_VERSION == 4) { if (SRC_VERSION == 4) {
if (verbose)
printf("Now repeat test with small nodes and small cache.\n");
littlenode = 1; // 4k nodes, small cache littlenode = 1; // 4k nodes, small cache
setup();
run_test();
} }
setup();
run_test(1);
return 0; return 0;
} }
...@@ -182,7 +202,7 @@ static void do_args(int argc, char * const argv[]) { ...@@ -182,7 +202,7 @@ static void do_args(int argc, char * const argv[]) {
} else if (strcmp(argv[0], "-h")==0) { } else if (strcmp(argv[0], "-h")==0) {
resultcode=0; resultcode=0;
do_usage: do_usage:
fprintf(stderr, "Usage: -h -c -d <num_dbs> -r <num_rows> %s\n", cmd); fprintf(stderr, "Usage: -h -d <num_dbs> -V <version> %s\n", cmd);
exit(resultcode); exit(resultcode);
} else if (strcmp(argv[0], "-d")==0) { } else if (strcmp(argv[0], "-d")==0) {
argc--; argv++; argc--; argv++;
...@@ -192,11 +212,6 @@ static void do_args(int argc, char * const argv[]) { ...@@ -192,11 +212,6 @@ static void do_args(int argc, char * const argv[]) {
resultcode=1; resultcode=1;
goto do_usage; goto do_usage;
} }
} else if (strcmp(argv[0], "-r")==0) {
argc--; argv++;
NUM_ROWS = atoi(argv[0]);
} else if (strcmp(argv[0], "-c")==0) {
CHECK_RESULTS = 1;
} else if (strcmp(argv[0], "-V")==0) { } else if (strcmp(argv[0], "-V")==0) {
argc--; argv++; argc--; argv++;
SRC_VERSION = atoi(argv[0]); SRC_VERSION = atoi(argv[0]);
......
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