Commit 78e2151d authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

closes[t:2588] fix the loader create close test

git-svn-id: file:///svn/toku/tokudb@20298 c7de825b-a66e-492c-adef-691d508d4ae1
parent 938a3d92
......@@ -2205,25 +2205,29 @@ static int toku_brt_loader_close_internal (BRTLOADER bl)
{
BL_TRACE(blt_do_put);
int result = 0;
int remaining_progress = PROGRESS_MAX;
for (int i=0; i<bl->N; i++) {
char * fname_in_cwd = toku_cachetable_get_fname_in_cwd(bl->cachetable, bl->new_fnames_in_env[i]);
// Take the unallocated progress and divide it among the unfinished jobs.
// This calculation allocates all of the PROGRESS_MAX bits of progress to some job.
int allocate_here = remaining_progress/(bl->N - i);
remaining_progress -= allocate_here;
//printf("%s:%d do_i(%d)\n", __FILE__, __LINE__, i);
BL_TRACE(blt_close);
result = loader_do_i(bl, i, bl->dbs[i], bl->bt_compare_funs[i], bl->descriptors[i], fname_in_cwd,
allocate_here
);
toku_free(fname_in_cwd);
if (result!=0) goto error;
toku_free((void*)bl->new_fnames_in_env[i]);
bl->new_fnames_in_env[i] = NULL;
invariant(0<=bl->progress && bl->progress <= PROGRESS_MAX);
result = update_progress(0, bl, "did index");
if (result) goto error;
if (bl->N == 0)
result = update_progress(PROGRESS_MAX, bl, "done");
else {
int remaining_progress = PROGRESS_MAX;
for (int i=0; i<bl->N; i++) {
char * fname_in_cwd = toku_cachetable_get_fname_in_cwd(bl->cachetable, bl->new_fnames_in_env[i]);
// Take the unallocated progress and divide it among the unfinished jobs.
// This calculation allocates all of the PROGRESS_MAX bits of progress to some job.
int allocate_here = remaining_progress/(bl->N - i);
remaining_progress -= allocate_here;
//printf("%s:%d do_i(%d)\n", __FILE__, __LINE__, i);
BL_TRACE(blt_close);
result = loader_do_i(bl, i, bl->dbs[i], bl->bt_compare_funs[i], bl->descriptors[i], fname_in_cwd,
allocate_here
);
toku_free(fname_in_cwd);
if (result!=0) goto error;
toku_free((void*)bl->new_fnames_in_env[i]);
bl->new_fnames_in_env[i] = NULL;
invariant(0<=bl->progress && bl->progress <= PROGRESS_MAX);
result = update_progress(0, bl, "did index");
if (result) goto error;
}
}
invariant(bl->file_infos.n_files_open == 0);
invariant(bl->file_infos.n_files_extant == 0);
......
......@@ -14,7 +14,7 @@ static int put_multiple_generate(DB *UU(dest_db), DB *UU(src_db), DBT *UU(dest_k
return ENOMEM;
}
static void loader_open_abort(void) {
static void loader_open_abort(int ndb) {
int r;
r = system("rm -rf " ENVDIR); CKERR(r);
......@@ -28,16 +28,32 @@ static void loader_open_abort(void) {
r = env->open(env, ENVDIR, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
env->set_errfile(env, stderr);
DB *dbs[ndb];
uint32_t db_flags[ndb];
uint32_t dbt_flags[ndb];
for (int i = 0; i < ndb; i++) {
db_flags[i] = DB_NOOVERWRITE;
dbt_flags[i] = 0;
r = db_create(&dbs[i], env, 0); CKERR(r);
char name[32];
sprintf(name, "db%d", i);
r = dbs[i]->open(dbs[i], NULL, name, NULL, DB_BTREE, DB_CREATE, 0666); CKERR(r);
}
DB_TXN *txn;
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
DB_LOADER *loader;
r = env->create_loader(env, txn, &loader, NULL, 0, NULL, NULL, NULL, loader_flags); CKERR(r);
r = env->create_loader(env, txn, &loader, dbs[0], ndb, dbs, db_flags, dbt_flags, loader_flags); CKERR(r);
r = loader->close(loader); CKERR(r);
r = txn->commit(txn, 0); CKERR(r);
for (int i = 0; i < ndb; i++) {
r = dbs[i]->close(dbs[i], 0); CKERR(r);
}
r = env->close(env, 0); CKERR(r);
}
......@@ -49,7 +65,7 @@ static void do_args(int argc, char * const argv[]) {
if (strcmp(argv[0], "-h")==0) {
resultcode=0;
do_usage:
fprintf(stderr, "Usage: -h -c -d <num_dbs> -r <num_rows>\n%s\n", cmd);
fprintf(stderr, "Usage: %s -h -v -q -p\n", cmd);
exit(resultcode);
} else if (strcmp(argv[0], "-v")==0) {
verbose++;
......@@ -70,6 +86,8 @@ static void do_args(int argc, char * const argv[]) {
int test_main(int argc, char * const *argv) {
do_args(argc, argv);
loader_open_abort();
loader_open_abort(0);
loader_open_abort(1);
loader_open_abort(2);
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