mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 06:44:16 +01:00
[t:4928], some simplification to toku_db_construct_autotxn
git-svn-id: file:///svn/toku/tokudb@43890 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
2dc2fee190
commit
939721e749
3 changed files with 17 additions and 17 deletions
|
@ -649,20 +649,20 @@ int
|
|||
autotxn_db_get(DB* db, DB_TXN* txn, DBT* key, DBT* data, u_int32_t flags) {
|
||||
BOOL changed; int r;
|
||||
// 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;
|
||||
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
|
||||
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;
|
||||
// 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;
|
||||
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
|
||||
|
|
10
src/ydb_db.h
10
src/ydb_db.h
|
@ -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: NOSYNC change to SYNC if DB_ENV has something in set_flags
|
||||
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);
|
||||
DB_ENV* env = db->dbenv;
|
||||
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
|
|||
}
|
||||
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);
|
||||
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;
|
||||
*changed = TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 (!holds_ydb_lock) toku_ydb_lock();
|
||||
toku_ydb_lock();
|
||||
if (r==0) {
|
||||
r = toku_txn_commit(txn, 0, NULL, NULL, false);
|
||||
}
|
||||
else {
|
||||
toku_txn_abort(txn, NULL, NULL, false);
|
||||
}
|
||||
if (!holds_ydb_lock) toku_ydb_unlock();
|
||||
toku_ydb_unlock();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -764,10 +764,10 @@ cleanup:
|
|||
int
|
||||
autotxn_db_del(DB* db, DB_TXN* txn, DBT* key, u_int32_t flags) {
|
||||
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;
|
||||
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
|
||||
|
@ -776,12 +776,12 @@ autotxn_db_put(DB* db, DB_TXN* txn, DBT* key, DBT* data, u_int32_t flags) {
|
|||
BOOL changed; int r;
|
||||
r = env_check_avail_fs_space(db->dbenv);
|
||||
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) {
|
||||
goto cleanup;
|
||||
}
|
||||
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:
|
||||
return r;
|
||||
}
|
||||
|
@ -794,10 +794,10 @@ autotxn_db_update(DB *db, DB_TXN *txn,
|
|||
BOOL changed; int r;
|
||||
r = env_check_avail_fs_space(db->dbenv);
|
||||
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; }
|
||||
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:
|
||||
return r;
|
||||
}
|
||||
|
@ -809,10 +809,10 @@ autotxn_db_update_broadcast(DB *db, DB_TXN *txn,
|
|||
BOOL changed; int r;
|
||||
r = env_check_avail_fs_space(db->dbenv);
|
||||
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; }
|
||||
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:
|
||||
return r;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue