From b8ce00f94ca2d22e270cdba166d3e305d48b3630 Mon Sep 17 00:00:00 2001 From: LiuYoung00 Date: Thu, 11 May 2023 13:26:01 +0000 Subject: [PATCH] [to #49620051]fixed local unstream cursor reopen to local stream cursor mem core dump --- src/pl/ob_pl_type.cpp | 21 ++++++++++----------- src/pl/ob_pl_type.h | 3 ++- src/sql/ob_spi.cpp | 14 +++----------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/pl/ob_pl_type.cpp b/src/pl/ob_pl_type.cpp index 3434805bf..d9813cf82 100644 --- a/src/pl/ob_pl_type.cpp +++ b/src/pl/ob_pl_type.cpp @@ -1988,15 +1988,10 @@ int ObPLCursorInfo::prepare_spi_result(ObPLExecCtx *ctx, ObSPIResultSet *&spi_re CK (OB_NOT_NULL(ctx)); CK (OB_NOT_NULL(ctx->exec_ctx_)); CK (OB_NOT_NULL(ctx->exec_ctx_->get_my_session())); - if (OB_SUCC(ret)) { - if (OB_ISNULL(spi_cursor_)) { - OV (OB_NOT_NULL(entity_)); - if (OB_SUCC(ret)) { - ObIAllocator &alloc = entity_->get_arena_allocator(); - OX (spi_cursor_ = alloc.alloc(sizeof(ObSPIResultSet))); - OV (OB_NOT_NULL(spi_cursor_), OB_ALLOCATE_MEMORY_FAILED); - } - } + if (OB_ISNULL(spi_cursor_)) { + OV (OB_NOT_NULL(get_allocator())); + OX (spi_cursor_ = get_allocator()->alloc(sizeof(ObSPIResultSet))); + OV (OB_NOT_NULL(spi_cursor_), OB_ALLOCATE_MEMORY_FAILED); } OX (spi_result = new (spi_cursor_) ObSPIResultSet()); OZ (spi_result->init(*ctx->exec_ctx_->get_my_session())); @@ -2005,7 +2000,8 @@ int ObPLCursorInfo::prepare_spi_result(ObPLExecCtx *ctx, ObSPIResultSet *&spi_re int ObPLCursorInfo::prepare_spi_cursor(ObSPICursor *&spi_cursor, uint64_t tenant_id, - uint64_t mem_limit) + uint64_t mem_limit, + bool is_local_for_update) { int ret = OB_SUCCESS; ObIAllocator *spi_allocator = get_allocator(); @@ -2013,7 +2009,10 @@ int ObPLCursorInfo::prepare_spi_cursor(ObSPICursor *&spi_cursor, ret = OB_ERR_UNEXPECTED; LOG_WARN("cursor allocator is null.", K(ret), K(spi_allocator), K(id_)); } else if (OB_ISNULL(spi_cursor_)) { - OX (spi_cursor_ = spi_allocator->alloc(sizeof(ObSPICursor))); + int64_t alloc_size = is_local_for_update + ? (sizeof(ObSPICursor) > sizeof(ObSPIResultSet) ? sizeof(ObSPICursor) : sizeof(ObSPIResultSet)) + : sizeof(ObSPICursor); + OX (spi_cursor_ = spi_allocator->alloc(alloc_size)); OV (OB_NOT_NULL(spi_cursor_), OB_ALLOCATE_MEMORY_FAILED); } OX (spi_cursor = new (spi_cursor_) ObSPICursor(*spi_allocator)); diff --git a/src/pl/ob_pl_type.h b/src/pl/ob_pl_type.h index af11508ee..fe7cb1ac2 100644 --- a/src/pl/ob_pl_type.h +++ b/src/pl/ob_pl_type.h @@ -967,7 +967,8 @@ public: int prepare_spi_result(ObPLExecCtx *ctx, sql::ObSPIResultSet *&spi_result); int prepare_spi_cursor(sql::ObSPICursor *&spi_cursor, uint64_t tenant_id, - uint64_t mem_limit); + uint64_t mem_limit, + bool is_local_for_update = false); TO_STRING_KV(K_(id), K_(is_explicit), diff --git a/src/sql/ob_spi.cpp b/src/sql/ob_spi.cpp index 970d4b742..e3072f5ea 100644 --- a/src/sql/ob_spi.cpp +++ b/src/sql/ob_spi.cpp @@ -3379,16 +3379,7 @@ int ObSPIService::spi_cursor_open(ObPLExecCtx *ctx, do { ret = OB_SUCCESS; // 如果当前cursor已经有spi_result则复用,避免内存占用过多 - spi_result = (NULL == cursor->get_cursor_handler()) - ? static_cast(cursor->get_allocator()->alloc(sizeof(ObSPIResultSet))) - : cursor->get_cursor_handler(); - if (OB_ISNULL(spi_result)) { - ret = OB_ALLOCATE_MEMORY_FAILED; - LOG_WARN("failed to alloc mysql result"); - } - OX (new(spi_result)ObSPIResultSet()); - OZ (spi_result->init(*session_info)); - OX (cursor->set_spi_cursor(spi_result)); + OZ (cursor->prepare_spi_result(ctx, spi_result)); OZ (spi_result->start_cursor_stmt(ctx, static_cast(type), false)); OZ ((GCTX.schema_service_->get_tenant_schema_guard(session_info->get_effective_tenant_id(), spi_result->get_scheme_guard()))); OX (spi_result->get_sql_ctx().schema_guard_ = &spi_result->get_scheme_guard()); @@ -3512,7 +3503,8 @@ int ObSPIService::spi_cursor_open(ObPLExecCtx *ctx, OZ (session_info->get_tmp_table_size(size)); OZ (cursor->prepare_spi_cursor(spi_cursor, session_info->get_effective_tenant_id(), - size), K(size)); + size, + for_update && !is_server_cursor), K(size)); //if (is_server_cursor) { // not only server cursor need field set // normal cursor maybe convert to session cursor by to_cursor_number