Commit 405d6513 authored by Barry Perlman's avatar Barry Perlman Committed by Yoni Fogel

[t:3196] Fix iname generation: only dictionaries created by brtloader

will have _L_ mark, dictionaries created using USE_PUTS (2440 log suppression, a.k.a. put-loader) will 
have _P_ mark, dictionaries created without loader will have no mark.

git-svn-id: file:///svn/toku/tokudb@27298 c7de825b-a66e-492c-adef-691d508d4ae1
parent 64f079d4
...@@ -125,6 +125,13 @@ static void free_loader(DB_LOADER *loader) ...@@ -125,6 +125,13 @@ static void free_loader(DB_LOADER *loader)
static const char *loader_temp_prefix = "tokuld"; // #2536 static const char *loader_temp_prefix = "tokuld"; // #2536
static const char *loader_temp_suffix = "XXXXXX"; static const char *loader_temp_suffix = "XXXXXX";
// loader_flags currently has three possible values:
// 0 use brt loader
// USE_PUTS do not use brt loader, use log suppression mechanism (2440)
// which results in recursive call here via toku_db_pre_acquire_table_lock()
// DB_PRELOCKED_WRITE do not use brt loader, this is the recursive (inner) call via
// toku_db_pre_acquire_table_lock()
int toku_loader_create_loader(DB_ENV *env, int toku_loader_create_loader(DB_ENV *env,
DB_TXN *txn, DB_TXN *txn,
DB_LOADER **blp, DB_LOADER **blp,
...@@ -136,6 +143,7 @@ int toku_loader_create_loader(DB_ENV *env, ...@@ -136,6 +143,7 @@ int toku_loader_create_loader(DB_ENV *env,
uint32_t loader_flags) uint32_t loader_flags)
{ {
int rval; int rval;
BOOL use_brt_loader = (loader_flags == 0);
*blp = NULL; // set later when created *blp = NULL; // set later when created
...@@ -212,7 +220,7 @@ int toku_loader_create_loader(DB_ENV *env, ...@@ -212,7 +220,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 = 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, use_brt_loader);
if ( r!=0 ) { if ( r!=0 ) {
toku_free(new_inames_in_env); toku_free(new_inames_in_env);
toku_free(brts); toku_free(brts);
......
...@@ -4325,10 +4325,11 @@ create_iname_hint(const char *dname, char *hint) { ...@@ -4325,10 +4325,11 @@ create_iname_hint(const char *dname, char *hint) {
} }
// n >= 0 means to include "_L_" with hex value of n in iname // n < 0 means to ignore mark and ignore n
// n >= 0 means to include mark ("_L_" or "_P_") with hex value of n in iname
// (intended for use by loader, which will create many inames using one txnid). // (intended for use by loader, which will create many inames using one txnid).
static char * static char *
create_iname(DB_ENV *env, u_int64_t id, char *hint, int n) { create_iname(DB_ENV *env, u_int64_t id, char *hint, char *mark, int n) {
int bytes; int bytes;
char inamebase[strlen(hint) + char inamebase[strlen(hint) +
8 + // hex file format version 8 + // hex file format version
...@@ -4339,10 +4340,12 @@ create_iname(DB_ENV *env, u_int64_t id, char *hint, int n) { ...@@ -4339,10 +4340,12 @@ create_iname(DB_ENV *env, u_int64_t id, char *hint, int n) {
bytes = snprintf(inamebase, sizeof(inamebase), bytes = snprintf(inamebase, sizeof(inamebase),
"%s_%"PRIx64"_%"PRIx32 ".tokudb", "%s_%"PRIx64"_%"PRIx32 ".tokudb",
hint, id, BRT_LAYOUT_VERSION); hint, id, BRT_LAYOUT_VERSION);
else else {
invariant(strlen(mark) == 1);
bytes = snprintf(inamebase, sizeof(inamebase), bytes = snprintf(inamebase, sizeof(inamebase),
"%s_%"PRIx64"_%"PRIx32"_L_%"PRIx32".tokudb", "%s_%"PRIx64"_%"PRIx32"_%s_%"PRIx32".tokudb",
hint, id, BRT_LAYOUT_VERSION, n); hint, id, BRT_LAYOUT_VERSION, mark, n);
}
assert(bytes>0); assert(bytes>0);
assert(bytes<=(int)sizeof(inamebase)-1); assert(bytes<=(int)sizeof(inamebase)-1);
char *rval; char *rval;
...@@ -4436,7 +4439,7 @@ toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *dbname, DBTYP ...@@ -4436,7 +4439,7 @@ toku_db_open(DB * db, DB_TXN * txn, const char *fname, const char *dbname, DBTYP
id = toku_txn_get_txnid(db_txn_struct_i(child)->tokutxn); id = toku_txn_get_txnid(db_txn_struct_i(child)->tokutxn);
} }
create_iname_hint(dname, hint); create_iname_hint(dname, hint);
iname = create_iname(db->dbenv, id, hint, -1); // allocated memory for iname iname = create_iname(db->dbenv, id, hint, NULL, -1); // allocated memory for iname
toku_fill_dbt(&iname_dbt, iname, strlen(iname) + 1); toku_fill_dbt(&iname_dbt, iname, strlen(iname) + 1);
// //
// DB_YESOVERWRITE for performance only, avoid unnecessary query // DB_YESOVERWRITE for performance only, avoid unnecessary query
...@@ -6073,9 +6076,11 @@ env_get_iname(DB_ENV* env, DBT* dname_dbt, DBT* iname_dbt) { ...@@ -6073,9 +6076,11 @@ env_get_iname(DB_ENV* env, DBT* dname_dbt, DBT* iname_dbt) {
// If the transaction aborts, the old inames will be restored. // If the transaction aborts, the old inames will be restored.
// The new inames are returned to the caller. // The new inames are returned to the caller.
// It is the caller's responsibility to free them. // It is the caller's responsibility to free them.
// If "mark_as_loader" is true, then include a mark in the iname
// to indicate that the file is created by the brt loader.
// Return 0 on success (could fail if write lock not available). // Return 0 on success (could fail if write lock not available).
int int
ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_inames_in_env[N], LSN *load_lsn) { ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_inames_in_env[N], LSN *load_lsn, BOOL mark_as_loader) {
int rval; int rval;
int i; int i;
...@@ -6085,6 +6090,13 @@ ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_iname ...@@ -6085,6 +6090,13 @@ ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_iname
DBT dname_dbt; // holds dname DBT dname_dbt; // holds dname
DBT iname_dbt; // holds new iname DBT iname_dbt; // holds new iname
char * mark;
if (mark_as_loader)
mark = "L";
else
mark = "P";
for (i=0; i<N; i++) { for (i=0; i<N; i++) {
new_inames_in_env[i] = NULL; new_inames_in_env[i] = NULL;
} }
...@@ -6101,7 +6113,7 @@ ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_iname ...@@ -6101,7 +6113,7 @@ ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_iname
// now create new iname // now create new iname
char hint[strlen(dname) + 1]; char hint[strlen(dname) + 1];
create_iname_hint(dname, hint); create_iname_hint(dname, hint);
char * new_iname = create_iname(env, xid, hint, i); // allocates memory for iname_in_env char * new_iname = create_iname(env, xid, hint, mark, i); // allocates memory for iname_in_env
new_inames_in_env[i] = new_iname; new_inames_in_env[i] = new_iname;
toku_fill_dbt(&iname_dbt, new_iname, strlen(new_iname) + 1); // iname_in_env goes in directory toku_fill_dbt(&iname_dbt, new_iname, strlen(new_iname) + 1); // iname_in_env goes in directory
rval = toku_db_put(env->i->directory, child, &dname_dbt, &iname_dbt, DB_YESOVERWRITE); // DB_YESOVERWRITE necessary rval = toku_db_put(env->i->directory, child, &dname_dbt, &iname_dbt, DB_YESOVERWRITE); // DB_YESOVERWRITE necessary
...@@ -6147,9 +6159,9 @@ ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_iname ...@@ -6147,9 +6159,9 @@ ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_iname
} }
int int
locked_ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_inames_in_env[N], LSN *load_lsn) { locked_ydb_load_inames(DB_ENV * env, DB_TXN * txn, int N, DB * dbs[N], char * new_inames_in_env[N], LSN *load_lsn, BOOL mark_as_loader) {
toku_ydb_lock(); toku_ydb_lock();
int r = ydb_load_inames(env, txn, N, dbs, new_inames_in_env, load_lsn); int r = ydb_load_inames(env, txn, N, dbs, new_inames_in_env, load_lsn, mark_as_loader);
toku_ydb_unlock(); toku_ydb_unlock();
return r; return r;
} }
......
...@@ -18,13 +18,16 @@ ...@@ -18,13 +18,16 @@
// If the transaction aborts, the old inames will be restored. // If the transaction aborts, the old inames will be restored.
// The new inames are returned to the caller. // The new inames are returned to the caller.
// It is the caller's responsibility to free them. // It is the caller's responsibility to free them.
// If "mark_as_loader" is true, then include a mark in the iname
// to indicate that the file is created by the brt loader.
// Return 0 on success (could fail if write lock not available). // Return 0 on success (could fail if write lock not available).
int ydb_load_inames(DB_ENV * env, int ydb_load_inames(DB_ENV * env,
DB_TXN * txn, DB_TXN * txn,
int N, int N,
DB * dbs[/*N*/], DB * dbs[/*N*/],
/*out*/ char * new_inames_in_env[N], /*out*/ char * new_inames_in_env[N],
LSN *load_lsn); LSN *load_lsn,
BOOL mark_as_loader);
// Wrapper to ydb_load_inames if you are not holding the ydb lock. // Wrapper to ydb_load_inames if you are not holding the ydb lock.
int locked_ydb_load_inames(DB_ENV * env, int locked_ydb_load_inames(DB_ENV * env,
...@@ -32,7 +35,9 @@ int locked_ydb_load_inames(DB_ENV * env, ...@@ -32,7 +35,9 @@ int locked_ydb_load_inames(DB_ENV * env,
int N, int N,
DB * dbs[/*N*/], DB * dbs[/*N*/],
/*out*/ char * new_inames_in_env[N], /*out*/ char * new_inames_in_env[N],
LSN *load_lsn); LSN *load_lsn,
BOOL mark_as_loader);
#endif #endif
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