Commit e3219f5a authored by Dave Wells's avatar Dave Wells Committed by Yoni Fogel

changes recommended during code review of loader.c

git-svn-id: file:///svn/toku/tokudb@25876 c7de825b-a66e-492c-adef-691d508d4ae1
parent d444012c
...@@ -174,10 +174,8 @@ int toku_loader_create_loader(DB_ENV *env, ...@@ -174,10 +174,8 @@ int toku_loader_create_loader(DB_ENV *env,
// lock tables and check empty // lock tables and check empty
for(int i=0;i<N;i++) { for(int i=0;i<N;i++) {
if (!(loader_flags&DB_PRELOCKED_WRITE)) { if (!(loader_flags&DB_PRELOCKED_WRITE)) {
toku_ydb_lock(); //Must hold ydb lock for acquiring locks
BOOL using_puts = (loader->i->loader_flags & LOADER_USE_PUTS) != 0; BOOL using_puts = (loader->i->loader_flags & LOADER_USE_PUTS) != 0;
r = toku_db_pre_acquire_table_lock(dbs[i], txn, !using_puts); r = toku_db_pre_acquire_table_lock(dbs[i], txn, !using_puts);
toku_ydb_unlock();
if (r!=0) break; if (r!=0) break;
} }
r = !toku_brt_is_empty_fast(dbs[i]->i->brt); r = !toku_brt_is_empty_fast(dbs[i]->i->brt);
...@@ -214,7 +212,7 @@ int toku_loader_create_loader(DB_ENV *env, ...@@ -214,7 +212,7 @@ int toku_loader_create_loader(DB_ENV *env,
loader->i->ekeys = NULL; loader->i->ekeys = NULL;
loader->i->evals = NULL; loader->i->evals = NULL;
LSN load_lsn; LSN load_lsn;
r = locked_ydb_load_inames (env, txn, N, dbs, new_inames_in_env, &load_lsn); r = ydb_load_inames(env, txn, N, dbs, new_inames_in_env, &load_lsn);
if ( r!=0 ) { if ( r!=0 ) {
toku_free(new_inames_in_env); toku_free(new_inames_in_env);
toku_free(brts); toku_free(brts);
...@@ -307,6 +305,9 @@ int toku_loader_put(DB_LOADER *loader, DBT *key, DBT *val) ...@@ -307,6 +305,9 @@ int toku_loader_put(DB_LOADER *loader, DBT *key, DBT *val)
loader->i->db_flags); // flags_array loader->i->db_flags); // flags_array
} }
else { else {
// calling toku_brt_loader_put without a lock assumes that the
// handlerton is guaranteeing single access to the loader
// future multi-threaded solutions may need to protect this call
r = toku_brt_loader_put(loader->i->brt_loader, key, val); r = toku_brt_loader_put(loader->i->brt_loader, key, val);
} }
if ( r != 0 ) { if ( r != 0 ) {
...@@ -364,7 +365,9 @@ int toku_loader_close(DB_LOADER *loader) ...@@ -364,7 +365,9 @@ int toku_loader_close(DB_LOADER *loader)
} }
} }
} }
toku_ydb_lock();
free_loader(loader); free_loader(loader);
toku_ydb_unlock();
if (r==0) if (r==0)
(void) toku_sync_fetch_and_increment_uint64(&status.close); (void) toku_sync_fetch_and_increment_uint64(&status.close);
else else
...@@ -386,7 +389,9 @@ int toku_loader_abort(DB_LOADER *loader) ...@@ -386,7 +389,9 @@ int toku_loader_abort(DB_LOADER *loader)
if ( !(loader->i->loader_flags & LOADER_USE_PUTS) ) { if ( !(loader->i->loader_flags & LOADER_USE_PUTS) ) {
r = toku_brt_loader_abort(loader->i->brt_loader, TRUE); r = toku_brt_loader_abort(loader->i->brt_loader, TRUE);
} }
toku_ydb_lock();
free_loader(loader); free_loader(loader);
toku_ydb_unlock();
return r; return r;
} }
......
...@@ -1498,6 +1498,23 @@ locked_env_create_indexer(DB_ENV *env, ...@@ -1498,6 +1498,23 @@ locked_env_create_indexer(DB_ENV *env,
return r; return r;
} }
static int
locked_env_create_loader(DB_ENV *env,
DB_TXN *txn,
DB_LOADER **blp,
DB *src_db,
int N,
DB *dbs[],
uint32_t db_flags[N],
uint32_t dbt_flags[N],
uint32_t loader_flags) {
toku_ydb_lock();
int r = toku_loader_create_loader(env, txn, blp, src_db, N, dbs, db_flags, dbt_flags, loader_flags);
toku_ydb_unlock();
return r;
}
static int static int
env_checkpointing_get_period(DB_ENV * env, u_int32_t *seconds) { env_checkpointing_get_period(DB_ENV * env, u_int32_t *seconds) {
...@@ -2155,8 +2172,7 @@ toku_env_create(DB_ENV ** envp, u_int32_t flags) { ...@@ -2155,8 +2172,7 @@ toku_env_create(DB_ENV ** envp, u_int32_t flags) {
result->txn_begin = locked_txn_begin; result->txn_begin = locked_txn_begin;
SENV(set_redzone); SENV(set_redzone);
SENV(create_indexer); SENV(create_indexer);
// note : create_loader should use SENV SENV(create_loader);
result->create_loader = toku_loader_create_loader;
#undef SENV #undef SENV
MALLOC(result->i); MALLOC(result->i);
......
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