Fix:session self-validation error

This commit is contained in:
yaojing624 2023-05-10 04:57:37 +00:00 committed by ob-robot
parent 25b2740486
commit f27495534e
6 changed files with 31 additions and 2 deletions

View File

@ -23,6 +23,7 @@
#include "sql/session/ob_sql_session_mgr.h"
#include "observer/mysql/obmp_utils.h"
#include "observer/mysql/ob_mysql_result_set.h"
#include "sql/session/ob_sess_info_verify.h"
namespace oceanbase
{
@ -271,6 +272,11 @@ int ObMPPacketSender::response_packet(obmysql::ObMySQLPacket &pkt, sql::ObSQLSes
}
}
if (OB_FAIL(ret)) {
} else if (FALSE_IT(ObSessInfoVerify::sess_veri_control(pkt, session))) {
// do nothing.
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(alloc_ezbuf())) {
LOG_ERROR("easy buffer alloc failed", K(ret));

View File

@ -2380,9 +2380,11 @@ int ObSessInfoVerificationP::process()
// 1. Broken link reuse session,need verify proxy sess id
// 2. Mixed running scene, need verify version
// 3. Routing without synchronizing session information, judge is_has_query_executed
// 4. need guarantee the latest session information
if (arg_.get_proxy_sess_id() == session->get_proxy_sessid() &&
GET_MIN_CLUSTER_VERSION() == CLUSTER_CURRENT_VERSION &&
session->is_has_query_executed()
session->is_has_query_executed() &&
session->is_latest_sess_info()
) {
if (OB_FAIL(ObSessInfoVerify::fetch_verify_session_info(*session,
str_result, result_.allocator_))) {

View File

@ -503,6 +503,21 @@ int ObSessInfoVerify::create_tmp_sys_var(sql::ObSQLSessionInfo &sess,
return ret;
}
int ObSessInfoVerify::sess_veri_control(obmysql::ObMySQLPacket &pkt, sql::ObSQLSessionInfo *&session)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(session)) {
// do nothing
} else if (pkt.get_mysql_packet_type() == ObMySQLPacketType::PKT_ERR) {
// when error scene, can not guarantee the latest session information
session->set_latest_sess_info(false);
} else {
// when other scene, can guarantee the latest session information
session->set_latest_sess_info(true);
}
return ret;
}
// this function use for get another session id when 1:1 server list test
bool GetAnotherSessID::operator()(ObSQLSessionMgr::Key key,
ObSQLSessionInfo *sess_info)

View File

@ -100,6 +100,7 @@ public:
static int create_tmp_sys_var(sql::ObSQLSessionInfo &sess,
share::ObSysVarClassType sys_var_id, share::ObBasicSysVar *&sys_var,
common::ObIAllocator &allocator);
static int sess_veri_control(obmysql::ObMySQLPacket &pkt, sql::ObSQLSessionInfo *&session);
};
class GetAnotherSessID

View File

@ -175,6 +175,7 @@ ObSQLSessionInfo::ObSQLSessionInfo() :
conn_res_user_id_(OB_INVALID_ID),
mem_context_(nullptr),
has_query_executed_(false),
is_latest_sess_info_(false),
cur_exec_ctx_(nullptr),
restore_auto_commit_(false),
dblink_context_(this),
@ -331,6 +332,7 @@ void ObSQLSessionInfo::reset(bool skip_sys_var)
coninfo_set_by_sess_ = false;
is_ob20_protocol_ = false;
is_session_var_sync_ = false;
is_latest_sess_info_ = false;
int temp_ret = OB_SUCCESS;
sql_req_level_ = 0;
optimizer_tracer_.reset();

View File

@ -637,7 +637,9 @@ public:
bool is_has_query_executed() {return has_query_executed_; }
void set_has_query_executed(bool has_query_executed) {
has_query_executed_ = has_query_executed; }
bool is_latest_sess_info() {return is_latest_sess_info_; }
void set_latest_sess_info(bool is_latest_sess_info) {
is_latest_sess_info_ = is_latest_sess_info; }
void reset_warnings_buf()
{
@ -1248,6 +1250,7 @@ private:
// There is a scenario, when the connection is established for the first time,
// the route is immediately switched and no request is initiated, and no verification is required at this time
bool has_query_executed_; //add for routing without synchronizing session information
bool is_latest_sess_info_; //add for the current session information is latest flag
char module_buf_[common::OB_MAX_MOD_NAME_LENGTH];
char action_buf_[common::OB_MAX_ACT_NAME_LENGTH];
char client_info_buf_[common::OB_MAX_CLIENT_INFO_LENGTH];