patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -25,17 +25,16 @@ using namespace oceanbase::lib;
using namespace oceanbase::common;
const int64_t update_cnt = 100000;
class TestSessionMultiThread : public CoKThread {
class TestSessionMultiThread: public Threads
{
public:
TestSessionMultiThread()
{}
virtual ~TestSessionMultiThread()
{}
TestSessionMultiThread() {}
virtual ~TestSessionMultiThread() {}
virtual void run(int64_t idx)
{
uint64_t session_id = (long)idx % 2 + 1;
ObSessionStatEstGuard session_guard(1, session_id, true /*is_multi_thread_plan*/);
ObDiagnoseSessionInfo* di = ObDiagnoseSessionInfo::get_local_diagnose_info();
ObDiagnoseSessionInfo *di = ObDiagnoseSessionInfo::get_local_diagnose_info();
ASSERT_TRUE(NULL != di);
for (int i = 0; i < update_cnt; i++) {
di->update_stat(ObStatEventIds::IO_READ_COUNT, 1);
@ -47,65 +46,61 @@ TEST(ObDICache, multithread)
{
bool stop = false;
int64_t round = 0;
cotesting::FlexPool pool;
pool.create(
[&stop] {
while (!stop) {
uint64_t begin_time = ::oceanbase::common::ObTimeUtility::current_time();
ObSEArray<std::pair<uint64_t, ObDISessionCollect*>, OB_MAX_SERVER_SESSION_CNT + 1> session_status;
ObDISessionCache::get_instance().get_all_diag_info(session_status);
uint64_t end_time = ::oceanbase::common::ObTimeUtility::current_time();
printf("session cnt: %ld, scan session time: %ld us\n", session_status.count(), (end_time - begin_time));
cotesting::FlexPool pool1([&stop]{
while (!stop) {
uint64_t begin_time = ::oceanbase::common::ObTimeUtility::current_time();
ObSEArray<std::pair<uint64_t, ObDISessionCollect*>, OB_MAX_SERVER_SESSION_CNT+1> session_status;
ObDISessionCache::get_instance().get_all_diag_info(session_status);
uint64_t end_time = ::oceanbase::common::ObTimeUtility::current_time();
printf("session cnt: %ld, scan session time: %ld us\n", session_status.count(), (end_time - begin_time));
sleep(1);
}
},
1)
.create(
[&stop, &round] {
ObSessionStatEstGuard guard(1, 1);
while (!stop) {
// uint32_t tenant_id = (uint32_t)rand.get(1+(uint64_t)arg*100, 100+(uint64_t)arg*100);
for (int64_t i = 0; i < 1000; ++i) {
EVENT_INC(REQUEST_ENQUEUE_COUNT);
}
sleep(1);
}
}, 1);
pool1.start(false);
cotesting::FlexPool pool2([&stop, &round]{
ObSessionStatEstGuard guard(1,1);
while (!stop) {
//uint32_t tenant_id = (uint32_t)rand.get(1+(uint64_t)arg*100, 100+(uint64_t)arg*100);
for (int64_t i = 0; i < 1000; ++i) {
EVENT_INC(REQUEST_ENQUEUE_COUNT);
}
ATOMIC_INC(&round);
}
},
1)
.start(false);
ATOMIC_INC(&round);
}
}, 1);
pool2.start(false);
int64_t qps = 0;
int64_t value = 0;
for (int64_t i = 0; i < 10; ++i) {
for (int64_t i = 0; i < 2; ++i) {
qps = round - value;
value = round;
printf("qps: %ld\n", qps);
sleep(1);
}
stop = true;
pool.wait();
pool1.wait();
pool2.wait();
}
TEST(ObDICache, session_multi_threads)
{
ObDISessionCollect* collect;
ObDISessionCollect *collect;
TestSessionMultiThread tester;
ObSEArray<std::pair<uint64_t, ObDISessionCollect*>, 10> session_status;
ObSEArray<std::pair<uint64_t, ObDISessionCollect *>, 10> session_status;
const int64_t th_cnt = 10;
tester.set_thread_count(th_cnt);
tester.start();
tester.wait();
ObDISessionCache::get_instance().get_the_diag_info(1, collect);
ASSERT_EQ(th_cnt * update_cnt / 2,
collect->base_value_.get_add_stat_stats().get(ObStatEventIds::IO_READ_COUNT)->stat_value_);
ASSERT_EQ(th_cnt * update_cnt / 2, collect->base_value_.get_add_stat_stats().get(ObStatEventIds::IO_READ_COUNT)->stat_value_);
ObDISessionCache::get_instance().get_all_diag_info(session_status);
ASSERT_EQ(2, session_status.count());
for (int i = 0; i < session_status.count(); i++) {
collect = session_status.at(i).second;
ASSERT_EQ(th_cnt * update_cnt / 2,
collect->base_value_.get_add_stat_stats().get(ObStatEventIds::IO_READ_COUNT)->stat_value_);
ASSERT_EQ(th_cnt * update_cnt / 2, collect->base_value_.get_add_stat_stats().get(ObStatEventIds::IO_READ_COUNT)->stat_value_);
}
}
@ -115,20 +110,18 @@ TEST(ObDICache, tenant)
ObDiagnoseTenantInfo diag_info;
bool stop = false;
cotesting::FlexPool pool(
[&stop] {
while (!stop) {
for (uint64_t i = 1; i < 100000; i++) {
ObSessionStatEstGuard guard(ObRandom::rand(1, 100), i);
EVENT_ADD(RPC_PACKET_IN, 1);
}
sleep(1);
}
},
4);
cotesting::FlexPool pool([&stop]{
while (!stop) {
for (uint64_t i = 1; i < 100000; i++) {
ObSessionStatEstGuard guard(ObRandom::rand(1, 100), i);
EVENT_ADD(RPC_PACKET_IN, 1);
}
sleep(1);
}
}, 4);
pool.start(false);
for (int64_t i = 0; i < 5; ++i) {
for (int64_t i = 0; i < 2; ++i) {
tenant_id = 1000 + ObRandom::rand(0, 100);
ObDIGlobalTenantCache::get_instance().get_the_diag_info(tenant_id, diag_info);
sleep(1);
@ -137,32 +130,34 @@ TEST(ObDICache, tenant)
pool.wait();
}
TEST(ObDISessionCache, multithread)
{
bool stop = false;
cotesting::FlexPool pool(
[&stop] {
while (!stop) {
for (uint64_t i = 1; i < 100000; i++) {
ObSessionStatEstGuard guard(1, i);
EVENT_ADD(RPC_PACKET_IN, 1);
}
sleep(1);
std::thread ths[4];
for (uint64_t i = 1; i < 4; i++) {
ths[i] = std::thread([&]() {
while (!stop) {
for (uint64_t i = 1; i < 100000; i++) {
ObSessionStatEstGuard guard(1,i);
EVENT_ADD(RPC_PACKET_IN, 1);
}
},
4);
sleep(1);
}});
}
pool.start(false);
sleep(5);
stop = true;
pool.wait();
for (uint64_t i = 1; i < 4; i++) {
ths[i].join();
}
common::ObArenaAllocator allocator;
common::ObSEArray<std::pair<uint64_t, common::ObDiagnoseTenantInfo*>, common::OB_MAX_SERVER_TENANT_CNT> tenant_dis;
ASSERT_EQ(OB_SUCCESS, common::ObDIGlobalTenantCache::get_instance().get_all_stat_event(allocator, tenant_dis));
int64_t count = 0;
for (int64_t i = 0; i < tenant_dis.count(); ++i) {
ObStatEventAddStat* stat = tenant_dis.at(i).second->get_add_stat_stats().get(ObStatEventIds::RPC_PACKET_IN);
ObStatEventAddStat *stat = tenant_dis.at(i).second->get_add_stat_stats().get(ObStatEventIds::RPC_PACKET_IN);
if (NULL != stat) {
count += stat->stat_value_;
}
@ -170,7 +165,7 @@ TEST(ObDISessionCache, multithread)
ASSERT_GT(count, 0);
}
int main(int argc, char** argv)
int main(int argc, char **argv)
{
oceanbase::common::ObLogger::get_logger().set_log_level("INFO");
testing::InitGoogleTest(&argc, argv);

View File

@ -17,24 +17,27 @@
#include "lib/lock/ob_spin_rwlock.h"
#include "lib/coro/testing.h"
namespace oceanbase {
namespace common {
#define TENANT_EVENT_GET(stat_no) \
({ \
int64_t ret = 0; \
oceanbase::common::ObDiagnoseTenantInfo* tenant_info = \
oceanbase::common::ObDiagnoseTenantInfo::get_local_diagnose_info(); \
if (NULL != tenant_info) { \
if (oceanbase::common::stat_no < oceanbase::common::ObStatEventIds::STAT_EVENT_ADD_END) { \
oceanbase::common::ObStatEventAddStat* stat = \
tenant_info->get_add_stat_stats().get(::oceanbase::common::stat_no); \
if (NULL != stat) { \
ret = stat->get_stat_value(); \
} \
} \
} \
ret; \
})
namespace oceanbase
{
namespace common
{
#define TENANT_EVENT_GET(stat_no) \
({ \
int64_t ret = 0; \
oceanbase::common::ObDiagnoseTenantInfo *tenant_info \
= oceanbase::common::ObDiagnoseTenantInfo::get_local_diagnose_info(); \
if (NULL != tenant_info) { \
if (oceanbase::common::stat_no < oceanbase::common::ObStatEventIds::STAT_EVENT_ADD_END) { \
oceanbase::common::ObStatEventAddStat *stat \
= tenant_info->get_add_stat_stats().get( \
::oceanbase::common::stat_no); \
if (NULL != stat) { \
ret = stat->get_stat_value(); \
} \
} \
} \
ret; \
})
TEST(ObDiagnoseSessionInfo, guard)
{
@ -61,50 +64,44 @@ TEST(ObDISessionCache, multithread)
{
ObDiagnoseSessionInfo info;
ObDiagnoseTenantInfo tenant_info;
ObWaitEventHistory& history = info.get_event_history();
for (uint64_t i = 0; i < 2; i++) {
ObWaitEventHistory &history = info.get_event_history();
for (uint64_t i = 0; i <2; i++) {
info.notify_wait_begin(ObWaitEventIds::PT_LOCATION_CACHE_LOCK_WAIT, 0, 0, 0, 0);
EXPECT_EQ(1, history.curr_pos_);
EXPECT_EQ(1, history.item_cnt_);
EXPECT_EQ(1, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::PT_LOCATION_CACHE_LOCK_WAIT,
history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(ObWaitEventIds::PT_LOCATION_CACHE_LOCK_WAIT, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(0, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
this_routine::usleep(1);
::usleep(1);
info.notify_wait_end(&tenant_info);
EXPECT_EQ(1, history.curr_pos_);
EXPECT_EQ(1, history.item_cnt_);
EXPECT_EQ(0, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::PT_LOCATION_CACHE_LOCK_WAIT,
history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(ObWaitEventIds::PT_LOCATION_CACHE_LOCK_WAIT, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(0, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
info.notify_wait_begin(ObWaitEventIds::MT_READ_LOCK_WAIT, 0, 0, 0, 0);
EXPECT_EQ(2, history.curr_pos_);
EXPECT_EQ(2, history.item_cnt_);
EXPECT_EQ(1, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT,
history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(0, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
info.notify_wait_begin(ObWaitEventIds::MT_READ_LOCK_WAIT, 0, 0, 0, 0);
EXPECT_EQ(3, history.curr_pos_);
EXPECT_EQ(3, history.item_cnt_);
EXPECT_EQ(2, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT,
history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(1, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
info.notify_wait_end(&tenant_info);
EXPECT_EQ(3, history.curr_pos_);
EXPECT_EQ(3, history.item_cnt_);
EXPECT_EQ(2, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT,
history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(0, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
info.notify_wait_begin(ObWaitEventIds::MT_READ_LOCK_WAIT, 0, 0, 0, 0);
EXPECT_EQ(4, history.curr_pos_);
EXPECT_EQ(4, history.item_cnt_);
EXPECT_EQ(3, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT,
history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(1, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
info.notify_wait_end(&tenant_info);
info.notify_wait_begin(ObWaitEventIds::MT_READ_LOCK_WAIT, 0, 0, 0, 0);
@ -114,54 +111,44 @@ TEST(ObDISessionCache, multithread)
EXPECT_EQ(7, history.curr_pos_);
EXPECT_EQ(7, history.item_cnt_);
EXPECT_EQ(6, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT,
history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(2, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
info.notify_wait_begin(ObWaitEventIds::MT_READ_LOCK_WAIT, 0, 0, 0, 0);
EXPECT_EQ(8, history.curr_pos_);
EXPECT_EQ(8, history.item_cnt_);
EXPECT_EQ(7, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT,
history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(3, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
info.notify_wait_end(&tenant_info);
info.notify_wait_end(&tenant_info);
EXPECT_EQ(8, history.curr_pos_);
EXPECT_EQ(8, history.item_cnt_);
EXPECT_EQ(7, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT,
history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(1, history.items_[(history.current_wait_ + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
info.notify_wait_end(&tenant_info);
if (1 == i) {
info.notify_wait_begin(ObWaitEventIds::PT_LOCATION_CACHE_LOCK_WAIT, 0, 0, 0, 0);
this_routine::usleep(1);
::usleep(1);
info.notify_wait_end(&tenant_info);
info.notify_wait_begin(ObWaitEventIds::PT_LOCATION_CACHE_LOCK_WAIT, 0, 0, 0, 0);
this_routine::usleep(1);
::usleep(1);
info.notify_wait_end(&tenant_info);
info.notify_wait_end(&tenant_info);
EXPECT_EQ(2, history.curr_pos_);
EXPECT_EQ(2, history.item_cnt_);
EXPECT_EQ(0, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT,
history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(
0, history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
EXPECT_EQ(history.items_[8].wait_begin_time_,
history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT]
.wait_begin_time_);
EXPECT_EQ(history.items_[9].wait_end_time_,
history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].wait_end_time_);
EXPECT_EQ(ObWaitEventIds::MT_READ_LOCK_WAIT, history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(0, history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
EXPECT_EQ(history.items_[8].wait_begin_time_, history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].wait_begin_time_);
EXPECT_EQ(history.items_[9].wait_end_time_, history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].wait_end_time_);
} else {
info.notify_wait_end(&tenant_info);
EXPECT_EQ(1, history.curr_pos_);
EXPECT_EQ(1, history.item_cnt_);
EXPECT_EQ(0, history.nest_cnt_);
EXPECT_EQ(ObWaitEventIds::PT_LOCATION_CACHE_LOCK_WAIT,
history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(
0, history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
EXPECT_EQ(ObWaitEventIds::PT_LOCATION_CACHE_LOCK_WAIT, history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].event_no_);
EXPECT_EQ(0, history.items_[(history.curr_pos_ - 1 + SESSION_WAIT_HISTORY_CNT) % SESSION_WAIT_HISTORY_CNT].level_);
}
info.reset();
}
@ -181,22 +168,22 @@ TEST(ObDiagnoseSessionInfo, normal)
for (int i = 0; i < 30; i++) {
{
ObWaitEventGuard wait_guard(i);
this_routine::usleep(i);
::usleep(i);
}
ObMaxWaitGuard max_guard1(&max_wait1);
ObTotalWaitGuard total_guard1(&total_wait1);
{
ObWaitEventGuard wait_guard1(29 - i);
this_routine::usleep(i * 200);
ObWaitEventGuard wait_guard1(29-i);
::usleep(i*200);
}
}
ObDiagnoseSessionInfo* info = ObDiagnoseSessionInfo::get_local_diagnose_info();
ObDiagnoseSessionInfo *info = ObDiagnoseSessionInfo::get_local_diagnose_info();
EXPECT_EQ(1, info->get_tenant_id());
ObWaitEventDesc* last_wait = NULL;
ObWaitEventDesc *last_wait = NULL;
info->get_event_history().get_last_wait(last_wait);
EXPECT_EQ(0, last_wait->event_no_);
EXPECT_EQ(0, info->get_curr_wait().event_no_);
// EXPECT_EQ(0, max_wait.event_no_);
//EXPECT_EQ(0, max_wait.event_no_);
EXPECT_EQ(54, total_wait.total_waits_);
uint64_t begin_time = ::oceanbase::common::ObTimeUtility::current_time();
for (int i = 0; i < 1000000; i++) {
@ -216,17 +203,16 @@ TEST(ObDiagnoseSessionInfo, normal)
}
}
class AtomicWaitEventTestRun : public cotesting::DefaultRunnable {
class AtomicWaitEventTestRun : public cotesting::DefaultRunnable
{
public:
AtomicWaitEventTestRun()
{}
~AtomicWaitEventTestRun()
{}
AtomicWaitEventTestRun() {}
~AtomicWaitEventTestRun() {}
void run1() override
{
ObSessionStatEstGuard session_guard(1, 1);
lock_.wrlock();
usleep(10000); // 10ms
usleep(10000); // 10ms
lock_.unlock();
}
@ -241,12 +227,12 @@ TEST(ObDiagnoseSessionInfo, atomic_wait_event)
test_run.set_thread_count(2);
test_run.start();
test_run.wait();
ObDiagnoseSessionInfo* info = ObDiagnoseSessionInfo::get_local_diagnose_info();
ObDiagnoseSessionInfo *info = ObDiagnoseSessionInfo::get_local_diagnose_info();
ASSERT_TRUE(NULL != info);
ASSERT_EQ(1, info->get_tenant_id());
ObWaitEventStat* event_stat = info->get_event_stats().get(ObWaitEventIds::LATCH_WAIT_QUEUE_LOCK_WAIT);
ObWaitEventStat *event_stat = info->get_event_stats().get(ObWaitEventIds::LATCH_WAIT_QUEUE_LOCK_WAIT);
ASSERT_TRUE(NULL != event_stat);
EXPECT_TRUE(0 < event_stat->total_waits_);
@ -255,10 +241,10 @@ TEST(ObDiagnoseSessionInfo, atomic_wait_event)
EXPECT_TRUE(0 < event_stat->total_waits_);
}
} // namespace common
} // namespace oceanbase
}
}
int main(int argc, char** argv)
int main(int argc, char **argv)
{
oceanbase::common::ObLogger::get_logger().set_log_level("INFO");
testing::InitGoogleTest(&argc, argv);

View File

@ -0,0 +1,103 @@
/**
* 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 "lib/memory/achunk_mgr.h"
#include "lib/allocator/ob_malloc.h"
using namespace oceanbase::lib;
using namespace oceanbase::common;
TEST(ObStatMemory, Basic)
{
int64_t limit = MSTAT_GET_LIMIT();
EXPECT_EQ(INT64_MAX, limit);
MSTAT_SET_LIMIT(1);
limit = MSTAT_GET_LIMIT();
EXPECT_EQ(1, limit);
EXPECT_LT(2<<20, ob_get_memory_size_handled()); // must gt 2M(block size)
{
MSTAT_SET_LIMIT(1L << 20);
int64_t limit = MSTAT_GET_LIMIT();
EXPECT_EQ(1L << 20, limit);
void *ptr = CHUNK_MGR.alloc_chunk();
EXPECT_EQ(NULL, ptr);
MSTAT_SET_LIMIT(2L << 20);
ptr = CHUNK_MGR.alloc_chunk();
EXPECT_EQ(NULL, ptr);
MSTAT_SET_LIMIT(4L << 20);
ptr = CHUNK_MGR.alloc_chunk();
EXPECT_EQ(NULL, ptr);
}
MSTAT_SET_LIMIT(100L << 20);
int64_t hold = 0;
int64_t used = 0;
MSTAT_GET_TENANT(1001, hold, used);
EXPECT_EQ(0, hold);
EXPECT_EQ(0, used);
{
MSTAT_SET_TENANT_LIMIT(1001, 0);
MSTAT_ADD(1001, ObModIds::TEST, 100, 10);
MSTAT_GET_MOD(ObModIds::TEST, hold, used);
EXPECT_EQ(0, hold);
EXPECT_EQ(0, used);
}
{
MSTAT_SET_TENANT_LIMIT(1001, 1000);
int64_t limit = MSTAT_GET_TENANT_LIMIT(1001);
EXPECT_EQ(1000, limit);
MSTAT_ADD(1001, ObModIds::TEST, 100, 10);
MSTAT_GET_MOD(ObModIds::TEST, hold, used);
EXPECT_EQ(100, hold);
EXPECT_EQ(10, used);
// It'll fail to update the statistics if hold exceeds limit
MSTAT_ADD(1001, ObModIds::TEST, 1000, 10);
MSTAT_GET_MOD(ObModIds::TEST, hold, used);
EXPECT_EQ(100, hold);
EXPECT_EQ(10, used);
// It'll success if hold doesn't exceed its limit
MSTAT_ADD(1001, ObModIds::TEST, 100, 10);
MSTAT_GET_MOD(ObModIds::TEST, hold, used);
EXPECT_EQ(200, hold);
EXPECT_EQ(20, used);
MSTAT_GET_TENANT(1001, hold, used);
EXPECT_EQ(200, hold);
EXPECT_EQ(20, used);
MSTAT_ADD(1001, ObModIds::OB_MOD_DO_NOT_USE_ME, 100, 10);
MSTAT_GET_TENANT(1001, hold, used);
EXPECT_EQ(300, hold);
EXPECT_EQ(30, used);
MSTAT_GET_TENANT(1002, hold, used);
EXPECT_EQ(0, hold);
EXPECT_EQ(0, used);
}
}
int main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -14,15 +14,17 @@
#include "lib/stat/ob_stat_template.h"
#include "lib/stat/ob_session_stat.h"
namespace oceanbase {
namespace common {
namespace oceanbase
{
namespace common
{
TEST(ObStatArray, normal)
{
int ret = OB_SUCCESS;
ObWaitEventStatArray stats1;
ObWaitEventStatArray stats2;
ObWaitEventStatArray::Iterator iter;
const ObWaitEventStat* item = NULL;
const ObWaitEventStat *item = NULL;
stats1.get(0)->total_waits_ = 1;
stats1.get(3)->total_waits_ = 2;
@ -41,13 +43,20 @@ TEST(ObStatArray, normal)
ASSERT_EQ(3, item->total_waits_);
ret = iter.get_next(item);
ASSERT_EQ(OB_ITER_END, ret);
}
} // namespace common
} // namespace oceanbase
}
}
int main(int argc, char** argv)
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}