[to #49620051]fixed local unstream cursor reopen to local stream cursor mem core dump

This commit is contained in:
LiuYoung00 2023-05-11 13:26:01 +00:00 committed by ob-robot
parent d5854e43fc
commit b8ce00f94c
3 changed files with 15 additions and 23 deletions

View File

@ -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));

View File

@ -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),

View File

@ -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<ObSPIResultSet*>(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<stmt::StmtType>(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