[FEAT MERGE] implement of log disk writing throttling
This commit is contained in:
@ -33,3 +33,4 @@ ob_unittest(test_log_dir_match)
|
||||
ob_unittest(test_server_log_block_mgr)
|
||||
log_unittest(test_role_change_handler)
|
||||
log_unittest(test_log_mode_mgr)
|
||||
ob_unittest(test_palf_throttling)
|
||||
|
@ -302,7 +302,7 @@ public:
|
||||
const int64_t &prev_log_proposal_id,
|
||||
const LSN &prev_lsn,
|
||||
const LSN &curr_lsn,
|
||||
const LogWriteBuf &write_buf)
|
||||
const LogWriteBuf &write_buf) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(addr);
|
||||
@ -318,7 +318,7 @@ public:
|
||||
int submit_push_log_resp(
|
||||
const common::ObAddr &server,
|
||||
const int64_t &msg_proposal_id,
|
||||
const LSN &lsn)
|
||||
const LSN &lsn) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
@ -327,7 +327,7 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int submit_prepare_meta_req(const ObMemberList &member_list, const int64_t &log_proposal_id)
|
||||
int submit_prepare_meta_req(const ObMemberList &member_list, const int64_t &log_proposal_id) override
|
||||
{
|
||||
UNUSEDx(member_list, log_proposal_id);
|
||||
return OB_SUCCESS;
|
||||
@ -339,7 +339,8 @@ public:
|
||||
const bool vote_granted,
|
||||
const int64_t &log_proposal_id,
|
||||
const LSN &lsn,
|
||||
const LogModeMeta &mode_meta)
|
||||
const LSN &committed_end_lsn,
|
||||
const LogModeMeta &mode_meta) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
@ -347,6 +348,7 @@ public:
|
||||
UNUSED(vote_granted);
|
||||
UNUSED(log_proposal_id);
|
||||
UNUSED(lsn);
|
||||
UNUSED(committed_end_lsn);
|
||||
UNUSED(mode_meta);
|
||||
return ret;
|
||||
}
|
||||
@ -357,7 +359,7 @@ public:
|
||||
const int64_t &prev_log_proposal_id,
|
||||
const LSN &prev_lsn,
|
||||
const int64_t &prev_mode_pid,
|
||||
const LogConfigMeta &config_meta)
|
||||
const LogConfigMeta &config_meta) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(member_list);
|
||||
@ -375,7 +377,7 @@ public:
|
||||
const int64_t &prev_log_proposal_id,
|
||||
const LSN &prev_lsn,
|
||||
const int64_t &prev_mode_pid,
|
||||
const LogConfigMeta &config_meta)
|
||||
const LogConfigMeta &config_meta) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(member_list);
|
||||
@ -393,7 +395,7 @@ public:
|
||||
const int64_t &prev_log_proposal_id,
|
||||
const LSN &prev_lsn,
|
||||
const int64_t &prev_mode_pid,
|
||||
const LogConfigMeta &config_meta)
|
||||
const LogConfigMeta &config_meta) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(member_list);
|
||||
@ -408,7 +410,7 @@ public:
|
||||
int submit_change_config_meta_resp(
|
||||
const common::ObAddr &server,
|
||||
const int64_t msg_proposal_id,
|
||||
const LogConfigVersion &config_version)
|
||||
const LogConfigVersion &config_version) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
@ -421,7 +423,7 @@ public:
|
||||
const common::ObMemberList &member_list,
|
||||
const int64_t &msg_proposal_id,
|
||||
const bool is_applied_mode_meta,
|
||||
const LogModeMeta &mode_meta)
|
||||
const LogModeMeta &mode_meta) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(member_list);
|
||||
@ -433,7 +435,7 @@ public:
|
||||
|
||||
int submit_change_mode_meta_resp(
|
||||
const common::ObAddr &server,
|
||||
const int64_t &msg_proposal_id)
|
||||
const int64_t &msg_proposal_id) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
@ -444,13 +446,15 @@ public:
|
||||
int submit_config_change_pre_check_req(
|
||||
const common::ObAddr &server,
|
||||
const LogConfigVersion &config_version,
|
||||
const bool need_purge_throttling,
|
||||
const int64_t timeout_ns,
|
||||
LogGetMCStResp &resp)
|
||||
LogGetMCStResp &resp) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
UNUSED(config_version);
|
||||
UNUSED(timeout_ns);
|
||||
UNUSED(need_purge_throttling);
|
||||
resp.is_normal_replica_ = true;
|
||||
resp.need_update_config_meta_ = false;
|
||||
resp.max_flushed_end_lsn_ = LSN(PALF_INITIAL_LSN_VAL);
|
||||
@ -481,7 +485,8 @@ public:
|
||||
|
||||
int submit_notify_rebuild_req(
|
||||
const ObAddr &server,
|
||||
const LSN &base_lsn)
|
||||
const LSN &base_lsn,
|
||||
const LogInfo &base_prev_log_info) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
@ -491,7 +496,7 @@ public:
|
||||
|
||||
int submit_register_parent_req(const common::ObAddr &server,
|
||||
const LogLearner &child_itself,
|
||||
const bool is_to_leader)
|
||||
const bool is_to_leader) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
@ -502,7 +507,7 @@ public:
|
||||
int submit_register_parent_resp(const common::ObAddr &server,
|
||||
const LogLearner &parent_itself,
|
||||
const LogCandidateList &candidate_list,
|
||||
const RegisterReturn reg_ret)
|
||||
const RegisterReturn reg_ret) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
@ -511,21 +516,21 @@ public:
|
||||
reg_ret_ = reg_ret;
|
||||
return ret;
|
||||
}
|
||||
int submit_retire_parent_req(const common::ObAddr &server, const LogLearner &child_itself)
|
||||
int submit_retire_parent_req(const common::ObAddr &server, const LogLearner &child_itself) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
UNUSED(child_itself);
|
||||
return ret;
|
||||
}
|
||||
int submit_retire_child_req(const common::ObAddr &server, const LogLearner &parent_itself)
|
||||
int submit_retire_child_req(const common::ObAddr &server, const LogLearner &parent_itself) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
UNUSED(parent_itself);
|
||||
return ret;
|
||||
}
|
||||
int submit_learner_keepalive_req(const common::ObAddr &server, const LogLearner &sender_itself)
|
||||
int submit_learner_keepalive_req(const common::ObAddr &server, const LogLearner &sender_itself) override
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(server);
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
log_meta_.log_snapshot_meta_.base_lsn_ = LSN(5 * PALF_BLOCK_SIZE);
|
||||
const int64_t new_palf_epoch = ATOMIC_AAF(&palf_epoch_, 1);
|
||||
if (OB_FAIL(log_engine_.init(palf_id, log_dir, log_meta_, &allocator_, &log_block_pool_, \
|
||||
&log_rpc_, &log_io_worker_, new_palf_epoch))) {
|
||||
&log_rpc_, &log_io_worker_wrapper_, new_palf_epoch))) {
|
||||
PALF_LOG(WARN, "LogEngine init failed", K(ret));
|
||||
}
|
||||
start_lsn_ = base_lsn;
|
||||
@ -93,7 +93,7 @@ public:
|
||||
// log_engine_.destroy();
|
||||
LogGroupEntryHeader entry_header;
|
||||
const int64_t new_palf_epoch = ATOMIC_AAF(&palf_epoch_, 1);
|
||||
ret = log_engine_.load(palf_id, log_dir, &allocator_, &log_block_pool_, &log_rpc_, &log_io_worker_, \
|
||||
ret = log_engine_.load(palf_id, log_dir, &allocator_, &log_block_pool_, &log_rpc_, &log_io_worker_wrapper_, \
|
||||
entry_header, new_palf_epoch);
|
||||
block_id_t min_block_id = LOG_INVALID_BLOCK_ID;
|
||||
block_id_t max_block_id = LOG_INVALID_BLOCK_ID;
|
||||
@ -250,7 +250,7 @@ private:
|
||||
LogMeta log_meta_;
|
||||
LogEngine log_engine_;
|
||||
LogRpc log_rpc_;
|
||||
LogIOWorker log_io_worker_;
|
||||
LogIOWorker log_io_worker_wrapper_;
|
||||
LSN start_lsn_;
|
||||
LSN curr_lsn_;
|
||||
DummyBlockPool log_block_pool_;
|
||||
|
428
unittest/logservice/test_palf_throttling.cpp
Normal file
428
unittest/logservice/test_palf_throttling.cpp
Normal file
@ -0,0 +1,428 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <pthread.h>
|
||||
|
||||
#define private public
|
||||
#include "logservice/palf/palf_env_impl.h"
|
||||
#include "logservice/palf/log_io_worker.h"
|
||||
#undef private
|
||||
#include "share/rc/ob_tenant_base.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace common;
|
||||
using namespace share;
|
||||
using namespace palf;
|
||||
|
||||
namespace unittest
|
||||
{
|
||||
|
||||
class TestPalfThrottling : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
TestPalfThrottling();
|
||||
virtual ~TestPalfThrottling();
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
protected:
|
||||
};
|
||||
|
||||
TestPalfThrottling::TestPalfThrottling() {}
|
||||
|
||||
TestPalfThrottling::~TestPalfThrottling()
|
||||
{
|
||||
}
|
||||
|
||||
void TestPalfThrottling::SetUp()
|
||||
{
|
||||
//ObMallocAllocator::get_instance()->create_and_add_tenant_allocator(1001);
|
||||
// init MTL
|
||||
//ObTenantBase tbase(1001);
|
||||
//ObTenantEnv::set_tenant(&tbase);
|
||||
}
|
||||
|
||||
void TestPalfThrottling::TearDown()
|
||||
{
|
||||
PALF_LOG(INFO, "TestPalfThrottling has TearDown");
|
||||
//ObMallocAllocator::get_instance()->recycle_tenant_allocator(1001);
|
||||
}
|
||||
|
||||
TEST(TestPalfThrottling, test_palf_options)
|
||||
{
|
||||
char buf[64] = {0};
|
||||
memset(buf, 0, 64);
|
||||
int64_t checksum = common::ob_crc64(buf, 64);
|
||||
PALF_LOG(INFO, "checksum", K(checksum));
|
||||
//test PalfDiskOptionsWrapper
|
||||
PalfDiskOptionsWrapper wrapper;
|
||||
ASSERT_EQ(false, wrapper.need_throttling());
|
||||
int64_t total_disk_size = 1024 * 1024 * 1024L;
|
||||
int64_t utilization_limit_threshold = 95;
|
||||
int64_t throttling_percentage = 60;
|
||||
wrapper.disk_opts_for_stopping_writing_.log_disk_throttling_percentage_ = throttling_percentage;
|
||||
wrapper.disk_opts_for_stopping_writing_.log_disk_usage_limit_size_ = total_disk_size;
|
||||
wrapper.disk_opts_for_stopping_writing_.log_disk_utilization_threshold_ = 80;
|
||||
wrapper.disk_opts_for_stopping_writing_.log_disk_utilization_limit_threshold_ = utilization_limit_threshold;
|
||||
int64_t unrecyclable_size = 0;
|
||||
wrapper.set_cur_unrecyclable_log_disk_size(unrecyclable_size);
|
||||
ASSERT_EQ(false, wrapper.need_throttling());
|
||||
unrecyclable_size = total_disk_size * 70 /100;
|
||||
wrapper.set_cur_unrecyclable_log_disk_size(unrecyclable_size);
|
||||
ASSERT_EQ(true, wrapper.need_throttling());
|
||||
//test PalfThrottleOptions
|
||||
PalfThrottleOptions throttling_options;
|
||||
ASSERT_EQ(false, throttling_options.is_valid());
|
||||
ASSERT_EQ(false, throttling_options.need_throttling());
|
||||
ASSERT_EQ(0, throttling_options.get_available_size_after_limit());
|
||||
wrapper.get_throttling_options(throttling_options);
|
||||
ASSERT_EQ(true, throttling_options.is_valid());
|
||||
ASSERT_EQ(throttling_options.total_disk_space_, total_disk_size);
|
||||
ASSERT_EQ(throttling_options.stopping_writing_percentage_, utilization_limit_threshold);
|
||||
ASSERT_EQ(throttling_options.trigger_percentage_, throttling_percentage);
|
||||
ASSERT_EQ(throttling_options.unrecyclable_disk_space_, unrecyclable_size);
|
||||
ASSERT_EQ(true, throttling_options.need_throttling());
|
||||
ASSERT_EQ(total_disk_size * (utilization_limit_threshold - throttling_percentage)/100, throttling_options.get_available_size_after_limit());
|
||||
}
|
||||
|
||||
TEST(TestPalfThrottling, test_throttling_stat)
|
||||
{
|
||||
LogThrottlingStat stat;
|
||||
ASSERT_EQ(false, stat.has_ever_throttled());
|
||||
stat.start_throttling();
|
||||
ASSERT_EQ(true, stat.has_ever_throttled());
|
||||
stat.after_throttling(0, 1024);
|
||||
stat.after_throttling(100, 1024);
|
||||
stat.after_throttling(200, 1024);
|
||||
stat.after_throttling(0, 1024);
|
||||
stat.stop_throttling();
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP != stat.start_ts_);
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP != stat.stop_ts_);
|
||||
ASSERT_EQ(2048, stat.total_skipped_size_);
|
||||
ASSERT_EQ(2, stat.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(2048, stat.total_throttling_size_);
|
||||
ASSERT_EQ(2, stat.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(300, stat.total_throttling_interval_);
|
||||
ASSERT_EQ(200, stat.max_throttling_interval_);
|
||||
stat.start_throttling();
|
||||
ASSERT_EQ(0, stat.total_skipped_size_);
|
||||
ASSERT_EQ(0, stat.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(0, stat.total_throttling_size_);
|
||||
ASSERT_EQ(0, stat.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(0, stat.total_throttling_interval_);
|
||||
ASSERT_EQ(0, stat.max_throttling_interval_);
|
||||
}
|
||||
|
||||
TEST(TestPalfThrottling, test_log_write_throttle)
|
||||
{
|
||||
int64_t total_disk_size = 1024 * 1024 * 1024L;
|
||||
int64_t utilization_limit_threshold = 95;
|
||||
int64_t throttling_percentage = 60;
|
||||
PalfEnvImpl palf_env_impl;
|
||||
palf_env_impl.is_inited_ = true;
|
||||
palf_env_impl.disk_options_wrapper_.disk_opts_for_stopping_writing_.log_disk_throttling_percentage_ = throttling_percentage;
|
||||
palf_env_impl.disk_options_wrapper_.disk_opts_for_stopping_writing_.log_disk_usage_limit_size_ = total_disk_size;
|
||||
palf_env_impl.disk_options_wrapper_.disk_opts_for_stopping_writing_.log_disk_utilization_threshold_ = 80;
|
||||
palf_env_impl.disk_options_wrapper_.disk_opts_for_stopping_writing_.log_disk_utilization_limit_threshold_ = utilization_limit_threshold;
|
||||
int64_t unrecyclable_size = 0;
|
||||
palf_env_impl.disk_options_wrapper_.set_cur_unrecyclable_log_disk_size(unrecyclable_size);
|
||||
PalfThrottleOptions throttle_options;
|
||||
palf_env_impl.disk_options_wrapper_.get_throttling_options(throttle_options);
|
||||
|
||||
LogWritingThrottle throttle;
|
||||
ASSERT_EQ(false, throttle.need_throttling_());
|
||||
ASSERT_EQ(false, throttle.need_writing_throttling_notified());
|
||||
throttle.notify_need_writing_throttling(true);
|
||||
ASSERT_EQ(true, throttle.need_writing_throttling_notified());
|
||||
|
||||
throttle.notify_need_writing_throttling(false);
|
||||
ASSERT_EQ(false, throttle.need_writing_throttling_notified());
|
||||
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, throttle.after_append_log(-1, 0));
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, throttle.after_append_log(0, -1));
|
||||
|
||||
//test throttling only after notified
|
||||
PALF_LOG(INFO, "case 1: test no need throttling while notify_need_writing_throttling is false");
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
PalfThrottleOptions invalid_throttle_options;
|
||||
ASSERT_EQ(invalid_throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP != throttle.last_update_ts_);
|
||||
ASSERT_EQ(false, throttle.need_writing_throttling_notified_);
|
||||
|
||||
// test update interval 500ms
|
||||
PALF_LOG(INFO, "case 2: test update interval");
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(invalid_throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP != throttle.last_update_ts_);
|
||||
ASSERT_EQ(false, throttle.need_writing_throttling_notified_);
|
||||
|
||||
//test no need throttling after update
|
||||
PALF_LOG(INFO, "case 3: test no need throttling while unrecyclable_log_disk_size is no more than trigger_size");
|
||||
usleep(LogWritingThrottle::UPDATE_INTERVAL_US);
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.notify_need_writing_throttling(true);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(false, throttle.need_throttling_());
|
||||
ASSERT_EQ(false, throttle.stat_.has_ever_throttled());
|
||||
|
||||
|
||||
PALF_LOG(INFO, "case 4: test no need throttling while trigger percentage is 100", K(throttle));
|
||||
unrecyclable_size = total_disk_size * 70 / 100;
|
||||
palf_env_impl.disk_options_wrapper_.set_cur_unrecyclable_log_disk_size(unrecyclable_size);
|
||||
palf_env_impl.disk_options_wrapper_.disk_opts_for_stopping_writing_.log_disk_throttling_percentage_ = 100;
|
||||
usleep(LogWritingThrottle::UPDATE_INTERVAL_US);
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
palf_env_impl.disk_options_wrapper_.get_throttling_options(throttle_options);
|
||||
ASSERT_EQ(false, throttle.need_throttling_());
|
||||
ASSERT_EQ(false, throttle.stat_.has_ever_throttled());
|
||||
|
||||
//test need throttling after update
|
||||
PALF_LOG(INFO, "case 4: test need throttling", K(throttle));
|
||||
palf_env_impl.disk_options_wrapper_.disk_opts_for_stopping_writing_.log_disk_throttling_percentage_ = throttling_percentage;
|
||||
unrecyclable_size = total_disk_size * 70 / 100;
|
||||
palf_env_impl.disk_options_wrapper_.set_cur_unrecyclable_log_disk_size(unrecyclable_size);
|
||||
usleep(LogWritingThrottle::UPDATE_INTERVAL_US);
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
palf_env_impl.disk_options_wrapper_.get_throttling_options(throttle_options);
|
||||
ASSERT_EQ(throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(true, throttle.need_throttling_());
|
||||
ASSERT_EQ(true, throttle.stat_.has_ever_throttled());
|
||||
ASSERT_EQ(1024, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(1, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_size_);
|
||||
throttle.after_append_log(1024, 0);
|
||||
ASSERT_EQ(1024, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(0, throttle.submitted_seq_);
|
||||
ASSERT_EQ(0, throttle.handled_seq_);
|
||||
|
||||
//test no need throttling with flush meta task in queue
|
||||
//.1 flush log task
|
||||
PALF_LOG(INFO, "case 5: test no need throttling while flush meta task ", K(throttle));
|
||||
throttle.inc_and_fetch_submitted_seq();
|
||||
throttle.inc_and_fetch_submitted_seq();
|
||||
throttle.inc_and_fetch_submitted_seq();
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(false, throttle.need_throttling_());
|
||||
ASSERT_EQ(1024, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(1, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(1, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(1024, throttle.stat_.total_skipped_size_);
|
||||
throttle.after_append_log(1024, 0);
|
||||
ASSERT_EQ(2048, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
ASSERT_EQ(0, throttle.handled_seq_);
|
||||
|
||||
//.2 flush meta task
|
||||
PALF_LOG(INFO, "case 6: test no need throttling and flush meta task ", K(throttle));
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(true, throttle.need_throttling_with_options_());
|
||||
ASSERT_EQ(false, throttle.need_throttling_());
|
||||
ASSERT_EQ(1024, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(1, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(2, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(2048, throttle.stat_.total_skipped_size_);
|
||||
throttle.after_append_log(1024, 1);
|
||||
ASSERT_EQ(3072, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
ASSERT_EQ(1, throttle.handled_seq_);
|
||||
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(true, throttle.need_throttling_with_options_());
|
||||
ASSERT_EQ(false, throttle.need_throttling_());
|
||||
ASSERT_EQ(1024, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(1, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(3, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(3072, throttle.stat_.total_skipped_size_);
|
||||
throttle.after_append_log(1024, 3);
|
||||
ASSERT_EQ(4096, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
ASSERT_EQ(3, throttle.handled_seq_);
|
||||
|
||||
PALF_LOG(INFO, "case 7: need throttling after all flush meta task handled", K(throttle));
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(true, throttle.decay_factor_ > 0.0);
|
||||
ASSERT_EQ(true, throttle.need_throttling_());
|
||||
ASSERT_EQ(2048, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(2, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(3, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(3072, throttle.stat_.total_skipped_size_);
|
||||
throttle.after_append_log(1024, 3);
|
||||
ASSERT_EQ(5120, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
ASSERT_EQ(3, throttle.handled_seq_);
|
||||
|
||||
//test notify_need_writing_throttling(false) changed
|
||||
PALF_LOG(INFO, "case 8: no need to throttle after notify_need_throttling(false)", K(throttle));
|
||||
usleep(LogWritingThrottle::UPDATE_INTERVAL_US);
|
||||
throttle.notify_need_writing_throttling(false);
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(invalid_throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(false, throttle.need_throttling_with_options_());
|
||||
ASSERT_EQ(false, throttle.need_throttling_());
|
||||
ASSERT_EQ(2048, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(2, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(3, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(3072, throttle.stat_.total_skipped_size_);
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP != throttle.stat_.stop_ts_);
|
||||
throttle.after_append_log(1024, 0);
|
||||
ASSERT_EQ(1024, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(0, throttle.decay_factor_);
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
ASSERT_EQ(3, throttle.handled_seq_);
|
||||
|
||||
//test need write throttling again
|
||||
PALF_LOG(INFO, "case 9: need to throttle after notify_need_throttling(true)", K(throttle));
|
||||
usleep(LogWritingThrottle::UPDATE_INTERVAL_US);
|
||||
throttle.notify_need_writing_throttling(true);
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(true, throttle.need_throttling_with_options_());
|
||||
ASSERT_EQ(true, throttle.need_throttling_());
|
||||
ASSERT_EQ(throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(true, throttle.decay_factor_ > 0.0);
|
||||
ASSERT_EQ(1024, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(1, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_size_);
|
||||
ASSERT_EQ(true, throttle.stat_.total_throttling_interval_ > 0);
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP == throttle.stat_.stop_ts_);
|
||||
throttle.after_append_log(1024, 0);
|
||||
ASSERT_EQ(1024, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
ASSERT_EQ(3, throttle.handled_seq_);
|
||||
|
||||
double old_decay_factor = throttle.decay_factor_;
|
||||
//
|
||||
PALF_LOG(INFO, "case 10: test recalculate decay_factor", K(throttle));
|
||||
usleep(LogWritingThrottle::UPDATE_INTERVAL_US);
|
||||
palf_env_impl.disk_options_wrapper_.disk_opts_for_stopping_writing_.log_disk_throttling_percentage_ = 55;
|
||||
palf_env_impl.get_throttling_options(throttle_options);
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(true, throttle.need_throttling_with_options_());
|
||||
ASSERT_EQ(true, throttle.need_throttling_());
|
||||
ASSERT_EQ(throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(true, throttle.decay_factor_ > 0.0);
|
||||
ASSERT_EQ(true, throttle.decay_factor_ != old_decay_factor);
|
||||
ASSERT_EQ(2048, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(2, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_size_);
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP == throttle.stat_.stop_ts_);
|
||||
throttle.after_append_log(1024, 0);
|
||||
ASSERT_EQ(2048, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
ASSERT_EQ(3, throttle.handled_seq_);
|
||||
|
||||
//test reset appended_log_size_cur_round_
|
||||
PALF_LOG(INFO, "case 11: test reset appended_log_size_cur_round_ after unrecyclable_size changes", K(throttle));
|
||||
old_decay_factor = throttle.decay_factor_;
|
||||
usleep(LogWritingThrottle::UPDATE_INTERVAL_US);
|
||||
unrecyclable_size = total_disk_size * 65/100;
|
||||
palf_env_impl.disk_options_wrapper_.set_cur_unrecyclable_log_disk_size(unrecyclable_size);
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(true, throttle.need_throttling_with_options_());
|
||||
ASSERT_EQ(true, throttle.need_throttling_());
|
||||
palf_env_impl.get_throttling_options(throttle_options);
|
||||
ASSERT_EQ(throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(true, throttle.decay_factor_ > 0.0);
|
||||
ASSERT_EQ(true, throttle.decay_factor_ == old_decay_factor);
|
||||
ASSERT_EQ(3072, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(3, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_size_);
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP != throttle.stat_.start_ts_);
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP == throttle.stat_.stop_ts_);
|
||||
throttle.after_append_log(1024, 0);
|
||||
ASSERT_EQ(1024, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
ASSERT_EQ(3, throttle.handled_seq_);
|
||||
ASSERT_EQ(OB_ERR_UNEXPECTED, throttle.after_append_log(0, 4));
|
||||
ASSERT_EQ(OB_ERR_UNEXPECTED, throttle.after_append_log(0, 2));
|
||||
|
||||
//test stop write throttling when trigger percentage changed
|
||||
PALF_LOG(INFO, "case 12: test stop write throttling when trigger percentage changed", K(throttle));
|
||||
usleep(LogWritingThrottle::UPDATE_INTERVAL_US);
|
||||
palf_env_impl.disk_options_wrapper_.disk_opts_for_stopping_writing_.log_disk_throttling_percentage_ = 80;
|
||||
palf_env_impl.get_throttling_options(throttle_options);
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(false, throttle.need_throttling_with_options_());
|
||||
ASSERT_EQ(false, throttle.need_throttling_());
|
||||
ASSERT_EQ(invalid_throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(0, throttle.decay_factor_);
|
||||
ASSERT_EQ(3072, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(3, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_size_);
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP != throttle.stat_.stop_ts_);
|
||||
ASSERT_EQ(0, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
ASSERT_EQ(3, throttle.handled_seq_);
|
||||
|
||||
PALF_LOG(INFO, "case 12: test stop writing throttling when unrecyclable size fallbacks", K(throttle));
|
||||
usleep(LogWritingThrottle::UPDATE_INTERVAL_US);
|
||||
palf_env_impl.disk_options_wrapper_.disk_opts_for_stopping_writing_.log_disk_throttling_percentage_ = 60;
|
||||
throttle.notify_need_writing_throttling(true);
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(true, throttle.need_throttling_with_options_());
|
||||
ASSERT_EQ(true, throttle.need_throttling_());
|
||||
palf_env_impl.get_throttling_options(throttle_options);
|
||||
ASSERT_EQ(throttle_options, throttle.throttling_options_);
|
||||
ASSERT_EQ(true, throttle.decay_factor_ > 0.0);
|
||||
ASSERT_EQ(1024, throttle.stat_.total_throttling_size_);
|
||||
ASSERT_EQ(1, throttle.stat_.total_throttling_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_task_cnt_);
|
||||
ASSERT_EQ(0, throttle.stat_.total_skipped_size_);
|
||||
ASSERT_EQ(true, throttle.stat_.total_throttling_interval_ > 0);
|
||||
ASSERT_EQ(true, OB_INVALID_TIMESTAMP == throttle.stat_.stop_ts_);
|
||||
throttle.after_append_log(1024, 0);
|
||||
ASSERT_EQ(1024, throttle.appended_log_size_cur_round_);
|
||||
ASSERT_EQ(3, throttle.submitted_seq_);
|
||||
ASSERT_EQ(3, throttle.handled_seq_);
|
||||
|
||||
usleep(LogWritingThrottle::UPDATE_INTERVAL_US);
|
||||
unrecyclable_size = total_disk_size * 45/100;
|
||||
palf_env_impl.disk_options_wrapper_.set_cur_unrecyclable_log_disk_size(unrecyclable_size);
|
||||
throttle.update_throttling_options(&palf_env_impl);
|
||||
throttle.throttling(1024, &palf_env_impl);
|
||||
ASSERT_EQ(false, throttle.need_throttling_with_options_());
|
||||
|
||||
}
|
||||
|
||||
} // END of unittest
|
||||
} // end of oceanbase
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
system("rm -rf ./test_palf_throttling.log*");
|
||||
OB_LOGGER.set_file_name("test_palf_throttling.log", true);
|
||||
OB_LOGGER.set_log_level("INFO");
|
||||
PALF_LOG(INFO, "begin unittest::test_palf_throttling");
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
@ -64,6 +64,7 @@ ob_unittest(test_geo_srs)
|
||||
ob_unittest(test_geo_srs_parser)
|
||||
ob_unittest(test_geo_func_difference)
|
||||
ob_unittest(test_geo_func_union)
|
||||
ob_unittest(test_throttling_utils)
|
||||
|
||||
ob_unittest(test_json_base)
|
||||
ob_unittest(test_json_bin)
|
||||
|
235
unittest/share/test_throttling_utils.cpp
Normal file
235
unittest/share/test_throttling_utils.cpp
Normal file
@ -0,0 +1,235 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#define USING_LOG_PREFIX SHARE
|
||||
#include <gtest/gtest.h>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "lib/ob_define.h"
|
||||
#include "lib/utility/ob_print_utils.h" // Print*
|
||||
#include "logservice/palf/log_define.h"
|
||||
#include "share/ob_throttling_utils.h"
|
||||
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace share;
|
||||
using namespace common;
|
||||
namespace unittest
|
||||
{
|
||||
|
||||
class TestThrottlingUtils : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
TestThrottlingUtils();
|
||||
virtual ~TestThrottlingUtils();
|
||||
virtual void test_get_throttling_interval_size(
|
||||
const int64_t chunk_size, const int64_t request_size,
|
||||
const int64_t trigger_limit, const int64_t stop_limit,
|
||||
const int64_t overused_size, const double decay_factor);
|
||||
virtual void test_get_throttling_interval_percentage(
|
||||
const int64_t chunk_size, const int64_t request_size,
|
||||
const int64_t trigger_limit, const int64_t stop_limit,
|
||||
const int64_t overused_percentage, const double decay_factor);
|
||||
virtual void test_get_throttling_interval(
|
||||
const int64_t chunk_size, const int64_t request_size,
|
||||
const int64_t trigger_limit, const int64_t stop_limit,
|
||||
const double decay_factor);
|
||||
virtual void SetUp();
|
||||
virtual void TearDown();
|
||||
protected:
|
||||
};
|
||||
|
||||
TestThrottlingUtils::TestThrottlingUtils() {}
|
||||
|
||||
TestThrottlingUtils::~TestThrottlingUtils()
|
||||
{
|
||||
}
|
||||
|
||||
void TestThrottlingUtils::test_get_throttling_interval_size(
|
||||
const int64_t chunk_size, const int64_t request_size,
|
||||
const int64_t trigger_limit, const int64_t stop_limit,
|
||||
const int64_t overused_size, const double decay_factor)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const int64_t GB = 1024 * 1024 * 1024L;
|
||||
const int64_t MB = 1024 * 1024L;
|
||||
const int64_t cur_hold = trigger_limit + overused_size;
|
||||
int64_t interval_us = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, ObThrottlingUtils::get_throttling_interval(chunk_size, request_size, trigger_limit,
|
||||
cur_hold, decay_factor, interval_us));
|
||||
LOG_INFO("get_interval", K(interval_us), K(request_size), "overused_size(MB)", overused_size/MB, "cur_hold(GB)", cur_hold /GB, "trigger_limit(GB)",
|
||||
trigger_limit / GB, "stop_limit", stop_limit/GB, K(interval_us));
|
||||
}
|
||||
|
||||
void TestThrottlingUtils::test_get_throttling_interval_percentage(
|
||||
const int64_t chunk_size, const int64_t request_size,
|
||||
const int64_t trigger_limit, const int64_t stop_limit,
|
||||
const int64_t overused_percentage, const double decay_factor)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const int64_t GB = 1024 * 1024 * 1024L;
|
||||
const int64_t MB = 1024 * 1024L;
|
||||
const int64_t overused_size = (stop_limit-trigger_limit) * overused_percentage / 100;
|
||||
const int64_t cur_hold = trigger_limit + overused_size;
|
||||
int64_t interval_us = 0;
|
||||
ASSERT_EQ(OB_SUCCESS, ObThrottlingUtils::get_throttling_interval(chunk_size, request_size, trigger_limit, cur_hold, decay_factor, interval_us));
|
||||
LOG_INFO("get_interval", K(interval_us), K(request_size), K(overused_percentage), "cur_hold(GB)", cur_hold / GB, "trigger_limit(GB)",
|
||||
trigger_limit / GB, "stop_limit", stop_limit/GB);
|
||||
}
|
||||
|
||||
void TestThrottlingUtils::test_get_throttling_interval(
|
||||
const int64_t chunk_size, const int64_t request_size,
|
||||
const int64_t trigger_limit, const int64_t stop_limit,
|
||||
const double decay_factor)
|
||||
{
|
||||
const int64_t GB = 1024 * 1024 * 1024L;
|
||||
const int64_t MB = 1024 * 1024L;
|
||||
LOG_INFO("BEGIN TEST big round", K(chunk_size), K(request_size), K(trigger_limit), K(stop_limit), K(decay_factor));
|
||||
int64_t interval_us = 0;
|
||||
int64_t overused_size = 1 * MB;
|
||||
test_get_throttling_interval_size(chunk_size, request_size, trigger_limit, stop_limit, overused_size, decay_factor);
|
||||
|
||||
overused_size = 10 * MB;
|
||||
test_get_throttling_interval_size(chunk_size, request_size, trigger_limit, stop_limit, overused_size, decay_factor);
|
||||
|
||||
overused_size = 100 * MB;
|
||||
test_get_throttling_interval_size(chunk_size, request_size, trigger_limit, stop_limit, overused_size, decay_factor);
|
||||
|
||||
overused_size = 200 * MB;
|
||||
test_get_throttling_interval_size(chunk_size, request_size, trigger_limit, stop_limit, overused_size, decay_factor);
|
||||
|
||||
overused_size = 300 * MB;
|
||||
test_get_throttling_interval_size(chunk_size, request_size, trigger_limit, stop_limit, overused_size, decay_factor);
|
||||
|
||||
overused_size = 400 * MB;
|
||||
test_get_throttling_interval_size(chunk_size, request_size, trigger_limit, stop_limit, overused_size, decay_factor);
|
||||
|
||||
overused_size = 500 * MB;
|
||||
test_get_throttling_interval_size(chunk_size, request_size, trigger_limit, stop_limit, overused_size, decay_factor);
|
||||
|
||||
overused_size = 1 * GB;
|
||||
test_get_throttling_interval_size(chunk_size, request_size, trigger_limit, stop_limit, overused_size, decay_factor);
|
||||
|
||||
|
||||
int64_t overused_percentage = 1;
|
||||
test_get_throttling_interval_percentage(chunk_size, request_size, trigger_limit, stop_limit, overused_percentage, decay_factor);
|
||||
|
||||
overused_percentage = 5;
|
||||
test_get_throttling_interval_percentage(chunk_size, request_size, trigger_limit, stop_limit, overused_percentage, decay_factor);
|
||||
|
||||
for (overused_percentage = 10; overused_percentage < 100; overused_percentage += 10) {
|
||||
test_get_throttling_interval_percentage(chunk_size, request_size, trigger_limit,
|
||||
stop_limit, overused_percentage,
|
||||
decay_factor);
|
||||
}
|
||||
LOG_INFO("END TEST big round", K(chunk_size), K(request_size), K(trigger_limit), K(stop_limit), K(decay_factor));
|
||||
}
|
||||
|
||||
void TestThrottlingUtils::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void TestThrottlingUtils::TearDown()
|
||||
{
|
||||
LOG_INFO("TestThrottlingUtils has TearDown");
|
||||
//ObMallocAllocator::get_instance()->recycle_tenant_allocator(1001);
|
||||
}
|
||||
|
||||
TEST_F(TestThrottlingUtils, test_calc_decay_factor)
|
||||
{
|
||||
const int64_t GB = 1024 * 1024 * 1024L;
|
||||
const int64_t MB = 1024 * 1024L;
|
||||
int64_t available_size = 0;
|
||||
int64_t duration_us = 0;
|
||||
int64_t chunk_size = 0;
|
||||
double decay_factor = 0.0;
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, ObThrottlingUtils::calc_decay_factor(available_size, duration_us, chunk_size, decay_factor));
|
||||
available_size = 1 * GB;
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, ObThrottlingUtils::calc_decay_factor(available_size, duration_us, chunk_size, decay_factor));
|
||||
duration_us = 1800 * 1000 * 1000L;
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, ObThrottlingUtils::calc_decay_factor(available_size, duration_us, chunk_size, decay_factor));
|
||||
chunk_size = palf::MAX_LOG_BUFFER_SIZE;
|
||||
ASSERT_EQ(OB_SUCCESS, ObThrottlingUtils::calc_decay_factor(available_size, duration_us, chunk_size, decay_factor));
|
||||
//0.10934
|
||||
LOG_INFO("calc_decay_factor", K(chunk_size), K(duration_us), K(available_size), K(decay_factor));
|
||||
ASSERT_EQ(10933, static_cast<int64_t>(decay_factor * 100000.0));
|
||||
available_size = 10 * GB;
|
||||
|
||||
ASSERT_EQ(OB_SUCCESS, ObThrottlingUtils::calc_decay_factor(available_size, duration_us, chunk_size, decay_factor));
|
||||
LOG_INFO("calc_decay_factor", K(chunk_size), K(duration_us), K(available_size), K(decay_factor));
|
||||
ASSERT_EQ(109728, static_cast<int64_t>(decay_factor * 10000000000.0));
|
||||
available_size = 40 * GB;
|
||||
ASSERT_EQ(OB_SUCCESS, ObThrottlingUtils::calc_decay_factor(available_size, duration_us, chunk_size, decay_factor));
|
||||
LOG_INFO("calc_decay_factor", K(chunk_size), K(duration_us), K(available_size), K(decay_factor));
|
||||
ASSERT_EQ(42875, static_cast<int64_t>(decay_factor * 1000000000000.0));
|
||||
}
|
||||
|
||||
TEST_F(TestThrottlingUtils, test_get_throttling_interval_basic)
|
||||
{
|
||||
const int64_t KB = 1024L;
|
||||
const int64_t MB = 1024 * 1024L;
|
||||
const int64_t GB = 1024 * 1024 * 1024L;
|
||||
int64_t chunk_size = 0;
|
||||
int64_t request_size = 0;
|
||||
int64_t trigger_limit = 0;
|
||||
int64_t cur_hold = 0;
|
||||
double decay_factor = 0.0;
|
||||
|
||||
int64_t interval_us = 0;
|
||||
ASSERT_EQ(OB_INVALID_ARGUMENT, ObThrottlingUtils::get_throttling_interval(chunk_size, request_size, trigger_limit, cur_hold, decay_factor, interval_us));
|
||||
|
||||
chunk_size = palf::MAX_LOG_BUFFER_SIZE;
|
||||
request_size = 1 * MB;
|
||||
trigger_limit = 50 * GB;
|
||||
int64_t stop_limit = 95 * GB;
|
||||
cur_hold = 51 * GB;
|
||||
|
||||
int64_t available_size = 40 * GB;
|
||||
int64_t duration_us = 1800 * 1000 * 1000L;
|
||||
ASSERT_EQ(OB_SUCCESS, ObThrottlingUtils::calc_decay_factor(available_size, duration_us, chunk_size, decay_factor));
|
||||
request_size = 1 * KB;
|
||||
LOG_INFO("TEST REQUEST_SIZE", K(request_size));
|
||||
test_get_throttling_interval(chunk_size, request_size, trigger_limit, stop_limit, decay_factor);
|
||||
|
||||
request_size = 10 * KB;
|
||||
LOG_INFO("TEST REQUEST_SIZE", K(request_size));
|
||||
test_get_throttling_interval(chunk_size, request_size, trigger_limit, stop_limit, decay_factor);
|
||||
|
||||
request_size = 100 * KB;
|
||||
LOG_INFO("TEST REQUEST_SIZE", K(request_size));
|
||||
test_get_throttling_interval(chunk_size, request_size, trigger_limit, stop_limit, decay_factor);
|
||||
|
||||
request_size = 1 * MB;
|
||||
LOG_INFO("TEST REQUEST_SIZE", K(request_size));
|
||||
test_get_throttling_interval(chunk_size, request_size, trigger_limit, stop_limit, decay_factor);
|
||||
|
||||
request_size = palf::MAX_LOG_BUFFER_SIZE;
|
||||
LOG_INFO("TEST REQUEST_SIZE", K(request_size));
|
||||
test_get_throttling_interval(chunk_size, request_size, trigger_limit, stop_limit, decay_factor);
|
||||
|
||||
}
|
||||
|
||||
} // END of unittest
|
||||
} // end of oceanbase
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
system("rm -rf ./test_throttling_utils.log*");
|
||||
OB_LOGGER.set_file_name("test_throttling_utils.log", true);
|
||||
OB_LOGGER.set_log_level("INFO");
|
||||
LOG_INFO("begin unittest::test_throttling_utils");
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Reference in New Issue
Block a user