Commit 939721e7 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:4928], some simplification to toku_db_construct_autotxn

git-svn-id: file:///svn/toku/tokudb@43890 c7de825b-a66e-492c-adef-691d508d4ae1
parent 2dc2fee1
...@@ -649,20 +649,20 @@ int ...@@ -649,20 +649,20 @@ int
autotxn_db_get(DB* db, DB_TXN* txn, DBT* key, DBT* data, u_int32_t flags) { autotxn_db_get(DB* db, DB_TXN* txn, DBT* key, DBT* data, u_int32_t flags) {
BOOL changed; int r; BOOL changed; int r;
// ydb lock is NOT held here // ydb lock is NOT held here
r = toku_db_construct_autotxn(db, &txn, &changed, FALSE, FALSE); r = toku_db_construct_autotxn(db, &txn, &changed, FALSE);
if (r!=0) return r; if (r!=0) return r;
r = toku_db_get(db, txn, key, data, flags); r = toku_db_get(db, txn, key, data, flags);
return toku_db_destruct_autotxn(txn, r, changed, FALSE); return toku_db_destruct_autotxn(txn, r, changed);
} }
static inline int static inline int
autotxn_db_getf_set (DB *db, DB_TXN *txn, u_int32_t flags, DBT *key, YDB_CALLBACK_FUNCTION f, void *extra) { autotxn_db_getf_set (DB *db, DB_TXN *txn, u_int32_t flags, DBT *key, YDB_CALLBACK_FUNCTION f, void *extra) {
BOOL changed; int r; BOOL changed; int r;
// ydb lock is NOT held here // ydb lock is NOT held here
r = toku_db_construct_autotxn(db, &txn, &changed, FALSE, FALSE); r = toku_db_construct_autotxn(db, &txn, &changed, FALSE);
if (r!=0) return r; if (r!=0) return r;
r = db_getf_set(db, txn, flags, key, f, extra); r = db_getf_set(db, txn, flags, key, f, extra);
return toku_db_destruct_autotxn(txn, r, changed, FALSE); return toku_db_destruct_autotxn(txn, r, changed);
} }
static int static int
......
...@@ -51,7 +51,7 @@ int autotxn_db_get(DB* db, DB_TXN* txn, DBT* key, DBT* data, u_int32_t flags); ...@@ -51,7 +51,7 @@ int autotxn_db_get(DB* db, DB_TXN* txn, DBT* key, DBT* data, u_int32_t flags);
//TODO: Nowait only conditionally? //TODO: Nowait only conditionally?
//TODO: NOSYNC change to SYNC if DB_ENV has something in set_flags //TODO: NOSYNC change to SYNC if DB_ENV has something in set_flags
static inline int static inline int
toku_db_construct_autotxn(DB* db, DB_TXN **txn, BOOL* changed, BOOL force_auto_commit, BOOL holds_ydb_lock) { toku_db_construct_autotxn(DB* db, DB_TXN **txn, BOOL* changed, BOOL force_auto_commit) {
assert(db && txn && changed); assert(db && txn && changed);
DB_ENV* env = db->dbenv; DB_ENV* env = db->dbenv;
if (*txn || !(env->i->open_flags & DB_INIT_TXN)) { if (*txn || !(env->i->open_flags & DB_INIT_TXN)) {
...@@ -60,23 +60,23 @@ toku_db_construct_autotxn(DB* db, DB_TXN **txn, BOOL* changed, BOOL force_auto_c ...@@ -60,23 +60,23 @@ toku_db_construct_autotxn(DB* db, DB_TXN **txn, BOOL* changed, BOOL force_auto_c
} }
BOOL nosync = (BOOL)(!force_auto_commit && !(env->i->open_flags & DB_AUTO_COMMIT)); BOOL nosync = (BOOL)(!force_auto_commit && !(env->i->open_flags & DB_AUTO_COMMIT));
u_int32_t txn_flags = DB_TXN_NOWAIT | (nosync ? DB_TXN_NOSYNC : 0); u_int32_t txn_flags = DB_TXN_NOWAIT | (nosync ? DB_TXN_NOSYNC : 0);
int r = toku_txn_begin(env, NULL, txn, txn_flags, 1, holds_ydb_lock); int r = toku_txn_begin(env, NULL, txn, txn_flags, 1, FALSE);
if (r!=0) return r; if (r!=0) return r;
*changed = TRUE; *changed = TRUE;
return 0; return 0;
} }
static inline int static inline int
toku_db_destruct_autotxn(DB_TXN *txn, int r, BOOL changed, BOOL holds_ydb_lock) { toku_db_destruct_autotxn(DB_TXN *txn, int r, BOOL changed) {
if (!changed) return r; if (!changed) return r;
if (!holds_ydb_lock) toku_ydb_lock(); toku_ydb_lock();
if (r==0) { if (r==0) {
r = toku_txn_commit(txn, 0, NULL, NULL, false); r = toku_txn_commit(txn, 0, NULL, NULL, false);
} }
else { else {
toku_txn_abort(txn, NULL, NULL, false); toku_txn_abort(txn, NULL, NULL, false);
} }
if (!holds_ydb_lock) toku_ydb_unlock(); toku_ydb_unlock();
return r; return r;
} }
......
...@@ -764,10 +764,10 @@ env_update_multiple(DB_ENV *env, DB *src_db, DB_TXN *txn, ...@@ -764,10 +764,10 @@ env_update_multiple(DB_ENV *env, DB *src_db, DB_TXN *txn,
int int
autotxn_db_del(DB* db, DB_TXN* txn, DBT* key, u_int32_t flags) { autotxn_db_del(DB* db, DB_TXN* txn, DBT* key, u_int32_t flags) {
BOOL changed; int r; BOOL changed; int r;
r = toku_db_construct_autotxn(db, &txn, &changed, FALSE, FALSE); r = toku_db_construct_autotxn(db, &txn, &changed, FALSE);
if (r!=0) return r; if (r!=0) return r;
r = toku_db_del(db, txn, key, flags, FALSE); r = toku_db_del(db, txn, key, flags, FALSE);
return toku_db_destruct_autotxn(txn, r, changed, FALSE); return toku_db_destruct_autotxn(txn, r, changed);
} }
int int
...@@ -776,12 +776,12 @@ autotxn_db_put(DB* db, DB_TXN* txn, DBT* key, DBT* data, u_int32_t flags) { ...@@ -776,12 +776,12 @@ autotxn_db_put(DB* db, DB_TXN* txn, DBT* key, DBT* data, u_int32_t flags) {
BOOL changed; int r; BOOL changed; int r;
r = env_check_avail_fs_space(db->dbenv); r = env_check_avail_fs_space(db->dbenv);
if (r != 0) { goto cleanup; } if (r != 0) { goto cleanup; }
r = toku_db_construct_autotxn(db, &txn, &changed, FALSE, FALSE); r = toku_db_construct_autotxn(db, &txn, &changed, FALSE);
if (r!=0) { if (r!=0) {
goto cleanup; goto cleanup;
} }
r = toku_db_put(db, txn, key, data, flags, FALSE); r = toku_db_put(db, txn, key, data, flags, FALSE);
r = toku_db_destruct_autotxn(txn, r, changed, FALSE); r = toku_db_destruct_autotxn(txn, r, changed);
cleanup: cleanup:
return r; return r;
} }
...@@ -794,10 +794,10 @@ autotxn_db_update(DB *db, DB_TXN *txn, ...@@ -794,10 +794,10 @@ autotxn_db_update(DB *db, DB_TXN *txn,
BOOL changed; int r; BOOL changed; int r;
r = env_check_avail_fs_space(db->dbenv); r = env_check_avail_fs_space(db->dbenv);
if (r != 0) { goto cleanup; } if (r != 0) { goto cleanup; }
r = toku_db_construct_autotxn(db, &txn, &changed, FALSE, FALSE); r = toku_db_construct_autotxn(db, &txn, &changed, FALSE);
if (r != 0) { return r; } if (r != 0) { return r; }
r = toku_db_update(db, txn, key, update_function_extra, flags); r = toku_db_update(db, txn, key, update_function_extra, flags);
r = toku_db_destruct_autotxn(txn, r, changed, FALSE); r = toku_db_destruct_autotxn(txn, r, changed);
cleanup: cleanup:
return r; return r;
} }
...@@ -809,10 +809,10 @@ autotxn_db_update_broadcast(DB *db, DB_TXN *txn, ...@@ -809,10 +809,10 @@ autotxn_db_update_broadcast(DB *db, DB_TXN *txn,
BOOL changed; int r; BOOL changed; int r;
r = env_check_avail_fs_space(db->dbenv); r = env_check_avail_fs_space(db->dbenv);
if (r != 0) { goto cleanup; } if (r != 0) { goto cleanup; }
r = toku_db_construct_autotxn(db, &txn, &changed, FALSE, FALSE); r = toku_db_construct_autotxn(db, &txn, &changed, FALSE);
if (r != 0) { return r; } if (r != 0) { return r; }
r = toku_db_update_broadcast(db, txn, update_function_extra, flags); r = toku_db_update_broadcast(db, txn, update_function_extra, flags);
r = toku_db_destruct_autotxn(txn, r, changed, FALSE); r = toku_db_destruct_autotxn(txn, r, changed);
cleanup: cleanup:
return r; return r;
} }
......
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