diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_connection.cpp b/deps/oblib/src/lib/mysqlclient/ob_mysql_connection.cpp index 916b8a2df5..e0466d60ad 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_connection.cpp +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_connection.cpp @@ -234,6 +234,15 @@ int ObMySQLConnection::connect(const char *user, const char *pass, const char *d LOG_WARN("fail to connect to mysql server", K(get_sessid()), KCSTRING(host), KCSTRING(user), KCSTRING(db), K(port), "info", mysql_error(&mysql_), K(ret)); if (OB_INVALID_ID != get_dblink_id()) { + LOG_WARN("dblink connection error", K(ret), + KP(this), + K(get_dblink_id()), + K(get_sessid()), + K(usable()), + K(user), + K(db), + K(host), + K(port)); TRANSLATE_CLIENT_ERR_2(ret, false, mysql_error(&mysql_)); } } else { diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_result.cpp b/deps/oblib/src/lib/mysqlclient/ob_mysql_result.cpp index 38a8b1b0b7..f0174ac9f4 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_result.cpp +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_result.cpp @@ -86,12 +86,20 @@ int ObMySQLResult::format_precision_scale_length(int16_t &precision, int16_t &sc // format precision from others to oceanbase if (!lib::is_oracle_mode()) { switch (ob_type) { - case ObUNumberType: - case ObNumberType: { // for mysql decimal - if (2 == length) { - precision = 1; + case ObUNumberType:{ + if (0 != scale) { + precision = length - 1;// remove length of decimal point } else { - precision = length - 1; + precision = length; + } + length = -1; + break; + } + case ObNumberType: { + if (0 != scale) { + precision = length - 2;// remove length of decimal point and sign(-/+) + } else { + precision = length - 1;// remove length of decimal point } length = -1; break; diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_result_impl.cpp b/deps/oblib/src/lib/mysqlclient/ob_mysql_result_impl.cpp index 4601115a97..631cd25823 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_result_impl.cpp +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_result_impl.cpp @@ -23,6 +23,7 @@ #include "common/ob_zerofill_info.h" #include "lib/timezone/ob_timezone_info.h" #include "lib/string/ob_hex_utils_base.h" +#include "lib/mysqlclient/ob_dblink_error_trans.h" namespace oceanbase { @@ -143,7 +144,33 @@ int ObMySQLResultImpl::next() ret = OB_ERR_UNEXPECTED; LOG_ERROR("result must not be null", K(ret)); } else if (OB_ISNULL(cur_row_ = mysql_fetch_row(result_))) { - ret = OB_ITER_END; + MYSQL *stmt_handler = stmt_.get_stmt_handler(); + if (OB_ISNULL(stmt_handler)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected null ptr", K(ret)); + } else { + ret = -mysql_errno(stmt_handler); + const char *errmsg = mysql_error(stmt_handler); + ObMySQLConnection *conn = stmt_.get_connection(); + if (0 == ret) { + ret = OB_ITER_END; + } else if (OB_ISNULL(conn)) { + int tmp_ret = ret; + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected null ptr", K(errmsg), K(tmp_ret), K(ret)); + } else if (OB_INVALID_ID != conn->get_dblink_id()) { + LOG_WARN("dblink connection error", K(ret), + KP(conn), + K(conn->get_dblink_id()), + K(conn->get_sessid()), + K(conn->usable()), + K(conn->ping())); + TRANSLATE_CLIENT_ERR(ret, errmsg); + if (ObMySQLStatement::is_need_disconnect_error(ret)) { + conn->set_usable(false); + } + } + } } else if (OB_ISNULL(cur_row_result_lengths_ = mysql_fetch_lengths(result_))) { ret = OB_ERR_UNEXPECTED; LOG_WARN("calling is out of sync", K(ret)); diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp b/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp index 8ef4153474..7ce9f5fceb 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp @@ -108,6 +108,17 @@ int ObMySQLStatement::execute_update(int64_t &affected_rows) conn_->get_root()->get_root()->signal_refresh(); // refresh server pool immediately } if (OB_INVALID_ID != conn_->get_dblink_id()) { + LOG_WARN("dblink connection error", K(ret), + KP(conn_), + K(conn_->get_dblink_id()), + K(conn_->get_sessid()), + K(conn_->usable()), + K(conn_->ping()), + K(stmt_->host), + K(stmt_->port), + K(mysql_error(stmt_)), + K(STRLEN(sql_str_)), + K(sql_str_)); TRANSLATE_CLIENT_ERR(ret, mysql_error(stmt_)); } if (is_need_disconnect_error(ret)) { @@ -151,6 +162,17 @@ ObMySQLResult *ObMySQLStatement::execute_query(bool enable_use_result) ret = OB_ERR_SQL_CLIENT; LOG_WARN("can not get errno", K(ret)); } else if (OB_INVALID_ID != conn_->get_dblink_id()) { + LOG_WARN("dblink connection error", K(ret), + KP(conn_), + K(conn_->get_dblink_id()), + K(conn_->get_sessid()), + K(conn_->usable()), + K(conn_->ping()), + K(stmt_->host), + K(stmt_->port), + K(mysql_error(stmt_)), + K(STRLEN(sql_str_)), + K(sql_str_)); TRANSLATE_CLIENT_ERR(ret, mysql_error(stmt_)); } if (is_need_disconnect_error(ret)) { diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.h b/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.h index 1b825a4647..9a40d9e792 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.h +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.h @@ -50,7 +50,7 @@ public: * but ignore affected_rows */ int execute_update(); - bool is_need_disconnect_error(int ret); + static bool is_need_disconnect_error(int ret); /* * ! Deprecated