From 0acbec120ffa36380a3aa187e294b5189767172d Mon Sep 17 00:00:00 2001 From: obdev Date: Mon, 26 Jun 2023 00:43:11 +0000 Subject: [PATCH] Make enable_system_tenant_memory_limit take effect dynamicly --- .../src/lib/alloc/ob_malloc_allocator.cpp | 5 +++- .../oblib/src/lib/alloc/ob_malloc_allocator.h | 2 +- src/diagnose/lua/ob_lua_api.cpp | 24 +++++++++++++++++++ src/diagnose/lua/test.lua | 4 +++- src/observer/ob_server.cpp | 5 ---- src/share/config/ob_server_config.cpp | 11 +++++++++ src/share/parameter/ob_parameter_seed.ipp | 2 +- 7 files changed, 44 insertions(+), 9 deletions(-) diff --git a/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp b/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp index cfd7add0d..56eda25cf 100644 --- a/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp +++ b/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp @@ -403,7 +403,7 @@ int ObMallocAllocator::with_resource_handle_invoke(uint64_t tenant_id, InvokeFun return ret; } #ifdef ENABLE_500_MEMORY_LIMIT -int ObMallocAllocator::set_500_tenant_limit() +int ObMallocAllocator::set_500_tenant_limit(const bool unlimited) { int ret = OB_SUCCESS; for (int ctx_id = 0; OB_SUCC(ret) && ctx_id < ObCtxIds::MAX_CTX_ID; ++ctx_id) { @@ -420,6 +420,9 @@ int ObMallocAllocator::set_500_tenant_limit() auto ta = get_tenant_ctx_allocator(OB_SERVER_TENANT_ID, ctx_id); if (OB_NOT_NULL(ta)) { int64_t ctx_limit = ObCtxIds::DEFAULT_CTX_ID == ctx_id ? (3LL<<30) : (50LL<<20); + if (unlimited) { + ctx_limit = INT64_MAX; + } if (OB_FAIL(ta->set_limit(ctx_limit))) { LIB_LOG(WARN, "set limit of 500 tenant failed", K(ret), K(ctx_limit), "ctx_name", get_global_ctx_info().get_ctx_name(ctx_id)); diff --git a/deps/oblib/src/lib/alloc/ob_malloc_allocator.h b/deps/oblib/src/lib/alloc/ob_malloc_allocator.h index c689bcfbe..b0d87f996 100644 --- a/deps/oblib/src/lib/alloc/ob_malloc_allocator.h +++ b/deps/oblib/src/lib/alloc/ob_malloc_allocator.h @@ -123,7 +123,7 @@ public: void set_reserved(int64_t bytes); int64_t get_reserved() const; #ifdef ENABLE_500_MEMORY_LIMIT - int set_500_tenant_limit(); + int set_500_tenant_limit(const bool unlimited); #endif int set_tenant_limit(uint64_t tenant_id, int64_t bytes); int64_t get_tenant_limit(uint64_t tenant_id); diff --git a/src/diagnose/lua/ob_lua_api.cpp b/src/diagnose/lua/ob_lua_api.cpp index 808024af9..196604fec 100644 --- a/src/diagnose/lua/ob_lua_api.cpp +++ b/src/diagnose/lua/ob_lua_api.cpp @@ -139,6 +139,7 @@ static constexpr const char *usage_str = "{{row1}, {row2}, ...} = select_schema_slot()\n" "{{row1}, {row2}, ...} = dump_thread_info()\n" "{{row1}, {row2}, ...} = select_malloc_sample_info()\n" +"int = enable_system_tenant_memory_limit(boolean)\n" ; class LuaVtableGenerator @@ -1986,6 +1987,28 @@ int select_malloc_sample_info(lua_State *L) return 1; } +// int = enable_system_tenant_memory_limit(boolean) +int enable_system_tenant_memory_limit(lua_State* L) +{ + int ret = OB_SUCCESS; + int argc = lua_gettop(L); + if (1 != argc) { + OB_LOG(ERROR, "call enable_system_tenant_memory_limit() failed, bad arguments count, should be 1."); + ret = OB_INVALID_ARGUMENT; + } else { + luaL_checktype(L, 1, LUA_TBOOLEAN); + int enable = lua_toboolean(L, 1); +#ifdef ENABLE_500_MEMORY_LIMIT + ObMallocAllocator::get_instance()->set_500_tenant_limit(!enable/*unlimited*/); +#endif + lua_pushinteger(L, 1); + } + if (OB_FAIL(ret)) { + lua_pushinteger(L, -1); + } + return 1; +} + // API end int get_tenant_sysstat(int64_t tenant_id, int64_t statistic, int64_t &value) @@ -2113,6 +2136,7 @@ void APIRegister::register_api(lua_State* L) lua_register(L, "select_schema_slot", select_schema_slot); lua_register(L, "dump_thread_info", dump_thread_info); lua_register(L, "select_malloc_sample_info", select_malloc_sample_info); + lua_register(L, "enable_system_tenant_memory_limit", enable_system_tenant_memory_limit); } int APIRegister::flush() diff --git a/src/diagnose/lua/test.lua b/src/diagnose/lua/test.lua index cffbe7a0a..a59d4a594 100644 --- a/src/diagnose/lua/test.lua +++ b/src/diagnose/lua/test.lua @@ -336,4 +336,6 @@ para["select"] = { "alloc_bytes" } print_to_client("select_malloc_sample_info") -select_malloc_sample_info(para) \ No newline at end of file +select_malloc_sample_info(para) + +enable_system_tenant_memory_limit(true) diff --git a/src/observer/ob_server.cpp b/src/observer/ob_server.cpp index de41769a2..e5719fcbf 100644 --- a/src/observer/ob_server.cpp +++ b/src/observer/ob_server.cpp @@ -1717,11 +1717,6 @@ int ObServer::init_config() LOG_ERROR("some config setting is not valid", KR(ret)); } else if (OB_FAIL(GMEMCONF.reload_config(config_))) { LOG_ERROR("reload memory config failed", KR(ret)); -#ifdef ENABLE_500_MEMORY_LIMIT - } else if (config_._enable_system_tenant_memory_limit && - OB_FAIL(ObMallocAllocator::get_instance()->set_500_tenant_limit())) { - LOG_ERROR("set the limit of tenant 500 failed", KR(ret)); -#endif } else if (!is_arbitration_mode() && OB_FAIL(set_running_mode())) { LOG_ERROR("set running mode failed", KR(ret)); } else { diff --git a/src/share/config/ob_server_config.cpp b/src/share/config/ob_server_config.cpp index ae6f69fff..fba20b4ca 100644 --- a/src/share/config/ob_server_config.cpp +++ b/src/share/config/ob_server_config.cpp @@ -287,6 +287,17 @@ int ObServerMemoryConfig::reload_config(const ObServerConfig& server_config) K(observer_tenant_hold), K_(system_memory)); } } + +#ifdef ENABLE_500_MEMORY_LIMIT + if (OB_FAIL(ret)) { + // do-nothing + } else if (is_arbitration_mode) { + // do-nothing + } else if (OB_FAIL(ObMallocAllocator::get_instance()->set_500_tenant_limit( + !server_config._enable_system_tenant_memory_limit))) { + LOG_ERROR("set the limit of tenant 500 failed", KR(ret)); + } +#endif return ret; } diff --git a/src/share/parameter/ob_parameter_seed.ipp b/src/share/parameter/ob_parameter_seed.ipp index 241f8c852..54558c511 100755 --- a/src/share/parameter/ob_parameter_seed.ipp +++ b/src/share/parameter/ob_parameter_seed.ipp @@ -1573,5 +1573,5 @@ DEF_CAP(range_optimizer_max_mem_size, OB_TENANT_PARAMETER, "128M", "[16M,1G]", #ifdef ENABLE_500_MEMORY_LIMIT DEF_BOOL(_enable_system_tenant_memory_limit, OB_CLUSTER_PARAMETER, "True", "specifies whether allowed to limit the memory of tenant 500", - ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::STATIC_EFFECTIVE)); + ObParameterAttr(Section::OBSERVER, Source::DEFAULT, EditLevel::DYNAMIC_EFFECTIVE)); #endif