Commit 2c1583ca authored by Yoni Fogel's avatar Yoni Fogel

[t:5106] closes #5106 Replaced txn omt (in FT) with integer

git-svn-id: file:///svn/toku/tokudb@44754 c7de825b-a66e-492c-adef-691d508d4ae1
parent 5cb07ca1
......@@ -445,14 +445,14 @@ struct ft {
TXNID txnid_that_created_or_locked_when_empty;
TXNID txnid_that_suppressed_recovery_logs;
// Logically the reference count is zero if live_ft_handles is empty, txns is empty, and pinned_by_checkpoint is false.
// Logically the reference count is zero if live_ft_handles is empty, txns is 0, and pinned_by_checkpoint is false.
// ft_ref_lock protects modifying live_ft_handles, txns, and pinned_by_checkpoint.
toku_mutex_t ft_ref_lock;
struct toku_list live_ft_handles;
// transactions that are using this header. you should only be able
// to modify this if you have a valid handle in the list of live brts
OMT txns;
// Number of transactions that are using this FT. you should only be able
// to modify this if you have a valid handle in live_ft_handles
uint32_t num_txns;
// A checkpoint is running. If true, then keep this header around for checkpoint, like a transaction
bool pinned_by_checkpoint;
......
......@@ -158,8 +158,6 @@ deserialize_ft_versioned(int fd, struct rbuf *rb, FT *ftp, uint32_t version)
ft->panic = 0;
ft->panic_string = 0;
toku_list_init(&ft->live_ft_handles);
r = toku_omt_create(&ft->txns);
assert_zero(r);
//version MUST be in network order on disk regardless of disk order
ft->layout_version_read_from_disk = rbuf_network_int(rb);
......
......@@ -41,7 +41,6 @@ ft_destroy(FT ft) {
if (ft->cmp_descriptor.dbt.data) toku_free(ft->cmp_descriptor.dbt.data);
toku_ft_destroy_treelock(ft);
toku_ft_destroy_reflock(ft);
toku_omt_destroy(&ft->txns);
toku_free(ft->h);
}
......@@ -385,8 +384,6 @@ ft_init(FT ft, FT_OPTIONS options, CACHEFILE cf) {
ft->layout_version_read_from_disk = FT_LAYOUT_VERSION; // fake, prevent unnecessary upgrade logic
toku_list_init(&ft->live_ft_handles);
int r = toku_omt_create(&ft->txns);
assert_zero(r);
ft->compare_fun = options->compare_fun;
ft->update_fun = options->update_fun;
......@@ -397,6 +394,7 @@ ft_init(FT ft, FT_OPTIONS options, CACHEFILE cf) {
ft->cf = cf;
ft->in_memory_stats = ZEROSTATS;
int r;
r = setup_initial_ft_root_node(ft, ft->h->root_blocknum);
if (r != 0) {
goto exit;
......@@ -550,9 +548,8 @@ toku_ft_note_ft_handle_open(FT ft, FT_HANDLE live) {
static int
ft_get_reference_count(FT ft) {
u_int32_t pinned_by_checkpoint = ft->pinned_by_checkpoint ? 1 : 0;
u_int32_t num_txns = toku_omt_size(ft->txns);
int num_handles = toku_list_num_elements_est(&ft->live_ft_handles);
return pinned_by_checkpoint + num_txns + num_handles;
return pinned_by_checkpoint + ft->num_txns + num_handles;
}
// a ft is needed in memory iff its reference count is non-zero
......@@ -842,40 +839,23 @@ toku_dictionary_redirect (const char *dst_fname_in_env, FT_HANDLE old_ft_h, TOKU
return r;
}
//Heaviside function to find a TOKUTXN by TOKUTXN (used to find the index)
static int find_xid (OMTVALUE v, void *txnv) {
TOKUTXN txn = v;
TOKUTXN txnfind = txnv;
if (txn->txnid64<txnfind->txnid64) return -1;
if (txn->txnid64>txnfind->txnid64) return +1;
return 0;
}
// Insert reference to transaction into ft
void
toku_ft_add_txn_ref(FT ft, TOKUTXN txn) {
toku_ft_add_txn_ref(FT ft) {
toku_ft_grab_reflock(ft);
uint32_t idx;
int r = toku_omt_insert(ft->txns, txn, find_xid, txn, &idx);
assert(r==0);
++ft->num_txns;
toku_ft_release_reflock(ft);
}
static void
remove_txn_ref_callback(FT ft, void *context) {
TOKUTXN txn = context;
OMTVALUE txnv_again=NULL;
u_int32_t index;
int r = toku_omt_find_zero(ft->txns, find_xid, txn, &txnv_again, &index);
assert(r==0);
assert(txnv_again == txn);
r = toku_omt_delete_at(ft->txns, index);
assert(r==0);
remove_txn_ref_callback(FT ft, void *UU(context)) {
invariant(ft->num_txns > 0);
--ft->num_txns;
}
void
toku_ft_remove_txn_ref(FT ft, TOKUTXN txn) {
toku_ft_remove_reference(ft, false, ZERO_LSN, remove_txn_ref_callback, txn);
toku_ft_remove_txn_ref(FT ft) {
toku_ft_remove_reference(ft, false, ZERO_LSN, remove_txn_ref_callback, NULL);
}
void toku_calculate_root_offset_pointer (
......
......@@ -70,10 +70,8 @@ void toku_reset_root_xid_that_created(FT h, TXNID new_root_xid_that_created);
// This redefines which xid created the dictionary.
void
toku_ft_add_txn_ref(FT h, TOKUTXN txn);
void
toku_ft_remove_txn_ref(FT h, TOKUTXN txn);
void toku_ft_add_txn_ref(FT h);
void toku_ft_remove_txn_ref(FT h);
void toku_calculate_root_offset_pointer ( FT h, CACHEKEY* root_key, u_int32_t *roothash);
void toku_ft_set_new_root_blocknum(FT h, CACHEKEY new_root_key);
......
......@@ -154,7 +154,7 @@ void toku_txn_maybe_note_ft (TOKUTXN txn, FT ft) {
assert_zero(r);
// TODO(leif): if there's anything that locks the reflock and then
// the txn lock, this may deadlock, because it grabs the reflock.
toku_ft_add_txn_ref(ft, txn);
toku_ft_add_txn_ref(ft);
exit:
toku_txn_unlock(txn);
}
......
......@@ -414,7 +414,7 @@ static int remove_txn (OMTVALUE hv, u_int32_t UU(idx), void *txnv)
if (txn->txnid64==h->txnid_that_suppressed_recovery_logs) {
h->txnid_that_suppressed_recovery_logs = TXNID_NONE;
}
toku_ft_remove_txn_ref(h, txn);
toku_ft_remove_txn_ref(h);
return 0;
}
......
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