From 145a4a87a67f04587c625be28940def9f9c4cd4c Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 24 Nov 2022 09:37:37 +0000 Subject: [PATCH] [CP] print MEMORY LOG when tenant deleted but memory not freed --- src/observer/omt/ob_multi_tenant.cpp | 9 +++++++- .../tx_storage/ob_tenant_memory_printer.cpp | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/observer/omt/ob_multi_tenant.cpp b/src/observer/omt/ob_multi_tenant.cpp index 8f57e1115..67f087f06 100644 --- a/src/observer/omt/ob_multi_tenant.cpp +++ b/src/observer/omt/ob_multi_tenant.cpp @@ -569,12 +569,19 @@ int ObMultiTenant::create_tenant_without_unit(const uint64_t tenant_id, static const int64_t VIRTUAL_TENANT_MEMORY_LIMTI = 1L << 30; mem_limit = VIRTUAL_TENANT_MEMORY_LIMTI; } - if (OB_FAIL(construct_meta_for_virtual_tenant(tenant_id, min_cpu, max_cpu, mem_limit, meta))) { LOG_WARN("fail to construct_meta_for_virtual_tenant", K(ret), K(tenant_id)); } else if (OB_FAIL(create_tenant(meta, false))) { LOG_WARN("fail to create virtual tenant", K(ret), K(tenant_id)); } + if (OB_SUCC(ret) && is_virtual_tenant_id(tenant_id)) { + ObVirtualTenantManager &omti = ObVirtualTenantManager::get_instance(); + if (OB_FAIL(omti.add_tenant(tenant_id))) { + LOG_ERROR("Fail to add virtual tenant to tenant manager, ", K(ret)); + } else if (OB_FAIL(omti.set_tenant_mem_limit(tenant_id, 0, mem_limit))) { + LOG_ERROR("Fail to set virtual tenant mem limit, ", K(ret)); + } + } return ret; } diff --git a/src/storage/tx_storage/ob_tenant_memory_printer.cpp b/src/storage/tx_storage/ob_tenant_memory_printer.cpp index 46a0d0acf..f5ba308d4 100644 --- a/src/storage/tx_storage/ob_tenant_memory_printer.cpp +++ b/src/storage/tx_storage/ob_tenant_memory_printer.cpp @@ -13,6 +13,7 @@ #define USING_LOG_PREFIX STORAGE #include "lib/utility/ob_print_utils.h" +#include "lib/alloc/memory_dump.h" #include "observer/omt/ob_multi_tenant.h" // ObMultiTenant #include "share/ob_tenant_mgr.h" // get_virtual_memory_used #include "share/allocator/ob_memstore_allocator_mgr.h" // ObMemstoreAllocatorMgr @@ -90,6 +91,28 @@ int ObTenantMemoryPrinter::print_tenant_usage() LOG_WARN("print mtl tenant usage failed", K(tmp_ret), K(tenant_id)); } } + static int64_t last_print_ts = 0; + const int64_t now = ObTimeUtility::current_time(); + const int64_t INTERVAL = 10 * 60 * 1000000L; + if (now - last_print_ts >= INTERVAL) { + omt::TenantIdList current_ids(nullptr, ObModIds::OMT); + omt->get_tenant_ids(current_ids); + int tenant_cnt = 0; + static uint64_t all_tenant_ids[OB_MAX_SERVER_TENANT_CNT] = {0}; + common::get_tenant_ids(all_tenant_ids, OB_MAX_SERVER_TENANT_CNT, tenant_cnt); + for (int64_t i = 0; OB_SUCC(ret) && i < tenant_cnt; ++i) { + uint64_t id = all_tenant_ids[i]; + if (OB_SERVER_TENANT_ID != id && current_ids.find(id) == current_ids.end()) { + // id is deleted tenant + lib::ObMallocAllocator *mallocator = lib::ObMallocAllocator::get_instance(); + if (OB_NOT_NULL(mallocator)) { + mallocator->print_tenant_memory_usage(id); + mallocator->print_tenant_ctx_memory_usage(id); + } + } + } + last_print_ts = now; + } } if (OB_SIZE_OVERFLOW == ret) {