Commit 3d6e8bef authored by Leif Walsh's avatar Leif Walsh Committed by Yoni Fogel

refs #5206 address review comments: remove static "allocation constructors",...

refs #5206 address review comments: remove static "allocation constructors", rename init/deinit to create/destroy


git-svn-id: file:///svn/toku/tokudb@45938 c7de825b-a66e-492c-adef-691d508d4ae1
parent d616c4cd
......@@ -2263,9 +2263,9 @@ toku_bnc_flush_to_child(
ft_leaf_gc_all_les(child, h, snapshot_txnids, referenced_xids, live_root_txns);
// Free the OMT's we used for garbage collecting.
snapshot_txnids.deinit();
live_root_txns.deinit();
referenced_xids.deinit();
snapshot_txnids.destroy();
live_root_txns.destroy();
referenced_xids.destroy();
}
return 0;
......
......@@ -970,14 +970,14 @@ deserialize_child_buffer(NONLEAF_CHILDINFO bnc, struct rbuf *rbuf,
struct toku_fifo_entry_key_msn_cmp_extra extra = { .desc = desc, .cmp = cmp, .fifo = bnc->buffer };
r = toku::sort<long, const struct toku_fifo_entry_key_msn_cmp_extra, toku_fifo_entry_key_msn_cmp>::mergesort_r(fresh_offsets, nfresh, extra);
assert_zero(r);
bnc->fresh_message_tree.deinit();
bnc->fresh_message_tree.init_steal_sorted_array(fresh_offsets, nfresh, n_in_this_buffer);
bnc->fresh_message_tree.destroy();
bnc->fresh_message_tree.create_steal_sorted_array(fresh_offsets, nfresh, n_in_this_buffer);
r = toku::sort<long, const struct toku_fifo_entry_key_msn_cmp_extra, toku_fifo_entry_key_msn_cmp>::mergesort_r(stale_offsets, nstale, extra);
assert_zero(r);
bnc->stale_message_tree.deinit();
bnc->stale_message_tree.init_steal_sorted_array(stale_offsets, nstale, n_in_this_buffer);
bnc->broadcast_list.deinit();
bnc->broadcast_list.init_steal_sorted_array(broadcast_offsets, nbroadcast_offsets, n_in_this_buffer);
bnc->stale_message_tree.destroy();
bnc->stale_message_tree.create_steal_sorted_array(stale_offsets, nstale, n_in_this_buffer);
bnc->broadcast_list.destroy();
bnc->broadcast_list.create_steal_sorted_array(broadcast_offsets, nbroadcast_offsets, n_in_this_buffer);
}
}
......@@ -1074,9 +1074,9 @@ BASEMENTNODE toku_create_empty_bn_no_buffer(void) {
NONLEAF_CHILDINFO toku_create_empty_nl(void) {
NONLEAF_CHILDINFO XMALLOC(cn);
int r = toku_fifo_create(&cn->buffer); assert_zero(r);
cn->fresh_message_tree.init();
cn->stale_message_tree.init();
cn->broadcast_list.init();
cn->fresh_message_tree.create();
cn->stale_message_tree.create();
cn->broadcast_list.create();
return cn;
}
......@@ -1084,9 +1084,9 @@ NONLEAF_CHILDINFO toku_create_empty_nl(void) {
NONLEAF_CHILDINFO toku_clone_nl(NONLEAF_CHILDINFO orig_childinfo) {
NONLEAF_CHILDINFO XMALLOC(cn);
toku_fifo_clone(orig_childinfo->buffer, &cn->buffer);
cn->fresh_message_tree.init_no_array();
cn->stale_message_tree.init_no_array();
cn->broadcast_list.init_no_array();
cn->fresh_message_tree.create_no_array();
cn->stale_message_tree.create_no_array();
cn->broadcast_list.create_no_array();
return cn;
}
......@@ -1102,9 +1102,9 @@ void destroy_basement_node (BASEMENTNODE bn)
void destroy_nonleaf_childinfo (NONLEAF_CHILDINFO nl)
{
toku_fifo_free(&nl->buffer);
nl->fresh_message_tree.deinit();
nl->stale_message_tree.deinit();
nl->broadcast_list.deinit();
nl->fresh_message_tree.destroy();
nl->stale_message_tree.destroy();
nl->broadcast_list.destroy();
toku_free(nl);
}
......@@ -1861,10 +1861,10 @@ deserialize_and_upgrade_internal_node(FTNODE node,
typedef toku::sort<long, const struct toku_fifo_entry_key_msn_cmp_extra, toku_fifo_entry_key_msn_cmp> key_msn_sort;
r = key_msn_sort::mergesort_r(fresh_offsets, nfresh, extra);
assert_zero(r);
bnc->fresh_message_tree.deinit();
bnc->fresh_message_tree.init_steal_sorted_array(fresh_offsets, nfresh, n_in_this_buffer);
bnc->broadcast_list.deinit();
bnc->broadcast_list.init_steal_sorted_array(broadcast_offsets, nbroadcast_offsets, n_in_this_buffer);
bnc->fresh_message_tree.destroy();
bnc->fresh_message_tree.create_steal_sorted_array(fresh_offsets, nfresh, n_in_this_buffer);
bnc->broadcast_list.destroy();
bnc->broadcast_list.create_steal_sorted_array(broadcast_offsets, nbroadcast_offsets, n_in_this_buffer);
}
}
......
......@@ -26,71 +26,28 @@ namespace toku {
template<typename omtdata_t,
typename omtdataout_t=omtdata_t>
struct omt {
/**
*
*/
static void create(struct omt *&omt)
{
XMALLOC(omt);
omt->init();
}
/**
*
*/
static void create_from_sorted_array(struct omt *&omt,
const omtdata_t *values,
const uint32_t numvalues)
{
XMALLOC(omt);
omt->init_from_sorted_array(values, numvalues);
}
/**
*
*/
static void create_steal_sorted_array(struct omt *&omt,
omtdata_t *&values,
const uint32_t numvalues,
const uint32_t capacity_)
{
XMALLOC(omt);
omt->init_steal_sorted_array(values, numvalues, capacity_);
}
/**
*
*/
static void destroy(struct omt *&omt)
{
omt->deinit();
toku_free(omt);
omt = nullptr;
}
/**
*
*/
void init(void)
void create(void)
{
this->init_internal(2);
this->create_internal(2);
}
/**
*
*/
void init_no_array(void)
void create_no_array(void)
{
this->init_internal_no_array(0);
this->create_internal_no_array(0);
}
/**
*
*/
void init_from_sorted_array(const omtdata_t *values, const uint32_t numvalues)
void create_from_sorted_array(const omtdata_t *values, const uint32_t numvalues)
{
this->init_internal(numvalues);
this->create_internal(numvalues);
memcpy(this->d.a.values, values, numvalues * (sizeof values[0]));
this->d.a.num_values = numvalues;
}
......@@ -98,9 +55,9 @@ namespace toku {
/**
*
*/
void init_steal_sorted_array(omtdata_t *&values, const uint32_t numvalues, const uint32_t capacity_)
void create_steal_sorted_array(omtdata_t *&values, const uint32_t numvalues, const uint32_t capacity_)
{
this->init_internal_no_array(capacity_);
this->create_internal_no_array(capacity_);
this->d.a.num_values = numvalues;
this->d.a.values = values;
values = nullptr;
......@@ -109,11 +66,11 @@ namespace toku {
/**
*
*/
void split_at_init(omt &newomt, const uint32_t idx) {
void split_at(omt &newomt, const uint32_t idx) {
if (idx > this->size()) { return EINVAL; }
this->convert_to_array();
const uint32_t newsize = this->size() - idx;
newomt.init_from_sorted_array(&this->d.a.values[this->d.a.start_idx + idx], newsize);
newomt.create_from_sorted_array(&this->d.a.values[this->d.a.start_idx + idx], newsize);
this->d.a.num_values = idx;
this->maybe_resize_array();
}
......@@ -121,35 +78,26 @@ namespace toku {
/**
*
*/
void split_at_create(omt *&newomt, const uint32_t idx) {
if (idx > this->size()) { return EINVAL; }
XMALLOC(newomt);
this->split_at_init(*newomt, idx);
}
/**
*
*/
void merge_init(omt &leftomt, omt &rightomt) {
void merge(omt &leftomt, omt &rightomt) {
const uint32_t leftsize = leftomt.size();
const uint32_t rightsize = rightomt.size();
const uint32_t newsize = leftsize + rightsize;
if (leftomt.is_array) {
if (leftomt.capacity - (leftomt.d.a.start_idx + leftomt.d.a.num_values) >= rightsize) {
this->init_steal_sorted_array(leftomt.d.a.values, leftomt.d.a.num_values, leftomt.capacity);
this->create_steal_sorted_array(leftomt.d.a.values, leftomt.d.a.num_values, leftomt.capacity);
this->d.a.start_idx = leftomt.d.a.start_idx;
} else {
this->init_internal(newsize);
this->create_internal(newsize);
memcpy(&this->d.a.values[0],
&leftomt.d.a.values[leftomt.d.a.start_idx],
leftomt.d.a.num_values * (sizeof this->d.a.values[0]));
}
} else {
this->init_internal(newsize);
this->create_internal(newsize);
leftomt.fill_array_with_subtree_values(&this->d.a.values[0], leftomt.d.t.root);
}
leftomt.deinit();
leftomt.destroy();
this->d.a.num_values = leftsize;
if (rightomt.is_array) {
......@@ -160,7 +108,7 @@ namespace toku {
rightomt.fill_array_with_subtree_values(&this->d.a.values[this->d.a.start_idx + this->d.a.num_values],
rightomt.d.t.root);
}
rightomt.deinit();
rightomt.destroy();
this->d.a.num_values += rightsize;
invariant(this->size() == newsize);
}
......@@ -168,17 +116,9 @@ namespace toku {
/**
*
*/
static void merge_create(omt *&newomt, omt &leftomt, omt &rightomt) {
XMALLOC(newomt);
newomt->merge_init(leftomt, rightomt);
}
/**
*
*/
void clone_init(const omt &src)
void clone(const omt &src)
{
this->init_internal(src.size());
this->create_internal(src.size());
if (src.is_array) {
memcpy(&this->d.a.values[0], &src.d.a.values[src.d.a.start_idx], src.d.a.num_values * (sizeof this->d.a.values[0]));
} else {
......@@ -190,30 +130,14 @@ namespace toku {
/**
*
*/
static void clone_create(omt *&newomt, const omt &src) {
XMALLOC(newomt);
newomt->clone_init(src);
}
/**
*
*/
void deep_clone_init(const omt &src)
void deep_clone(const omt &src)
{
this->init_internal(src.size());
this->create_internal(src.size());
int r = src.iterate<omt, deep_clone_iter>(*this);
lazy_assert_zero(r);
this->d.a.num_values = src.size();
}
/**
*
*/
static void deep_clone_create(omt *&newomt, const omt &src) {
XMALLOC(newomt);
newomt->deep_clone_init(src);
}
/**
*
*/
......@@ -231,7 +155,7 @@ namespace toku {
/**
*
*/
void deinit(void)
void destroy(void)
{
this->clear();
this->capacity = 0;
......@@ -497,7 +421,7 @@ namespace toku {
} d;
void init_internal_no_array(const uint32_t capacity_) {
void create_internal_no_array(const uint32_t capacity_) {
this->is_array = true;
this->capacity = capacity_;
this->d.a.start_idx = 0;
......@@ -505,8 +429,8 @@ namespace toku {
this->d.a.values = nullptr;
}
void init_internal(const uint32_t capacity_) {
this->init_internal_no_array(capacity_);
void create_internal(const uint32_t capacity_) {
this->create_internal_no_array(capacity_);
XMALLOC_N(this->capacity, this->d.a.values);
}
......
......@@ -75,6 +75,7 @@ static void reset_table_compress(qlz_state_compress *state)
state->hash[i].offset = 0;
#else
state->hash_counter[i] = 0;
state->hash[i].offset[0] = 0;
#endif
}
}
......
......@@ -171,10 +171,10 @@ verify_snapshot_system(TXN_MANAGER txn_manager UU()) {
void toku_txn_manager_init(TXN_MANAGER* txn_managerp) {
TXN_MANAGER XCALLOC(txn_manager);
toku_mutex_init(&txn_manager->txn_manager_lock, NULL);
txn_manager->live_txns.init();
txn_manager->live_root_txns.init();
txn_manager->snapshot_txnids.init();
txn_manager->referenced_xids.init();
txn_manager->live_txns.create();
txn_manager->live_root_txns.create();
txn_manager->snapshot_txnids.create();
txn_manager->referenced_xids.create();
txn_manager->last_xid = 0;
toku_list_init(&txn_manager->prepared_txns);
toku_list_init(&txn_manager->prepared_and_returned_txns);
......@@ -185,10 +185,10 @@ void toku_txn_manager_init(TXN_MANAGER* txn_managerp) {
void toku_txn_manager_destroy(TXN_MANAGER txn_manager) {
toku_mutex_destroy(&txn_manager->txn_manager_lock);
txn_manager->live_txns.deinit();
txn_manager->live_root_txns.deinit();
txn_manager->snapshot_txnids.deinit();
txn_manager->referenced_xids.deinit();
txn_manager->live_txns.destroy();
txn_manager->live_root_txns.destroy();
txn_manager->snapshot_txnids.destroy();
txn_manager->referenced_xids.destroy();
toku_cond_destroy(&txn_manager->wait_for_unpin_of_txn);
toku_free(txn_manager);
}
......@@ -212,7 +212,9 @@ toku_txn_manager_get_oldest_living_xid(TXN_MANAGER txn_manager) {
static void
setup_live_root_txn_list(TXN_MANAGER txn_manager, TOKUTXN txn) {
invariant(txn_manager->live_root_txns.size() > 0);
xid_omt_t::clone_create(txn->live_root_txn_list, txn_manager->live_root_txns);
invariant(txn->live_root_txn_list == nullptr);
XMALLOC(txn->live_root_txn_list);
txn->live_root_txn_list->clone(txn_manager->live_root_txns);
}
//Heaviside function to search through an OMT by a TXNID
......@@ -532,7 +534,8 @@ void toku_txn_manager_finish_txn(TXN_MANAGER txn_manager, TOKUTXN txn) {
//Cleanup that does not require the txn_manager lock
if (is_snapshot) {
invariant(txn->live_root_txn_list != nullptr);
xid_omt_t::destroy(txn->live_root_txn_list);
txn->live_root_txn_list->destroy();
toku_free(txn->live_root_txn_list);
}
}
......@@ -544,9 +547,9 @@ void toku_txn_manager_clone_state_for_gc(
)
{
toku_mutex_lock(&txn_manager->txn_manager_lock);
snapshot_xids.clone_init(txn_manager->snapshot_txnids);
referenced_xids.clone_init(txn_manager->referenced_xids);
live_root_txns.clone_init(txn_manager->live_root_txns);
snapshot_xids.clone(txn_manager->snapshot_txnids);
referenced_xids.clone(txn_manager->referenced_xids);
live_root_txns.clone(txn_manager->live_root_txns);
toku_mutex_unlock(&txn_manager->txn_manager_lock);
}
......
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