fix bug: plan cache core is caused by the plan cache diagnostic view.

This commit is contained in:
GongYusen
2023-12-18 21:47:59 +00:00
committed by ob-robot
parent 5c8abefd6d
commit f0d025ca4c
8 changed files with 56 additions and 9 deletions

View File

@ -132,7 +132,7 @@ void ObLCObjectManager::common_free(ObILibCacheObject *cache_obj,
if (OB_ISNULL(cache_obj)) {
// do nothing
} else {
if (!cache_obj->added_lc()) {
if (ref_handle != PC_DIAG_HANDLE && !cache_obj->added_lc()) {
cache_obj->set_logical_del_time(ObTimeUtility::current_monotonic_time());
LOG_WARN("set logical del time", K(cache_obj->get_logical_del_time()),
K(cache_obj->added_lc()),

View File

@ -65,7 +65,8 @@ const char* ObCacheRefHandleMgr::handle_name(const CacheRefHandleID handle_id)
"plan_baseline_handle",
"tableapi_node_handle",
"sql_plan_handle",
"callstmt_handle"
"callstmt_handle",
"pc_diag_handle"
};
static_assert(sizeof(handle_names)/sizeof(const char*) == MAX_HANDLE, "invalid handle name array");
if (handle_id < MAX_HANDLE) {

View File

@ -130,6 +130,7 @@ enum CacheRefHandleID
TABLEAPI_NODE_HANDLE,
SQL_PLAN_HANDLE,
CALLSTMT_HANDLE,
PC_DIAG_HANDLE,
MAX_HANDLE
};

View File

@ -1707,7 +1707,7 @@ int ObPlanCache::ref_cache_obj(const ObCacheObjID obj_id, ObCacheObjGuard& guard
int ret = OB_SUCCESS;
ObCacheObjAtomicOp op(guard.ref_handle_);
ObGlobalReqTimeService::check_req_timeinfo();
if (OB_FAIL(co_mgr_.atomic_get_alloc_cache_obj(obj_id, op))) {
if (OB_FAIL(co_mgr_.atomic_get_cache_obj(obj_id, op))) {
SQL_PC_LOG(WARN, "failed to get update plan statistic", K(obj_id), K(ret));
} else if (NULL == op.get_value()) {
ret = OB_HASH_NOT_EXIST;
@ -1736,6 +1736,40 @@ int ObPlanCache::ref_plan(const ObCacheObjID plan_id, ObCacheObjGuard& guard)
return ret;
}
int ObPlanCache::ref_alloc_obj(const ObCacheObjID obj_id, ObCacheObjGuard& guard)
{
int ret = OB_SUCCESS;
ObCacheObjAtomicOp op(guard.ref_handle_);
ObGlobalReqTimeService::check_req_timeinfo();
if (OB_FAIL(co_mgr_.atomic_get_alloc_cache_obj(obj_id, op))) {
SQL_PC_LOG(WARN, "failed to get update plan statistic", K(obj_id), K(ret));
} else if (NULL == op.get_value()) {
ret = OB_HASH_NOT_EXIST;
} else {
guard.cache_obj_ = op.get_value();
}
return ret;
}
int ObPlanCache::ref_alloc_plan(const ObCacheObjID plan_id, ObCacheObjGuard& guard)
{
int ret = OB_SUCCESS;
ObILibCacheObject *cache_obj = NULL;
ObGlobalReqTimeService::check_req_timeinfo();
if (OB_FAIL(ref_alloc_obj(plan_id, guard))) { // inc ref count by 1
LOG_WARN("failed to ref cache obj", K(ret));
} else if (FALSE_IT(cache_obj = guard.cache_obj_)) {
// do nothing
} else if (OB_ISNULL(cache_obj)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null cache object", K(ret));
} else if (ObLibCacheNameSpace::NS_CRSR != cache_obj->get_ns()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("this cache object is not a plan.", K(ret), K(cache_obj->get_ns()));
}
return ret;
}
int ObPlanCache::add_cache_obj_stat(ObILibCacheCtx &ctx, ObILibCacheObject *cache_obj)
{
int ret = OB_SUCCESS;

View File

@ -26,6 +26,11 @@
#include "sql/plan_cache/ob_lib_cache_object_manager.h"
namespace oceanbase
{
namespace observer
{
class ObGVSql;
class ObAllVirtualSqlPlan;
}
namespace rpc
{
class ObLoadBaselineArg;
@ -221,6 +226,8 @@ class ObPlanCache
{
friend class ObCacheObjectFactory;
friend class ObPlanCacheEliminationTask;
friend class observer::ObAllVirtualSqlPlan;
friend class observer::ObGVSql;
public:
static const int64_t MAX_PLAN_SIZE = 20*1024*1024; //20M
@ -421,6 +428,10 @@ public:
int flush_lib_cache_by_ns(const ObLibCacheNameSpace ns);
int flush_pl_cache();
protected:
int ref_alloc_obj(const ObCacheObjID obj_id, ObCacheObjGuard& guard);
int ref_alloc_plan(const ObCacheObjID obj_id, ObCacheObjGuard& guard);
private:
DISALLOW_COPY_AND_ASSIGN(ObPlanCache);
int add_plan_cache(ObILibCacheCtx &ctx,