Commit 868c5872 authored by Rik Prohaska's avatar Rik Prohaska

DB-832 capture txn start time and make it available to the txn object and live txn iterator

Conflicts:
	ft/txn/txn.cc
parent c8b7fd67
......@@ -587,6 +587,7 @@ static void print_db_txn_struct (void) {
"uint64_t (*get_client_id)(DB_TXN *)",
"bool (*is_prepared)(DB_TXN *)",
"DB_TXN *(*get_child)(DB_TXN *)",
"uint64_t (*get_start_time)(DB_TXN *)",
NULL};
sort_and_dump_fields("db_txn", false, extra);
}
......@@ -786,7 +787,7 @@ int main (int argc, char *const argv[] __attribute__((__unused__))) {
printf("typedef void (*lock_timeout_callback)(DB *db, uint64_t requesting_txnid, const DBT *left_key, const DBT *right_key, uint64_t blocking_txnid);\n");
printf("typedef int (*iterate_row_locks_callback)(DB **db, DBT *left_key, DBT *right_key, void *extra);\n");
printf("typedef int (*iterate_transactions_callback)(uint64_t txnid, uint64_t client_id, iterate_row_locks_callback cb, void *locks_extra, void *extra);\n");
printf("typedef int (*iterate_transactions_callback)(DB_TXN *dbtxn, iterate_row_locks_callback cb, void *locks_extra, void *extra);\n");
printf("typedef int (*iterate_requests_callback)(DB *db, uint64_t requesting_txnid, const DBT *left_key, const DBT *right_key, uint64_t blocking_txnid, uint64_t start_time, void *extra);\n");
print_db_env_struct();
print_db_key_range_struct();
......
......@@ -342,6 +342,7 @@ static txn_child_manager tcm;
.state = TOKUTXN_LIVE,
.num_pin = 0,
.client_id = 0,
.start_time = time(NULL),
};
TOKUTXN result = NULL;
......@@ -785,6 +786,10 @@ void toku_txn_set_client_id(TOKUTXN txn, uint64_t client_id) {
txn->client_id = client_id;
}
time_t toku_txn_get_start_time(struct tokutxn *txn) {
return txn->start_time;
}
int toku_txn_reads_txnid(TXNID txnid, TOKUTXN txn) {
int r = 0;
TXNID oldest_live_in_snapshot = toku_get_oldest_in_live_root_txn_list(txn);
......
......@@ -253,6 +253,7 @@ struct tokutxn {
uint32_t num_pin; // number of threads (all hot indexes) that want this
// txn to not transition to commit or abort
uint64_t client_id;
time_t start_time;
};
typedef struct tokutxn *TOKUTXN;
......@@ -368,6 +369,8 @@ bool toku_txn_has_spilled_rollback(struct tokutxn *txn);
uint64_t toku_txn_get_client_id(struct tokutxn *txn);
void toku_txn_set_client_id(struct tokutxn *txn, uint64_t client_id);
time_t toku_txn_get_start_time(struct tokutxn *txn);
//
// This function is used by the leafentry iterators.
// returns TOKUDB_ACCEPT if live transaction context is allowed to read a value
......
......@@ -104,9 +104,11 @@ struct iterate_extra {
bool visited_txn[3];
};
static int iterate_callback(uint64_t txnid, uint64_t client_id,
static int iterate_callback(DB_TXN *txn,
iterate_row_locks_callback iterate_locks,
void *locks_extra, void *extra) {
uint64_t txnid = txn->id64(txn);
uint64_t client_id = txn->get_client_id(txn);
iterate_extra *info = reinterpret_cast<iterate_extra *>(extra);
DB *db;
DBT left_key, right_key;
......
......@@ -140,9 +140,11 @@ static int UU() iterate_pending_lock_requests_op(DB_TXN *UU(txn), ARG arg, void
return r;
}
static int iterate_txns(uint64_t txnid, uint64_t client_id,
static int iterate_txns(DB_TXN *txn,
iterate_row_locks_callback iterate_locks,
void *locks_extra, void *extra) {
uint64_t txnid = txn->id64(txn);
uint64_t client_id = txn->get_client_id(txn);
invariant_null(extra);
invariant(txnid > 0);
invariant(client_id == 0);
......
......@@ -2500,8 +2500,7 @@ static int iter_txns_callback(TOKUTXN txn, void *extra) {
toku_pthread_rwlock_rdlock(&info->env->i->open_dbs_rwlock);
iter_txn_row_locks_callback_extra e(info->env, &db_txn_struct_i(dbtxn)->lt_map);
const int r = info->callback(toku_txn_get_txnid(txn).parent_id64,
toku_txn_get_client_id(txn),
const int r = info->callback(dbtxn,
iter_txn_row_locks_callback,
&e,
info->extra);
......
......@@ -432,6 +432,11 @@ static DB_TXN *toku_txn_get_child(DB_TXN *txn) {
return db_txn_struct_i(txn)->child;
}
static uint64_t toku_txn_get_start_time(DB_TXN *txn) {
TOKUTXN ttxn = db_txn_struct_i(txn)->tokutxn;
return toku_txn_get_start_time(ttxn);
}
static inline void txn_func_init(DB_TXN *txn) {
#define STXN(name) txn->name = locked_txn_ ## name
STXN(abort);
......@@ -450,6 +455,7 @@ static inline void txn_func_init(DB_TXN *txn) {
txn->id64 = toku_txn_id64;
txn->is_prepared = toku_txn_is_prepared;
txn->get_child = toku_txn_get_child;
txn->get_start_time = toku_txn_get_start_time;
}
//
......
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