Commit 9b1ff91d authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

[t:4573] Merge test for 4573 onto main. Refs #4573.

git-svn-id: file:///svn/toku/tokudb@40334 c7de825b-a66e-492c-adef-691d508d4ae1
parent f01fbd0f
......@@ -713,7 +713,7 @@ test_update_stress.tdbrun: VGRIND=
stress-test.tdbrun: VGRIND=
stress-test.bdbrun: VGRIND=
hot-optimize-table-tests.tdbrun: VGRIND=
test4573-logtrim.tdbrun: VGRIND=
libs:
cd ..;$(MAKE)
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#include "test.h"
#include <sys/wait.h>
const int envflags = DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE|DB_RECOVER;
const int my_lg_max = IS_TDB ? 100 : (4096*2);
int test_main (int UU(argc), char UU(*const argv[])) {
int r;
pid_t pid;
r = system("rm -rf " ENVDIR); CKERR(r);
r = toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
const int N = 5;
if (0==(pid=fork())) {
DB_ENV *env;
r = db_env_create(&env, 0); CKERR(r);
r = env->set_lg_max(env, my_lg_max); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
DB *db;
r = db_create(&db, env, 0); CKERR(r);
r = db->open(db, txn, "test.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
for (int i=0; i<N; i++) {
DBT k,v;
r = db->put(db, txn, dbt_init(&k, &i, sizeof(i)), dbt_init(&v, &i, sizeof(i)), 0); CKERR(r);
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
}
r = txn->commit(txn, 0); CKERR(r);
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
for (int i=0; i<N; i+=2) {
DBT k;
r = db->del(db, txn, dbt_init(&k, &i, sizeof(i)), 0); CKERR(r);
r = env->txn_checkpoint(env, 0, 0, 0); CKERR(r);
}
r = txn->commit(txn, 0); CKERR(r);
exit(0);
}
{
int status;
pid_t pid2 = wait(&status);
assert(pid2==pid);
assert(WIFEXITED(status) && WEXITSTATUS(status)==0);
}
// Now run recovery to see what happens.
DB_ENV *env;
r = db_env_create(&env, 0); CKERR(r);
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
DB *db;
r = db_create(&db, env, 0); CKERR(r);
r = db->open(db, txn, "test.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
for (int i=0; i<N; i++) {
DBT k;
DBT v = {.size=0};
r = db->get(db, txn, dbt_init(&k, &i, sizeof(i)), &v, 0);
if (i%2==1) {
assert(r==0);
//printf("Got %d\n", *(int*)v.data);
} else {
assert(r==DB_NOTFOUND);
}
}
r = txn->commit(txn, 0); CKERR(r);
r = db->close(db, 0); CKERR(r);
r = env->close(env, 0); CKERR(r);
//r = system("rm -rf " ENVDIR); CKERR(r);
return 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