[FIX] do throttle when mds operation is finished instead of allocating mds memory

This commit is contained in:
ZenoWang
2024-01-04 13:42:38 +00:00
committed by ob-robot
parent d798c34580
commit 3bdc9cb5df
11 changed files with 114 additions and 28 deletions

View File

@ -105,16 +105,13 @@ void *ObTenantMdsAllocator::alloc(const int64_t size, const int64_t abs_expire_t
{
bool is_throttled = false;
// try alloc resource from throttle tool
// record alloc resource in throttle tool, but do not throttle immediately
// ObMdsThrottleGuard calls the real throttle logic
(void)throttle_tool_->alloc_resource<ObTenantMdsAllocator>(size, abs_expire_time, is_throttled);
// if is throttled, do throttle
if (OB_UNLIKELY(is_throttled)) {
if (MTL(ObTenantFreezer *)->exist_ls_freezing()) {
(void)throttle_tool_->skip_throttle<ObTenantTxDataAllocator>(size);
} else {
(void)throttle_tool_->do_throttle<ObTenantTxDataAllocator>(abs_expire_time);
}
share::mds_throttled_alloc() += size;
}
void *obj = allocator_.alloc(size);
@ -174,5 +171,44 @@ void ObTenantBufferCtxAllocator::free(void *ptr)
MTL(ObTenantMdsService*)->erase_alloc_backtrace(ptr);
}
ObMdsThrottleGuard::ObMdsThrottleGuard(const bool for_replay, const int64_t abs_expire_time) : for_replay_(for_replay), abs_expire_time_(abs_expire_time)
{
throttle_tool_ = &(MTL(ObSharedMemAllocMgr *)->share_resource_throttle_tool());
}
ObMdsThrottleGuard::~ObMdsThrottleGuard()
{
ObThrottleInfoGuard share_ti_guard;
ObThrottleInfoGuard module_ti_guard;
if (OB_ISNULL(throttle_tool_)) {
MDS_LOG_RET(ERROR, OB_ERR_UNEXPECTED, "throttle tool is unexpected nullptr", KP(throttle_tool_));
} else if (throttle_tool_->is_throttling<ObTenantMdsAllocator>(share_ti_guard, module_ti_guard)) {
if (MTL(ObTenantFreezer *)->exist_ls_freezing()) {
(void)throttle_tool_->skip_throttle<ObTenantMdsAllocator>(
share::mds_throttled_alloc(), share_ti_guard, module_ti_guard);
if (module_ti_guard.is_valid()) {
module_ti_guard.throttle_info()->reset();
}
} else {
uint64_t timeout = 10000; // 10s
int64_t left_interval = abs_expire_time_ - ObClockGenerator::getClock();
common::ObWaitEventGuard wait_guard(
common::ObWaitEventIds::MEMSTORE_MEM_PAGE_ALLOC_WAIT, timeout, 0, 0, left_interval);
(void)throttle_tool_->do_throttle<ObTenantMdsAllocator>(abs_expire_time_);
if (for_replay_) {
get_replay_is_writing_throttling() = true;
}
}
// reset mds throttled alloc size
share::mds_throttled_alloc() = 0;
} else {
// do not need throttle, exit directly
}
}
} // namespace share
} // namespace oceanbase

View File

@ -20,6 +20,12 @@ namespace oceanbase {
namespace share {
OB_INLINE int64_t &mds_throttled_alloc()
{
RLOCAL_INLINE(int64_t, mds_throttled_alloc);
return mds_throttled_alloc;
}
class ObTenantMdsAllocator : public ObIAllocator {
private:
static const int64_t MDS_ALLOC_CONCURRENCY = 32;
@ -55,6 +61,18 @@ struct ObTenantBufferCtxAllocator : public ObIAllocator// for now, it is just a
virtual void set_attr(const ObMemAttr &) override {}
};
class ObMdsThrottleGuard
{
public:
ObMdsThrottleGuard(const bool for_replay, const int64_t abs_expire_time);
~ObMdsThrottleGuard();
private:
bool for_replay_;
int64_t abs_expire_time_;
share::TxShareThrottleTool *throttle_tool_;
};
} // namespace share
} // namespace oceanbase

View File

@ -100,6 +100,10 @@ void *ObTenantTxDataAllocator::alloc(const bool enable_throttle, const int64_t a
if (MTL(ObTenantFreezer *)->exist_ls_freezing()) {
(void)throttle_tool_->skip_throttle<ObTenantTxDataAllocator>(storage::TX_DATA_SLICE_SIZE);
} else {
uint64_t timeout = 10000; // 10s
int64_t left_interval = abs_expire_time - ObClockGenerator::getClock();
common::ObWaitEventGuard wait_guard(
common::ObWaitEventIds::MEMSTORE_MEM_PAGE_ALLOC_WAIT, timeout, 0, 0, left_interval);
(void)throttle_tool_->do_throttle<ObTenantTxDataAllocator>(abs_expire_time);
}
}