From 0f89d506f88e8865f595b5ad0b0115a2190f67a2 Mon Sep 17 00:00:00 2001 From: Zardosht Kasheff Date: Wed, 17 Apr 2013 00:00:10 -0400 Subject: [PATCH] [t:4498], initialize a txn's lth on demand, in toku_txn_add_lt and not in the begin of a txn git-svn-id: file:///svn/toku/tokudb@39758 c7de825b-a66e-492c-adef-691d508d4ae1 --- src/ydb-internal.h | 2 +- src/ydb.c | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/ydb-internal.h b/src/ydb-internal.h index 3fe32b46381..ed4f05114cd 100644 --- a/src/ydb-internal.h +++ b/src/ydb-internal.h @@ -209,7 +209,7 @@ typedef enum __toku_isolation_level { struct __toku_db_txn_internal { //TXNID txnid64; /* A sixty-four bit txn id. */ struct tokutxn *tokutxn; - struct __toku_lth *lth; //Hash table holding list of dictionaries this txn has touched + struct __toku_lth *lth; //Hash table holding list of dictionaries this txn has touched, only initialized if txn touches a dictionary u_int32_t flags; TOKU_ISOLATION iso; DB_TXN *child; diff --git a/src/ydb.c b/src/ydb.c index 5b033c6ce91..709e8046a72 100644 --- a/src/ydb.c +++ b/src/ydb.c @@ -2939,17 +2939,12 @@ toku_txn_begin(DB_ENV *env, DB_TXN * stxn, DB_TXN ** txn, u_int32_t flags, int i db_txn_struct_i(result)->iso = child_isolation; toku_list_init(&db_txn_struct_i(result)->dbs_that_must_close_before_abort); - int r; - if (env->i->open_flags & DB_INIT_LOCK && !stxn) { - r = toku_lth_create(&db_txn_struct_i(result)->lth); - if (r!=0) { -#if !TOKUDB_NATIVE_H - toku_free(db_txn_struct_i(result)); -#endif - toku_free(result); - return r; - } - } + // we used to initialize the transaction's lth here. + // Now we initialize the lth only if the transaction needs the lth, + // in toku_txn_add_lt. If this transaction never does anything + // that requires using a lock tree, then the lth is never + // created. + int r = 0; //r = toku_logger_txn_begin(stxn ? db_txn_struct_i(stxn)->tokutxn : 0, &db_txn_struct_i(result)->tokutxn, env->i->logger); TXN_SNAPSHOT_TYPE snapshot_type; @@ -4536,7 +4531,13 @@ toku_txn_add_lt(DB_TXN* txn, toku_lock_tree* lt) { int r = ENOSYS; assert(txn && lt); toku_lth* lth = db_txn_struct_i(txn)->lth; - assert(lth); + // we used to initialize the transaction's lth during begin. + // Now we initialize the lth only if the transaction needs the lth, here + if (!lth) { + r = toku_lth_create(&db_txn_struct_i(txn)->lth); + assert_zero(r); + lth = db_txn_struct_i(txn)->lth; + } toku_lock_tree* find = toku_lth_find(lth, lt); if (find) {