[to #49335040]add thread lock for pl_cursor_map_

This commit is contained in:
LiuYoung00
2023-04-26 15:06:08 +00:00
committed by ob-robot
parent ffb125d10e
commit 3514f929b6

View File

@ -292,6 +292,9 @@ void ObSQLSessionInfo::reset(bool skip_sys_var)
pl_query_sender_ = NULL;
pl_ps_protocol_ = false;
if (pl_cursor_cache_.is_inited()) {
// when select GV$OPEN_CURSOR, we will add get_thread_data_lock to fetch pl_cursor_map_
// so we need get_thread_data_lock there
ObSQLSessionInfo::LockGuard lock_guard(get_thread_data_lock());
pl_cursor_cache_.reset();
}
inner_conn_ = NULL;
@ -1190,7 +1193,11 @@ int ObSQLSessionInfo::add_cursor(pl::ObPLCursorInfo *cursor)
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(pl_cursor_cache_.pl_cursor_map_.set_refactored(id, cursor))) {
} else {
// when select GV$OPEN_CURSOR, we will add get_thread_data_lock to fetch pl_cursor_map_
// so we need get_thread_data_lock there
ObSQLSessionInfo::LockGuard lock_guard(get_thread_data_lock());
if (OB_FAIL(pl_cursor_cache_.pl_cursor_map_.set_refactored(id, cursor))) {
LOG_WARN("fail insert ps id to hash map", K(id), K(*cursor), K(ret));
} else {
cursor->set_id(id);
@ -1202,6 +1209,7 @@ int ObSQLSessionInfo::add_cursor(pl::ObPLCursorInfo *cursor)
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);
@ -1234,6 +1242,9 @@ int ObSQLSessionInfo::close_cursor(int64_t cursor_id)
int ret = OB_SUCCESS;
ObPLCursorInfo *cursor = NULL;
LOG_INFO("ps cursor : remove cursor", K(ret), K(cursor_id), K(get_sessid()));
// when select GV$OPEN_CURSOR, we will add get_thread_data_lock to fetch pl_cursor_map_
// so we need get_thread_data_lock there
ObSQLSessionInfo::LockGuard lock_guard(get_thread_data_lock());
if (OB_FAIL(pl_cursor_cache_.pl_cursor_map_.erase_refactored(cursor_id, &cursor))) {
LOG_WARN("cursor info not exist", K(cursor_id));
} else if (OB_ISNULL(cursor)) {
@ -1286,6 +1297,9 @@ int ObSQLSessionInfo::init_cursor_cache()
{
int ret = OB_SUCCESS;
if (!pl_cursor_cache_.is_inited()) {
// when select GV$OPEN_CURSOR, we will add get_thread_data_lock to fetch pl_cursor_map_
// so we need get_thread_data_lock there
ObSQLSessionInfo::LockGuard lock_guard(get_thread_data_lock());
OZ (pl_cursor_cache_.init(get_effective_tenant_id()),
get_effective_tenant_id(),
get_proxy_sessid(),
@ -1299,6 +1313,9 @@ int ObSQLSessionInfo::close_dbms_cursor(int64_t cursor_id)
int ret = OB_SUCCESS;
ObPLCursorInfo *cursor = NULL;
LOG_INFO("remove dbms cursor", K(ret), K(cursor_id), K(get_sessid()));
// when select GV$OPEN_CURSOR, we will add get_thread_data_lock to fetch pl_cursor_map_
// so we need get_thread_data_lock there
ObSQLSessionInfo::LockGuard lock_guard(get_thread_data_lock());
OZ (pl_cursor_cache_.pl_cursor_map_.erase_refactored(cursor_id, &cursor), cursor_id);
OV (OB_NOT_NULL(cursor), OB_ERR_UNEXPECTED, cursor_id);
if (OB_SUCC(ret) && lib::is_diagnose_info_enabled()) {