[CP] close cursor when add fail

This commit is contained in:
LiuYoung00
2022-11-03 11:38:02 +00:00
committed by wangzelin.wzl
parent aa32ee0f60
commit 4ce250c313
2 changed files with 27 additions and 0 deletions

View File

@ -1218,6 +1218,7 @@ int ObSQLSessionInfo::add_cursor(pl::ObPLCursorInfo *cursor)
// open_cursors is 0 to indicate a special state, no limit is set // open_cursors is 0 to indicate a special state, no limit is set
#define NEED_CHECK_SESS_OPEN_CURSORS_LIMIT(v) (0 == v ? false : true) #define NEED_CHECK_SESS_OPEN_CURSORS_LIMIT(v) (0 == v ? false : true)
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
bool add_cursor_success = false;
omt::ObTenantConfigGuard tenant_config(TENANT_CONF(get_effective_tenant_id())); omt::ObTenantConfigGuard tenant_config(TENANT_CONF(get_effective_tenant_id()));
CK (tenant_config.is_valid()); CK (tenant_config.is_valid());
CK (OB_NOT_NULL(cursor)); CK (OB_NOT_NULL(cursor));
@ -1251,6 +1252,7 @@ int ObSQLSessionInfo::add_cursor(pl::ObPLCursorInfo *cursor)
LOG_WARN("fail insert ps id to hash map", K(id), K(*cursor), K(ret)); LOG_WARN("fail insert ps id to hash map", K(id), K(*cursor), K(ret));
} else { } else {
cursor->set_id(id); cursor->set_id(id);
add_cursor_success = true;
if (lib::is_diagnose_info_enabled()) { if (lib::is_diagnose_info_enabled()) {
EVENT_INC(SQL_OPEN_CURSORS_CURRENT); EVENT_INC(SQL_OPEN_CURSORS_CURRENT);
EVENT_INC(SQL_OPEN_CURSORS_CUMULATIVE); EVENT_INC(SQL_OPEN_CURSORS_CUMULATIVE);
@ -1258,6 +1260,30 @@ int ObSQLSessionInfo::add_cursor(pl::ObPLCursorInfo *cursor)
LOG_DEBUG("ps cursor: add cursor", K(ret), K(id), K(get_sessid())); LOG_DEBUG("ps cursor: add cursor", K(ret), K(id), K(get_sessid()));
} }
} }
if (!add_cursor_success && OB_NOT_NULL(cursor)) {
int64_t id = cursor->get_id();
int tmp_ret = close_cursor(cursor);
ret = OB_SUCCESS == ret ? tmp_ret : ret;
if (OB_SUCCESS != tmp_ret) {
LOG_WARN("close cursor fail when add cursor to sesssion.", K(ret), K(id), K(get_sessid()));
}
}
return ret;
}
int ObSQLSessionInfo::close_cursor(ObPLCursorInfo *&cursor)
{
int ret = OB_SUCCESS;
if (OB_NOT_NULL(cursor)) {
int64_t id = cursor->get_id();
OZ (cursor->close(*this));
cursor->~ObPLCursorInfo();
get_cursor_allocator().free(cursor);
cursor = NULL;
LOG_DEBUG("close cursor", K(ret), K(id), K(get_sessid()));
} else {
LOG_DEBUG("close cursor is null", K(get_sessid()));
}
return ret; return ret;
} }

View File

@ -676,6 +676,7 @@ public:
pl::ObPLCursorInfo *get_cursor(int64_t cursor_id); pl::ObPLCursorInfo *get_cursor(int64_t cursor_id);
pl::ObDbmsCursorInfo *get_dbms_cursor(int64_t cursor_id); pl::ObDbmsCursorInfo *get_dbms_cursor(int64_t cursor_id);
int add_cursor(pl::ObPLCursorInfo *cursor); int add_cursor(pl::ObPLCursorInfo *cursor);
int close_cursor(pl::ObPLCursorInfo *&cursor);
int close_cursor(int64_t cursor_id); int close_cursor(int64_t cursor_id);
int make_cursor(pl::ObPLCursorInfo *&cursor); int make_cursor(pl::ObPLCursorInfo *&cursor);
int init_cursor_cache(); int init_cursor_cache();