Commit 0cd9fdc1 authored by John Esmet's avatar John Esmet Committed by Yoni Fogel

fixes #6100 #6232 track memory usage in each txn's range buffer, resetting on...

fixes #6100 #6232 track memory usage in each txn's range buffer, resetting on txn commit and in the escalation callback. large write transactions that get redundant locks in the locktree will now be under control.


git-svn-id: file:///svn/toku/tokudb@54278 c7de825b-a66e-492c-adef-691d508d4ae1
parent d697e3ad
...@@ -671,6 +671,10 @@ void locktree::set_descriptor(DESCRIPTOR desc) { ...@@ -671,6 +671,10 @@ void locktree::set_descriptor(DESCRIPTOR desc) {
m_cmp->set_descriptor(desc); m_cmp->set_descriptor(desc);
} }
locktree::manager::memory_tracker *locktree::get_mem_tracker(void) const {
return m_mem_tracker;
}
int locktree::compare(const locktree *lt) { int locktree::compare(const locktree *lt) {
if (m_dict_id.dictid < lt->m_dict_id.dictid) { if (m_dict_id.dictid < lt->m_dict_id.dictid) {
return -1; return -1;
......
...@@ -251,6 +251,8 @@ class locktree { ...@@ -251,6 +251,8 @@ class locktree {
}; };
ENSURE_POD(manager); ENSURE_POD(manager);
manager::memory_tracker *get_mem_tracker(void) const;
private: private:
manager::memory_tracker *m_mem_tracker; manager::memory_tracker *m_mem_tracker;
......
...@@ -59,7 +59,11 @@ static void db_txn_note_row_lock(DB *db, DB_TXN *txn, const DBT *left_key, const ...@@ -59,7 +59,11 @@ static void db_txn_note_row_lock(DB *db, DB_TXN *txn, const DBT *left_key, const
} }
// add a new lock range to this txn's row lock buffer // add a new lock range to this txn's row lock buffer
size_t old_num_bytes = ranges.buffer->get_num_bytes();
ranges.buffer->append(left_key, right_key); ranges.buffer->append(left_key, right_key);
size_t new_num_bytes = ranges.buffer->get_num_bytes();
invariant(new_num_bytes > old_num_bytes);
lt->get_mem_tracker()->note_mem_used(new_num_bytes - old_num_bytes);
toku_mutex_unlock(&db_txn_struct_i(txn)->txn_mutex); toku_mutex_unlock(&db_txn_struct_i(txn)->txn_mutex);
} }
...@@ -112,6 +116,7 @@ void toku_db_txn_escalate_callback(TXNID txnid, const toku::locktree *lt, const ...@@ -112,6 +116,7 @@ void toku_db_txn_escalate_callback(TXNID txnid, const toku::locktree *lt, const
// //
// We could theoretically steal the memory from the caller instead of copying // We could theoretically steal the memory from the caller instead of copying
// it, but it's simpler to have a callback API that doesn't transfer memory ownership. // it, but it's simpler to have a callback API that doesn't transfer memory ownership.
lt->get_mem_tracker()->note_mem_released(ranges.buffer->get_num_bytes());
ranges.buffer->destroy(); ranges.buffer->destroy();
ranges.buffer->create(); ranges.buffer->create();
toku::range_buffer::iterator iter; toku::range_buffer::iterator iter;
...@@ -121,6 +126,7 @@ void toku_db_txn_escalate_callback(TXNID txnid, const toku::locktree *lt, const ...@@ -121,6 +126,7 @@ void toku_db_txn_escalate_callback(TXNID txnid, const toku::locktree *lt, const
ranges.buffer->append(rec.get_left_key(), rec.get_right_key()); ranges.buffer->append(rec.get_left_key(), rec.get_right_key());
iter.next(); iter.next();
} }
lt->get_mem_tracker()->note_mem_used(ranges.buffer->get_num_bytes());
} else { } else {
// In rare cases, we may not find the associated locktree, because we are // In rare cases, we may not find the associated locktree, because we are
// racing with the transaction trying to add this locktree to the lt map // racing with the transaction trying to add this locktree to the lt map
...@@ -209,6 +215,7 @@ void toku_db_release_lt_key_ranges(DB_TXN *txn, txn_lt_key_ranges *ranges) { ...@@ -209,6 +215,7 @@ void toku_db_release_lt_key_ranges(DB_TXN *txn, txn_lt_key_ranges *ranges) {
// release all of the locks this txn has ever successfully // release all of the locks this txn has ever successfully
// acquired and stored in the range buffer for this locktree // acquired and stored in the range buffer for this locktree
lt->release_locks(txnid, ranges->buffer); lt->release_locks(txnid, ranges->buffer);
lt->get_mem_tracker()->note_mem_released(ranges->buffer->get_num_bytes());
ranges->buffer->destroy(); ranges->buffer->destroy();
toku_free(ranges->buffer); toku_free(ranges->buffer);
......
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