fix WORK_AREA not limit after restart observer
This commit is contained in:
1
deps/oblib/src/lib/alloc/alloc_func.h
vendored
1
deps/oblib/src/lib/alloc/alloc_func.h
vendored
@ -48,6 +48,7 @@ int64_t ob_get_reserved_urgent_memory();
|
||||
// pc_pctg: percentage limitation of tenant memory can be used by Plan Cache
|
||||
// wa_pctg: percentage limitation of tenant memory can be used by Work Area
|
||||
|
||||
int set_ctx_limit(uint64_t tenant_id, uint64_t ctx_id, const int64_t limit);
|
||||
int set_wa_limit(uint64_t tenand_id, int64_t wa_pctg);
|
||||
|
||||
// set meta object memory limit for specified tenant.
|
||||
|
||||
@ -235,19 +235,21 @@ TEST_F(TestMultiTenant, get_tenant_context)
|
||||
class CtxMemConfigGetter : public ObICtxMemConfigGetter
|
||||
{
|
||||
public:
|
||||
virtual int get(common::ObIArray<ObCtxMemConfig> &configs)
|
||||
virtual int get(common::ObIArray<ObCtxMemConfig> &configs, int64_t tenant_limit)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
{
|
||||
ObCtxMemConfig cfg;
|
||||
cfg.ctx_id_ = 10;
|
||||
cfg.idle_size_ = 10 * INTACT_ACHUNK_SIZE;
|
||||
cfg.limit_ = 5 * tenant_limit / 100;
|
||||
ret = configs.push_back(cfg);
|
||||
}
|
||||
{
|
||||
ObCtxMemConfig cfg;
|
||||
cfg.ctx_id_ = 11;
|
||||
cfg.idle_size_ = 20 * INTACT_ACHUNK_SIZE;
|
||||
cfg.limit_ = 10 * tenant_limit / 100;
|
||||
ret = configs.push_back(cfg);
|
||||
}
|
||||
return ret;
|
||||
@ -262,10 +264,11 @@ TEST_F(TestMultiTenant, idle)
|
||||
uint64_t tenant_id = 100;
|
||||
int ret = add_tenant(tenant_id);
|
||||
ASSERT_EQ(OB_SUCCESS, ret);
|
||||
common::ObArray<ObCtxMemConfig> configs;
|
||||
mcg.get(configs);
|
||||
ASSERT_TRUE(2 == configs.size());
|
||||
ObMallocAllocator *malloc_allocator = ObMallocAllocator::get_instance();
|
||||
int64_t tenant_limit = malloc_allocator->get_tenant_limit(tenant_id);
|
||||
common::ObArray<ObCtxMemConfig> configs;
|
||||
mcg.get(configs, tenant_limit);
|
||||
ASSERT_TRUE(2 == configs.size());
|
||||
for (int i = 0 ; i < configs.size(); i++) {
|
||||
ObCtxMemConfig &cfg = configs.at(i);
|
||||
auto ta = malloc_allocator->get_tenant_ctx_allocator(tenant_id, cfg.ctx_id_);
|
||||
@ -273,6 +276,7 @@ TEST_F(TestMultiTenant, idle)
|
||||
int64_t chunk_cnt = cfg.idle_size_/INTACT_ACHUNK_SIZE;
|
||||
ASSERT_EQ(ta->chunk_cnt_, chunk_cnt);
|
||||
ASSERT_EQ(ta->idle_size_, cfg.idle_size_);
|
||||
ASSERT_EQ(ta->get_limit(), cfg.limit_);
|
||||
ASSERT_NE(0, malloc_allocator->get_tenant_ctx_hold(tenant_id, cfg.ctx_id_));
|
||||
}
|
||||
// remove
|
||||
|
||||
@ -210,10 +210,17 @@ bool equal_with_tenant_id(const ObTenant *lhs,
|
||||
return NULL != lhs ? (lhs->id() == tenant_id) : false;
|
||||
}
|
||||
|
||||
int ObCtxMemConfigGetter::get(common::ObIArray<ObCtxMemConfig> &configs)
|
||||
int ObCtxMemConfigGetter::get(common::ObIArray<ObCtxMemConfig> &configs, int64_t tenant_limit)
|
||||
{
|
||||
UNUSED(configs);
|
||||
return OB_SUCCESS;
|
||||
int64_t ret = OB_SUCCESS;
|
||||
{
|
||||
ObCtxMemConfig cfg;
|
||||
cfg.ctx_id_ = ObCtxIds::WORK_AREA;
|
||||
cfg.idle_size_ = 0;
|
||||
cfg.limit_ = 5 * tenant_limit / 100;
|
||||
ret = configs.push_back(cfg);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ObCtxMemConfigGetter g_default_mcg;
|
||||
@ -786,15 +793,18 @@ int ObMultiTenant::create_tenant(const ObTenantMeta &meta, bool write_slog, cons
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
ObSEArray<ObCtxMemConfig, ObCtxIds::MAX_CTX_ID> configs;
|
||||
if (OB_FAIL(mcg_->get(configs))) {
|
||||
if (OB_FAIL(mcg_->get(configs, allowed_mem_limit))) {
|
||||
LOG_ERROR("get ctx mem config failed", K(ret));
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < configs.count(); i++) {
|
||||
const uint64_t ctx_id = configs.at(i).ctx_id_;
|
||||
const int64_t idle_size = configs.at(i).idle_size_;
|
||||
const int64_t limit = configs.at(i).limit_;
|
||||
const bool reserve = true;
|
||||
if (OB_FAIL(malloc_allocator->set_tenant_ctx_idle(tenant_id, ctx_id, idle_size, reserve))) {
|
||||
LOG_ERROR("set tenant ctx idle failed", K(ret));
|
||||
} else if (OB_FAIL(set_ctx_limit(tenant_id, ctx_id, limit))) {
|
||||
LOG_ERROR("set tenant ctx limit failed", K(ret), K(limit));
|
||||
}
|
||||
LOG_INFO("init ctx memory finish", K(ret), K(tenant_id), K(i), K(configs.at(i)));
|
||||
}
|
||||
|
||||
@ -45,22 +45,23 @@ class ObTenantConfig;
|
||||
struct ObCtxMemConfig
|
||||
{
|
||||
ObCtxMemConfig()
|
||||
: ctx_id_(0), idle_size_(0) {}
|
||||
: ctx_id_(0), idle_size_(0), limit_(INT64_MAX) {}
|
||||
uint64_t ctx_id_;
|
||||
int64_t idle_size_;
|
||||
TO_STRING_KV(K_(ctx_id), K_(idle_size));
|
||||
int64_t limit_;
|
||||
TO_STRING_KV(K_(ctx_id), K_(idle_size), K_(limit));
|
||||
};
|
||||
|
||||
class ObICtxMemConfigGetter
|
||||
{
|
||||
public:
|
||||
virtual int get(common::ObIArray<ObCtxMemConfig> &configs) = 0;
|
||||
virtual int get(common::ObIArray<ObCtxMemConfig> &configs, int64_t tenant_limit) = 0;
|
||||
};
|
||||
|
||||
class ObCtxMemConfigGetter : public ObICtxMemConfigGetter
|
||||
{
|
||||
public:
|
||||
virtual int get(common::ObIArray<ObCtxMemConfig> &configs);
|
||||
virtual int get(common::ObIArray<ObCtxMemConfig> &configs, int64_t tenant_limit);
|
||||
};
|
||||
|
||||
// Forward declearation
|
||||
|
||||
Reference in New Issue
Block a user