From 659402ae3237b05ab21ba953bef05b142823c52d Mon Sep 17 00:00:00 2001 From: zzg19950727 <1071026277@qq.com> Date: Fri, 8 Sep 2023 12:43:14 +0800 Subject: [PATCH] fix dblink unknown error code --- .../lib/mysqlclient/ob_dblink_error_trans.cpp | 43 ++++++------------- .../lib/mysqlclient/ob_mysql_connection.cpp | 4 +- src/share/ob_errno.cpp | 8 ++-- src/share/ob_errno.def | 2 +- src/share/ob_errno.h | 4 +- 5 files changed, 21 insertions(+), 40 deletions(-) diff --git a/deps/oblib/src/lib/mysqlclient/ob_dblink_error_trans.cpp b/deps/oblib/src/lib/mysqlclient/ob_dblink_error_trans.cpp index d0dcd20322..66258f97f3 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_dblink_error_trans.cpp +++ b/deps/oblib/src/lib/mysqlclient/ob_dblink_error_trans.cpp @@ -12,6 +12,7 @@ #define USING_LOG_PREFIX LIB_MYSQLC #include "lib/mysqlclient/ob_dblink_error_trans.h" +#include "share/ob_errno.h" int __attribute__((weak)) get_oracle_errno(int index) { @@ -56,39 +57,19 @@ int sqlclient::ObDblinkErrorTrans::external_errno_to_ob_errno(bool is_oracle_err std::min(STRLEN(oracle_msg_prefix), STRLEN(external_errmsg)))))) { ob_errno = external_errno; // do not map, show user client errno directly. } else { - ob_errno = OB_ERR_DBLINK_REMOTE_ECODE; // default ob_errno, if external_errno can not map to any valid ob_errno - if (OB_ISNULL(external_errmsg) || 0 == STRLEN(external_errmsg)) { - for (int i = 0; i < oceanbase::common::OB_MAX_ERROR_CODE; ++i) { - if (external_errno == (is_oracle_err ? get_oracle_errno(i) : get_mysql_errno(i))) { - ob_errno = -i; - break; - } - } - } else { - ObEditDistance ed; - int64_t edit_dist = 0x7fffffffffffffff; - int64_t min_edit_dist = 0x7fffffffffffffff; - for (int i = 0; i < oceanbase::common::OB_MAX_ERROR_CODE; ++i) { - if (external_errno == (is_oracle_err ? get_oracle_errno(i) : get_mysql_errno(i))) { - const char *external_errstr = (is_oracle_err ? get_oracle_str_error(i) : get_mysql_str_error(i)); - if (OB_ISNULL(external_errstr)) { - // In the case of a null pointer boundary - edit_dist = 0x7ffffffffffffffe; - } else { - // The edit distance between the strings is used to measure their similarity. - // The smaller the edit distance, the greater the similarity, so as to find the most similar error message. - ObEditDistance::cal_edit_distance(external_errmsg, external_errstr, STRLEN(external_errmsg), STRLEN(external_errstr), edit_dist); - } - if (edit_dist < min_edit_dist) { - ob_errno = -i; - min_edit_dist = edit_dist; - if (0 == min_edit_dist) { - break; - } - } - } + int64_t match_count = 0; + for (int i = 0; i < oceanbase::common::OB_MAX_ERROR_CODE; ++i) { + if (external_errno == (is_oracle_err ? get_oracle_errno(i) : get_mysql_errno(i))) { + ob_errno = -i; + ++match_count; } } + if (1 != match_count) { + // default ob_errno, if external_errno can not map to any valid ob_errno + ob_errno = OB_ERR_DBLINK_REMOTE_ECODE; + int msg_len = STRLEN(external_errmsg); + LOG_USER_ERROR(OB_ERR_DBLINK_REMOTE_ECODE, external_errno, msg_len, external_errmsg); + } } } return ret; diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_connection.cpp b/deps/oblib/src/lib/mysqlclient/ob_mysql_connection.cpp index 7ea2e9397d..b18165ea85 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_connection.cpp +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_connection.cpp @@ -560,8 +560,8 @@ int ObMySQLConnection::execute_read(const uint64_t tenant_id, const char *sql, LOG_WARN("create statement failed", KCSTRING(sql), K(ret)); } else if (OB_ISNULL(read_ctx->result_ = read_ctx->stmt_.execute_query(res.is_enable_use_result()))) { ret = get_last_error(); - const int ER_LOCK_WAIT_TIMEOUT = -1205; - if (ER_LOCK_WAIT_TIMEOUT == ret) { + //const int ER_LOCK_WAIT_TIMEOUT = -1205; + if (-1205 == ret) { LOG_INFO("query failed", K(get_server()), KCSTRING(sql), K(ret)); } else { LOG_WARN("query failed", K(get_server()), KCSTRING(sql), K(ret)); diff --git a/src/share/ob_errno.cpp b/src/share/ob_errno.cpp index 9e68694b46..8389563631 100755 --- a/src/share/ob_errno.cpp +++ b/src/share/ob_errno.cpp @@ -17583,11 +17583,11 @@ static const _error _error_OB_ERR_DBLINK_REMOTE_ECODE = { .error_solution = "Contact OceanBase Support", .mysql_errno = -1, .sqlstate = "HY000", - .str_error = "Unknown errorcode: %d", - .str_user_error = "Unknown errorcode: %d", + .str_error = "\ndblink remote error code: %d,\nremote error msg: %.*s", + .str_user_error = "\ndblink remote error code: %d,\nremote error msg: %.*s", .oracle_errno = 600, - .oracle_str_error = "ORA-00600: internal error code, arguments: -5975, Unknown errorcode: %d", - .oracle_str_user_error = "ORA-00600: internal error code, arguments: -5975, Unknown errorcode: %d" + .oracle_str_error = "ORA-00600: internal error code, arguments: -5975, \ndblink remote error code: %d,\nremote error msg: %.*s", + .oracle_str_user_error = "ORA-00600: internal error code, arguments: -5975, \ndblink remote error code: %d,\nremote error msg: %.*s" }; static const _error _error_OB_ERR_DBLINK_NO_LIB = { .error_name = "OB_ERR_DBLINK_NO_LIB", diff --git a/src/share/ob_errno.def b/src/share/ob_errno.def index aaa4f3e958..fe33924d64 100755 --- a/src/share/ob_errno.def +++ b/src/share/ob_errno.def @@ -1612,7 +1612,7 @@ DEFINE_ORACLE_ERROR_EXT(OB_ERR_CHECK_OPTION_VIOLATED, -5971, ER_VIEW_CHECK_FAILE DEFINE_ERROR_EXT(OB_ERR_CHECK_OPTION_ON_NONUPDATABLE_VIEW, -5972, ER_VIEW_NONUPD_CHECK, "HY000", "CHECK OPTION on non-updatable view", "CHECK OPTION on non-updatable view '%.*s.%.*s'"); DEFINE_ORACLE_ERROR(OB_ERR_NO_DESC_FOR_POS, -5973, -1, "HY000", "no descriptor for this position", 24334, "no descriptor for this position"); DEFINE_ORACLE_ERROR(OB_ERR_ILL_OBJ_FLAG, -5974, -1, "HY000", "object specified is incompatible with the flag specified", 4047, "object specified is incompatible with the flag specified"); -DEFINE_ERROR_DEP(OB_ERR_DBLINK_REMOTE_ECODE, -5975, -1, "HY000", "Unknown errorcode: %d", "dblink remote ora error code: %d"); +DEFINE_ERROR_DEP(OB_ERR_DBLINK_REMOTE_ECODE, -5975, -1, "HY000", "\ndblink remote error code: %d,\nremote error msg: %.*s", "\ndblink remote error code: %d,\nremote error msg: %.*s"); DEFINE_ERROR_DEP(OB_ERR_DBLINK_NO_LIB, -5976, -1, "HY000", "oci lib not founded"); DEFINE_ORACLE_ERROR(OB_ERR_PARTITION_EXTENDED_ON_VIEW, -5977, -1, "HY000", "partition-extended object names may only be used with tables and editioning views", 14109, "partition-extended object names may only be used with tables and editioning views"); DEFINE_ORACLE_ERROR(OB_ERR_NOT_ALL_VARIABLE_BIND, -5978, -1, "HY000", "not all variables bound", 1008, "not all variables bound"); diff --git a/src/share/ob_errno.h b/src/share/ob_errno.h index e9a10d77d3..eab01fc288 100755 --- a/src/share/ob_errno.h +++ b/src/share/ob_errno.h @@ -3251,7 +3251,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219; #define OB_ERR_CHECK_OPTION_ON_NONUPDATABLE_VIEW__USER_ERROR_MSG "CHECK OPTION on non-updatable view '%.*s.%.*s'" #define OB_ERR_NO_DESC_FOR_POS__USER_ERROR_MSG "no descriptor for this position" #define OB_ERR_ILL_OBJ_FLAG__USER_ERROR_MSG "object specified is incompatible with the flag specified" -#define OB_ERR_DBLINK_REMOTE_ECODE__USER_ERROR_MSG "Unknown errorcode: %d" +#define OB_ERR_DBLINK_REMOTE_ECODE__USER_ERROR_MSG "\ndblink remote error code: %d,\nremote error msg: %.*s" #define OB_ERR_DBLINK_NO_LIB__USER_ERROR_MSG "oci lib not founded" #define OB_ERR_PARTITION_EXTENDED_ON_VIEW__USER_ERROR_MSG "partition-extended object names may only be used with tables and editioning views" #define OB_ERR_NOT_ALL_VARIABLE_BIND__USER_ERROR_MSG "not all variables bound" @@ -5379,7 +5379,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219; #define OB_ERR_CHECK_OPTION_ON_NONUPDATABLE_VIEW__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5972, CHECK OPTION on non-updatable view '%.*s.%.*s'" #define OB_ERR_NO_DESC_FOR_POS__ORA_USER_ERROR_MSG "ORA-24334: no descriptor for this position" #define OB_ERR_ILL_OBJ_FLAG__ORA_USER_ERROR_MSG "ORA-04047: object specified is incompatible with the flag specified" -#define OB_ERR_DBLINK_REMOTE_ECODE__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5975, Unknown errorcode: %d" +#define OB_ERR_DBLINK_REMOTE_ECODE__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5975, \ndblink remote error code: %d,\nremote error msg: %.*s" #define OB_ERR_DBLINK_NO_LIB__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5976, oci lib not founded" #define OB_ERR_PARTITION_EXTENDED_ON_VIEW__ORA_USER_ERROR_MSG "ORA-14109: partition-extended object names may only be used with tables and editioning views" #define OB_ERR_NOT_ALL_VARIABLE_BIND__ORA_USER_ERROR_MSG "ORA-01008: not all variables bound"