Commit d814701d authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

refs #5370, put partitioned counters in evictor

git-svn-id: file:///svn/toku/tokudb@47148 c7de825b-a66e-492c-adef-691d508d4ae1
parent fda14cdd
......@@ -12,6 +12,7 @@
#include "nonblocking_mutex.h"
#include "kibbutz.h"
#include "background_job_manager.h"
#include "partitioned_counter.h"
//////////////////////////////////////////////////////////////////////////////
//
......@@ -426,10 +427,10 @@ private:
toku_cond_t m_flow_control_cond;
// variables for engine status
int64_t m_size_nonleaf;
int64_t m_size_leaf;
int64_t m_size_rollback;
int64_t m_size_cachepressure;
PARTITIONED_COUNTER m_size_nonleaf;
PARTITIONED_COUNTER m_size_leaf;
PARTITIONED_COUNTER m_size_rollback;
PARTITIONED_COUNTER m_size_cachepressure;
KIBBUTZ m_kibbutz;
......
......@@ -3582,12 +3582,13 @@ void evictor::init(long _size_limit, pair_list* _pl, KIBBUTZ _kibbutz, uint32_t
m_high_size_watermark = (3 * _size_limit)/2; // 50% more
m_size_reserved = unreservable_memory(_size_limit);
m_size_nonleaf = 0;
m_size_current = 0;
m_size_evicting = 0;
m_size_leaf = 0;
m_size_rollback = 0;
m_size_cachepressure = 0;
m_size_nonleaf = create_partitioned_counter();
m_size_leaf = create_partitioned_counter();
m_size_rollback = create_partitioned_counter();
m_size_cachepressure = create_partitioned_counter();
m_pl = _pl;
m_kibbutz = _kibbutz;
......@@ -3624,6 +3625,15 @@ void evictor::destroy() {
assert_zero(r);
assert(!m_ev_thread_is_running);
destroy_partitioned_counter(m_size_nonleaf);
m_size_nonleaf = NULL;
destroy_partitioned_counter(m_size_leaf);
m_size_leaf = NULL;
destroy_partitioned_counter(m_size_rollback);
m_size_rollback = NULL;
destroy_partitioned_counter(m_size_cachepressure);
m_size_cachepressure = NULL;
toku_cond_destroy(&m_flow_control_cond);
toku_cond_destroy(&m_ev_thread_cond);
toku_mutex_destroy(&m_ev_thread_lock);
......@@ -3636,10 +3646,10 @@ void evictor::destroy() {
void evictor::add_pair_attr(PAIR_ATTR attr) {
assert(attr.is_valid);
add_to_size_current(attr.size);
(void) __sync_fetch_and_add(&m_size_nonleaf, attr.nonleaf_size);
(void) __sync_fetch_and_add(&m_size_leaf, attr.leaf_size);
(void) __sync_fetch_and_add(&m_size_rollback, attr.rollback_size);
(void) __sync_fetch_and_add(&m_size_cachepressure, attr.cache_pressure_size);
increment_partitioned_counter(m_size_nonleaf, attr.nonleaf_size);
increment_partitioned_counter(m_size_leaf, attr.leaf_size);
increment_partitioned_counter(m_size_rollback, attr.rollback_size);
increment_partitioned_counter(m_size_cachepressure, attr.cache_pressure_size);
}
//
......@@ -3649,10 +3659,10 @@ void evictor::add_pair_attr(PAIR_ATTR attr) {
void evictor::remove_pair_attr(PAIR_ATTR attr) {
assert(attr.is_valid);
remove_from_size_current(attr.size);
(void) __sync_fetch_and_sub(&m_size_nonleaf, attr.nonleaf_size);
(void) __sync_fetch_and_sub(&m_size_leaf, attr.leaf_size);
(void) __sync_fetch_and_sub(&m_size_rollback, attr.rollback_size);
(void) __sync_fetch_and_sub(&m_size_cachepressure, attr.cache_pressure_size);
increment_partitioned_counter(m_size_nonleaf, 0 - attr.nonleaf_size);
increment_partitioned_counter(m_size_leaf, 0 - attr.leaf_size);
increment_partitioned_counter(m_size_rollback, 0 - attr.rollback_size);
increment_partitioned_counter(m_size_cachepressure, 0 - attr.cache_pressure_size);
assert(m_size_current >= 0);
}
......@@ -4141,10 +4151,10 @@ void evictor::fill_engine_status() {
STATUS_VALUE(CT_SIZE_CURRENT) = m_size_current;
STATUS_VALUE(CT_SIZE_LIMIT) = m_low_size_hysteresis;
STATUS_VALUE(CT_SIZE_WRITING) = m_size_evicting;
STATUS_VALUE(CT_SIZE_NONLEAF) = m_size_nonleaf;
STATUS_VALUE(CT_SIZE_LEAF) = m_size_leaf;
STATUS_VALUE(CT_SIZE_ROLLBACK) = m_size_rollback;
STATUS_VALUE(CT_SIZE_CACHEPRESSURE) = m_size_cachepressure;
STATUS_VALUE(CT_SIZE_NONLEAF) = read_partitioned_counter(m_size_nonleaf);
STATUS_VALUE(CT_SIZE_LEAF) = read_partitioned_counter(m_size_leaf);
STATUS_VALUE(CT_SIZE_ROLLBACK) = read_partitioned_counter(m_size_rollback);
STATUS_VALUE(CT_SIZE_CACHEPRESSURE) = read_partitioned_counter(m_size_cachepressure);
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -44,10 +44,10 @@ void evictor_unit_test::verify_ev_init(long limit) {
assert(m_ev.m_num_sleepers == 0);
assert(m_ev.m_run_thread == true);
assert(m_ev.m_size_current == 0);
assert(m_ev.m_size_leaf== 0);
assert(m_ev.m_size_nonleaf== 0);
assert(m_ev.m_size_rollback== 0);
assert(m_ev.m_size_cachepressure == 0);
assert(read_partitioned_counter(m_ev.m_size_leaf) == 0);
assert(read_partitioned_counter(m_ev.m_size_nonleaf) == 0);
assert(read_partitioned_counter(m_ev.m_size_rollback) == 0);
assert(read_partitioned_counter(m_ev.m_size_cachepressure) == 0);
assert(m_ev.m_size_evicting == 0);
// this comes from definition of unreservable_memory in cachetable.cc
assert(m_ev.m_size_reserved == (limit/4));
......@@ -81,10 +81,10 @@ void evictor_unit_test::verify_ev_counts() {
m_ev.add_to_size_current(1);
assert(m_ev.m_size_current == 1);
assert(m_ev.m_size_reserved == expected_m_size_reserved);
assert(m_ev.m_size_leaf == 0);
assert(m_ev.m_size_nonleaf == 0);
assert(m_ev.m_size_rollback == 0);
assert(m_ev.m_size_cachepressure == 0);
assert(read_partitioned_counter(m_ev.m_size_leaf) == 0);
assert(read_partitioned_counter(m_ev.m_size_nonleaf) == 0);
assert(read_partitioned_counter(m_ev.m_size_rollback) == 0);
assert(read_partitioned_counter(m_ev.m_size_cachepressure) == 0);
assert(m_ev.m_size_evicting == 0);
m_ev.add_to_size_current(3);
......@@ -105,16 +105,16 @@ void evictor_unit_test::verify_ev_counts() {
m_ev.add_pair_attr(attr);
assert(m_ev.m_size_current == 1);
assert(m_ev.m_size_nonleaf == 2);
assert(m_ev.m_size_leaf == 3);
assert(m_ev.m_size_rollback == 4);
assert(m_ev.m_size_cachepressure == 5);
assert(read_partitioned_counter(m_ev.m_size_nonleaf) == 2);
assert(read_partitioned_counter(m_ev.m_size_leaf) == 3);
assert(read_partitioned_counter(m_ev.m_size_rollback) == 4);
assert(read_partitioned_counter(m_ev.m_size_cachepressure) == 5);
m_ev.remove_pair_attr(attr);
assert(m_ev.m_size_current == 0);
assert(m_ev.m_size_leaf == 0);
assert(m_ev.m_size_nonleaf == 0);
assert(m_ev.m_size_rollback == 0);
assert(m_ev.m_size_cachepressure == 0);
assert(read_partitioned_counter(m_ev.m_size_leaf) == 0);
assert(read_partitioned_counter(m_ev.m_size_nonleaf) == 0);
assert(read_partitioned_counter(m_ev.m_size_rollback) == 0);
assert(read_partitioned_counter(m_ev.m_size_cachepressure) == 0);
PAIR_ATTR other_attr = {
.size = 2,
......@@ -126,10 +126,10 @@ void evictor_unit_test::verify_ev_counts() {
};
m_ev.change_pair_attr(attr, other_attr);
assert(m_ev.m_size_current == 1);
assert(m_ev.m_size_leaf == 1);
assert(m_ev.m_size_nonleaf == 1);
assert(m_ev.m_size_rollback == 1);
assert(m_ev.m_size_cachepressure == 1);
assert(read_partitioned_counter(m_ev.m_size_leaf) == 1);
assert(read_partitioned_counter(m_ev.m_size_nonleaf) == 1);
assert(read_partitioned_counter(m_ev.m_size_rollback) == 1);
assert(read_partitioned_counter(m_ev.m_size_cachepressure) == 1);
m_ev.destroy();
this->verify_ev_destroy();
......
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