From 94e2cc67b4bd48a22d7a54e89814b6f108c54329 Mon Sep 17 00:00:00 2001 From: nroskill Date: Wed, 18 Aug 2021 10:16:22 +0800 Subject: [PATCH] memory diagnose including deleted tenant --- .../src/lib/alloc/ob_malloc_allocator.cpp | 4 +++ .../oblib/src/lib/alloc/ob_malloc_allocator.h | 3 +- src/share/ob_tenant_mgr.cpp | 28 +++---------------- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp b/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp index 9363d40446..2afe961d8a 100644 --- a/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp +++ b/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp @@ -25,6 +25,7 @@ using namespace oceanbase::lib; using namespace oceanbase::common; ObMallocAllocator* ObMallocAllocator::instance_ = NULL; +uint64_t ObMallocAllocator::max_used_tenant_id_ = 0; ObMallocAllocator::ObMallocAllocator() : locks_(), allocators_(), reserved_(0), urgent_(0) {} @@ -206,6 +207,9 @@ ObTenantCtxAllocator* ObMallocAllocator::get_tenant_ctx_allocator(uint64_t tenan int ObMallocAllocator::create_tenant_ctx_allocator(uint64_t tenant_id, uint64_t ctx_id) { int ret = OB_SUCCESS; + if (tenant_id > max_used_tenant_id_) { + UNUSED(ATOMIC_BCAS(&max_used_tenant_id_, max_used_tenant_id_, tenant_id)); + } if (INT64_MAX == tenant_id) { ret = OB_INVALID_ARGUMENT; LOG_ERROR("invalid argument", K(lbt()), K(tenant_id), K(ret)); diff --git a/deps/oblib/src/lib/alloc/ob_malloc_allocator.h b/deps/oblib/src/lib/alloc/ob_malloc_allocator.h index 132593a3d2..7bfca7bf0a 100644 --- a/deps/oblib/src/lib/alloc/ob_malloc_allocator.h +++ b/deps/oblib/src/lib/alloc/ob_malloc_allocator.h @@ -66,7 +66,7 @@ public: int set_tenant_ctx_idle( const uint64_t tenant_id, const uint64_t ctx_id, const int64_t size, const bool reserve = false); int get_chunks(AChunk** chunks, int cap, int& cnt); - + static uint64_t get_max_used_tenant_id() { return max_used_tenant_id_; } private: using InvokeFunc = std::function; static int with_resource_handle_invoke(uint64_t tenant_id, InvokeFunc func); @@ -79,6 +79,7 @@ private: ObTenantCtxAllocator* allocators_[PRESERVED_TENANT_COUNT][common::ObCtxIds::MAX_CTX_ID]; int64_t reserved_; int64_t urgent_; + static uint64_t max_used_tenant_id_; static ObMallocAllocator* instance_; }; // end of class ObMallocAllocator diff --git a/src/share/ob_tenant_mgr.cpp b/src/share/ob_tenant_mgr.cpp index ae993b961f..7fc04a824e 100644 --- a/src/share/ob_tenant_mgr.cpp +++ b/src/share/ob_tenant_mgr.cpp @@ -194,31 +194,11 @@ using namespace oceanbase::storage; void get_tenant_ids(uint64_t* ids, int cap, int& cnt) { int ret = OB_SUCCESS; + auto *instance = ObMallocAllocator::get_instance(); cnt = 0; - omt::ObMultiTenant* omt = GCTX.omt_; - if (OB_ISNULL(omt)) { - if (ObTenantManager::get_instance().is_inited()) { - common::ObArray tmp_ids; - if (OB_FAIL(ObTenantManager::get_instance().get_all_tenant_id(tmp_ids))) { - SERVER_LOG(WARN, "get tenant id error", K(ret)); - } else { - for (auto it = tmp_ids.begin(); OB_SUCC(ret) && it != tmp_ids.end() && cnt < cap; it++) { - ids[cnt++] = *it; - } - } - } else { - if (cnt < cap) { - ids[cnt++] = OB_SYS_TENANT_ID; - } - if (cnt < cap) { - ids[cnt++] = OB_SERVER_TENANT_ID; - } - } - } else { - omt::TenantIdList tmp_ids(nullptr, ObModIds::OMT); - omt->get_tenant_ids(tmp_ids); - for (auto it = tmp_ids.begin(); OB_SUCC(ret) && it != tmp_ids.end() && cnt < cap; it++) { - ids[cnt++] = *it; + for (uint64_t tenant_id = 1; tenant_id <= ObMallocAllocator::get_max_used_tenant_id() && cnt < cap; ++tenant_id) { + if (nullptr != instance->get_tenant_ctx_allocator(tenant_id, 0)) { + ids[cnt++] = tenant_id; } } }