[to #2024082000104197520] fix memory leak of session cursor & fix var%notfound

This commit is contained in:
obdev 2024-08-27 12:14:26 +00:00 committed by ob-robot
parent 502c2b251d
commit ee76b4deb8
6 changed files with 62 additions and 23 deletions

File diff suppressed because one or more lines are too long

View File

@ -2645,6 +2645,8 @@ DEFINE_ERROR(OB_ERR_EVENT_RECURSION_FORBIDDEN, -9780, ER_EVENT_RECURSION_FORBIDD
DEFINE_ORACLE_ERROR(OB_NO_PARTITION_FOR_GIVEN_VALUE_SCHEMA_ERROR, -9781, ER_NO_PARTITION_FOR_GIVEN_VALUE, "HY000", "Table has no partition for value", 14400, "inserted partition key does not map to any partition");
DEFINE_ORACLE_ERROR(OB_ERR_INVALID_CHARACTER, -9782, -1, "HY000", "invalid character", 911, "invalid character");
DEFINE_ORACLE_ERROR_EXT(OB_ERR_MVIEW_CAN_NOT_ON_QUERY_COMPUTE, -9783, -1, "HY000", "cannot ENABLE ON QUERY COMPUTATION for the materialized view", "cannot ENABLE ON QUERY COMPUTATION for the materialized view `%s`.`%s`", 32361, "cannot ENABLE ON QUERY COMPUTATION for the materialized view", "cannot ENABLE ON QUERY COMPUTATION for the materialized view %s.%s");
DEFINE_PLS_ERROR_EXT(OB_ERR_CURSOR_ATTR_APPLY, -9784, -1, "HY000", "cursor attribute may not be applied to non-cursor", "cursor attribute may not be applied to non-cursor %.*s", 324, "cursor attribute may not be applied to non-cursor", "cursor attribute may not be applied to non-cursor %.*s");
//
////////////////////////////////////////////////////////////////
// PL/SQL错误码值域 [-9500, -10000)

View File

@ -1869,6 +1869,7 @@ constexpr int OB_ERR_EVENT_RECURSION_FORBIDDEN = -9780;
constexpr int OB_NO_PARTITION_FOR_GIVEN_VALUE_SCHEMA_ERROR = -9781;
constexpr int OB_ERR_INVALID_CHARACTER = -9782;
constexpr int OB_ERR_MVIEW_CAN_NOT_ON_QUERY_COMPUTE = -9783;
constexpr int OB_ERR_CURSOR_ATTR_APPLY = -9784;
constexpr int OB_ERR_KV_GLOBAL_INDEX_ROUTE = -10500;
constexpr int OB_TTL_NOT_ENABLE = -10501;
constexpr int OB_TTL_COLUMN_NOT_EXIST = -10502;
@ -4173,6 +4174,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
#define OB_NO_PARTITION_FOR_GIVEN_VALUE_SCHEMA_ERROR__USER_ERROR_MSG "Table has no partition for value"
#define OB_ERR_INVALID_CHARACTER__USER_ERROR_MSG "invalid character"
#define OB_ERR_MVIEW_CAN_NOT_ON_QUERY_COMPUTE__USER_ERROR_MSG "cannot ENABLE ON QUERY COMPUTATION for the materialized view `%s`.`%s`"
#define OB_ERR_CURSOR_ATTR_APPLY__USER_ERROR_MSG "cursor attribute may not be applied to non-cursor %.*s"
#define OB_ERR_KV_GLOBAL_INDEX_ROUTE__USER_ERROR_MSG "incorrect route for obkv global index, client router should refresh."
#define OB_TTL_NOT_ENABLE__USER_ERROR_MSG "TTL feature is not enabled"
#define OB_TTL_COLUMN_NOT_EXIST__USER_ERROR_MSG "TTL column '%.*s' not exists"
@ -8753,6 +8755,8 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
#define OB_ERR_INVALID_CHARACTER__OBE_USER_ERROR_MSG "OBE-00911: invalid character"
#define OB_ERR_MVIEW_CAN_NOT_ON_QUERY_COMPUTE__ORA_USER_ERROR_MSG "ORA-32361: cannot ENABLE ON QUERY COMPUTATION for the materialized view %s.%s"
#define OB_ERR_MVIEW_CAN_NOT_ON_QUERY_COMPUTE__OBE_USER_ERROR_MSG "OBE-32361: cannot ENABLE ON QUERY COMPUTATION for the materialized view %s.%s"
#define OB_ERR_CURSOR_ATTR_APPLY__ORA_USER_ERROR_MSG "PLS-00324: cursor attribute may not be applied to non-cursor %.*s"
#define OB_ERR_CURSOR_ATTR_APPLY__OBE_USER_ERROR_MSG "PLS-00324: cursor attribute may not be applied to non-cursor %.*s"
#define OB_ERR_KV_GLOBAL_INDEX_ROUTE__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -10500, incorrect route for obkv global index, client router should refresh."
#define OB_ERR_KV_GLOBAL_INDEX_ROUTE__OBE_USER_ERROR_MSG "OBE-00600: internal error code, arguments: -10500, incorrect route for obkv global index, client router should refresh."
#define OB_TTL_NOT_ENABLE__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -10501, TTL feature is not enabled"
@ -8914,7 +8918,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219;
#define OB_ERR_INVALID_DATE_MSG_FMT_V2__ORA_USER_ERROR_MSG "ORA-01861: Incorrect datetime value for column '%.*s' at row %ld"
#define OB_ERR_INVALID_DATE_MSG_FMT_V2__OBE_USER_ERROR_MSG "OBE-01861: Incorrect datetime value for column '%.*s' at row %ld"
extern int g_all_ob_errnos[2327];
extern int g_all_ob_errnos[2328];
const char *ob_error_name(const int oberr);
const char* ob_error_cause(const int oberr);

View File

@ -211,6 +211,12 @@ int ObExprPLGetCursorAttr::calc_pl_get_cursor_attr(
if (info->pl_cursor_info_.is_explicit_cursor()) {
CK (ObExtendType == datum_meta.type_);
OX (datum->to_obj(obj, obj_meta));
if (OB_SUCC(ret)
&& obj.get_meta().get_extend_type() != pl::PL_CURSOR_TYPE
&& obj.get_meta().get_extend_type() != pl::PL_REF_CURSOR_TYPE) {
ret = OB_ERR_CURSOR_ATTR_APPLY;
LOG_WARN("cursor attribute may not applied to non-cursor", K(ret), K(obj.get_meta()));
}
OX (cursor = reinterpret_cast<const pl::ObPLCursorInfo*>(obj.get_ext()));
} else {
if (OB_ISNULL(cursor = session->get_pl_implicit_cursor())) {

View File

@ -705,14 +705,16 @@ void ObSQLSessionInfo::destroy(bool skip_sys_var)
}
//close all cursor
if (OB_SUCC(ret) && pl_cursor_cache_.is_inited()) {
if (OB_FAIL(pl_cursor_cache_.close_all(*this))) {
if (pl_cursor_cache_.is_inited()) {
int temp_ret = pl_cursor_cache_.close_all(*this);
if (temp_ret != OB_SUCCESS) {
LOG_WARN("failed to close all cursor", K(ret));
}
}
if (OB_SUCC(ret) && NULL != piece_cache_) {
if (OB_FAIL(piece_cache_->close_all(*this))) {
if (NULL != piece_cache_) {
int temp_ret = piece_cache_->close_all(*this);
if (temp_ret != OB_SUCCESS) {
LOG_WARN("failed to close all piece", K(ret));
}
piece_cache_->~ObPieceCache();

View File

@ -639,37 +639,47 @@ public:
} else { /*do nothing*/ }
return ret;
}
int close_all(sql::ObSQLSessionInfo &session)
{
int ret = OB_SUCCESS;
common::ObSEArray<uint64_t, 32> cursor_ids;
ObSessionStatEstGuard guard(session.get_effective_tenant_id(), session.get_sessid());
for (CursorMap::iterator iter = pl_cursor_map_.begin(); //ignore ret
iter != pl_cursor_map_.end();
++iter) {
pl::ObPLCursorInfo *cursor_info = iter->second;
if (OB_ISNULL(cursor_info)) {
while (pl_cursor_map_.size() > 0) { // ignore error, just log, try to close all cursor in this loop.
int ret = OB_SUCCESS;
CursorMap::iterator iter = pl_cursor_map_.begin();
pl::ObPLCursorInfo *cursor = NULL;
if (iter == pl_cursor_map_.end()) {
ret = OB_ERR_UNEXPECTED;
SQL_ENG_LOG(WARN, "cursor info is NULL", K(cursor_info), K(ret));
SQL_ENG_LOG(ERROR, "unexpected hashmap iter", K(ret));
break;
} else if (OB_ISNULL(cursor = iter->second)) {
ret = OB_ERR_UNEXPECTED;
SQL_ENG_LOG(WARN, "unexpected nullptr cursor info", K(ret), K(iter->first));
if (OB_FAIL(pl_cursor_map_.erase_refactored(iter->first))) {
SQL_ENG_LOG(ERROR, "failed to erase hash map", K(ret), K(iter->first));
break;
}
} else if (OB_FAIL(session.close_cursor(cursor->get_id()))) {
SQL_ENG_LOG(WARN, "failed to close session cursor", K(ret), K(cursor->get_id()));
} else {
cursor_ids.push_back(cursor_info->get_id());
SQL_ENG_LOG(INFO, "clsoe session cursor implicit successed!", K(cursor->get_id()));
}
}
for (int64_t i = 0; i < cursor_ids.count() && OB_SUCC(ret); i++) {
uint64_t cursor_id = cursor_ids.at(i);
if (OB_FAIL(session.close_cursor(cursor_id))) {
SQL_ENG_LOG(WARN, "failed to close cursor",
K(cursor_id), K(session.get_sessid()), K(ret));
} else {
SQL_ENG_LOG(INFO, "NOTICE: cursor is closed unexpectedly",
K(cursor_id), K(session.get_sessid()), K(ret));
}
if (pl_cursor_map_.size() > 0) {
ret = OB_ERR_UNEXPECTED;
SQL_ENG_LOG(ERROR, "failed to close all cursor", K(ret), K(pl_cursor_map_.size()));
}
return ret;
}
inline bool is_inited() const { return NULL != mem_context_; }
void reset()
{
int ret = OB_SUCCESS;
if (pl_cursor_map_.size() != 0) {
ret = OB_ERR_UNEXPECTED;
SQL_ENG_LOG(ERROR, "session cursor map not empty, cursor leaked", K(pl_cursor_map_.size()));
}
pl_cursor_map_.reuse();
next_cursor_id_ = 1LL << 31;
if (NULL != mem_context_) {