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 @@
#ident "Copyright (c) 2010 Tokutek Inc. All rights reserved."
#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 "toku_pthread.h"
#include "toku_atomic.h"
......@@ -31,64 +36,83 @@ char *db_v4_dir_node4k = OLDDATADIR "env_preload.4.1.1.node4k.cleanshutdown";
static void upgrade_test_3(DB **dbs) {
int r;
// open the DBS
{
DBT desc;
dbt_init(&desc, "foo", sizeof("foo"));
char name[MAX_NAME*2];
int idx[MAX_DBS];
for(int i=0;i<NUM_DBS;i++) {
idx[i] = i;
r = db_create(&dbs[i], env, 0); CKERR(r);
r = dbs[i]->set_descriptor(dbs[i], 1, &desc); CKERR(r);
dbs[i]->app_private = &idx[i];
snprintf(name, sizeof(name), "db_%04x", i);
r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
}
}
// insert some rows
printf("ToDo : insert rows\n");
// 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];
for(int i=0;i<NUM_DBS;i++) {
idx[i] = i;
r = db_create(&dbs[i], env, 0); CKERR(r);
r = dbs[i]->set_descriptor(dbs[i], 1, &desc); CKERR(r);
dbs[i]->app_private = &idx[i];
snprintf(name, sizeof(name), "db_%04x", i);
r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
}
}
int r = 0;
char name[MAX_NAME*2];
// truncate, verify, close, open, verify again
DBC *cursor;
DB_TXN * txn;
DBT desc;
int idx[MAX_DBS];
dbt_init(&desc, "foo", sizeof("foo"));
for(int i=0;i<NUM_DBS;i++) {
idx[i] = i;
r = db_create(&dbs[i], env, 0); CKERR(r);
r = dbs[i]->set_descriptor(dbs[i], 1, &desc); CKERR(r);
dbs[i]->app_private = &idx[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 = 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);
CKERR(r);
assert(rowcount == 0);
r = txn->commit(txn, 0);
CKERR(r);
r = dbs[i]->close(dbs[i], 0); assert(r == 0);
r = db_create(&dbs[i], env, 0); assert(r == 0);
snprintf(name, sizeof(name), "db_%04x", i);
r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
// open new txn and walk the tree again - expect 0 rows
r = env->txn_begin(env, NULL, &txn, DB_SERIALIZABLE);
CKERR(r);
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++;
}
r = cursor->c_close(cursor); assert(r == 0);
assert(rowcount == 0);
// read and verify all rows
{
if ( verbose ) {printf("checking");fflush(stdout);}
check_results(env, dbs, NUM_DBS, NUM_ROWS);
if ( verbose) {printf("\ndone\n");fflush(stdout);}
}
// close
{
for(int i=0;i<NUM_DBS;i++) {
dbs[i]->close(dbs[i], 0); CKERR(r);
dbs[i] = NULL;
}
r = txn->commit(txn, 0);
CKERR(r);
r = dbs[i]->close(dbs[i], 0);
CKERR(r);
dbs[i] = NULL;
}
}
static void setup(void) {
int r;
int len = 256;
......@@ -118,11 +142,10 @@ static void setup(void) {
assert(r<len);
r = system(syscmd);
CKERR(r);
generate_permute_tables();
}
static void run_test(void)
static void run_test(int checkpoint_period)
{
int r;
......@@ -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;
r = env->open(env, env_dir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
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);
assert(dbs != NULL);
......@@ -153,18 +176,15 @@ static void run_test(void)
// ------------ infrastructure ----------
static void do_args(int argc, char * const argv[]);
int test_main(int argc, char * const *argv) {
do_args(argc, argv);
littlenode = 0;
setup();
run_test();
if (SRC_VERSION == 4) {
if (verbose)
printf("Now repeat test with small nodes and small cache.\n");
littlenode = 1; // 4k nodes, small cache
setup();
run_test();
}
setup();
run_test(1);
return 0;
}
......@@ -182,7 +202,7 @@ static void do_args(int argc, char * const argv[]) {
} else if (strcmp(argv[0], "-h")==0) {
resultcode=0;
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);
} else if (strcmp(argv[0], "-d")==0) {
argc--; argv++;
......@@ -192,11 +212,6 @@ static void do_args(int argc, char * const argv[]) {
resultcode=1;
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) {
argc--; argv++;
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