From 2ad78b0e634c6825cc34515ae3ae77007d01845a Mon Sep 17 00:00:00 2001 From: obdev Date: Tue, 4 Apr 2023 03:41:57 +0000 Subject: [PATCH] Replace ps inner stmt id calculated position in sql audit --- src/observer/mysql/obmp_stmt_execute.cpp | 13 +++++++++---- src/observer/mysql/obmp_stmt_execute.h | 3 ++- src/observer/mysql/obmp_stmt_fetch.cpp | 1 + src/observer/mysql/obmp_stmt_get_piece_data.cpp | 1 + src/observer/mysql/obmp_stmt_prepare.cpp | 6 ++++++ src/observer/mysql/obmp_stmt_prexecute.cpp | 4 +++- src/observer/mysql/obmp_stmt_prexecute.h | 3 ++- src/observer/mysql/obmp_stmt_send_piece_data.cpp | 1 + src/observer/ob_inner_sql_connection.cpp | 1 + src/sql/session/ob_sql_session_info.cpp | 8 -------- 10 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/observer/mysql/obmp_stmt_execute.cpp b/src/observer/mysql/obmp_stmt_execute.cpp index 364908b21..46007590b 100644 --- a/src/observer/mysql/obmp_stmt_execute.cpp +++ b/src/observer/mysql/obmp_stmt_execute.cpp @@ -962,10 +962,11 @@ int ObMPStmtExecute::execute_response(ObSQLSessionInfo &session, bool &is_diagnostics_stmt, int64_t &execution_id, const bool force_sync_resp, - bool &async_resp_used) + bool &async_resp_used, + ObPsStmtId &inner_stmt_id) { int ret = OB_SUCCESS; - ObPsStmtId inner_stmt_id = OB_INVALID_ID; + inner_stmt_id = OB_INVALID_ID; ObIAllocator &alloc = CURRENT_CONTEXT->get_arena_allocator(); if (OB_ISNULL(session.get_ps_cache())) { ret = OB_ERR_UNEXPECTED; @@ -1103,6 +1104,7 @@ int ObMPStmtExecute::do_process(ObSQLSessionInfo &session, ObAuditRecordData &audit_record = session.get_raw_audit_record(); audit_record.try_cnt_++; bool is_diagnostics_stmt = false; + ObPsStmtId inner_stmt_id = OB_INVALID_ID; bool need_response_error = is_arraybinding_ ? false : true; const bool enable_perf_event = lib::is_diagnose_info_enabled(); const bool enable_sql_audit = @@ -1165,7 +1167,8 @@ int ObMPStmtExecute::do_process(ObSQLSessionInfo &session, is_diagnostics_stmt, execution_id, force_sync_resp, - async_resp_used); + async_resp_used, + inner_stmt_id); } else { ret = execute_response(session, result, @@ -1174,7 +1177,8 @@ int ObMPStmtExecute::do_process(ObSQLSessionInfo &session, is_diagnostics_stmt, execution_id, force_sync_resp, - async_resp_used); + async_resp_used, + inner_stmt_id); } if ((OB_SUCC(ret) && is_diagnostics_stmt) || async_resp_used) { // if diagnostic stmt succeed, no need to clear warning buf. @@ -1257,6 +1261,7 @@ int ObMPStmtExecute::do_process(ObSQLSessionInfo &session, audit_record.sql_len_ = min(ctx_.cur_sql_.length(), OB_MAX_SQL_LENGTH); audit_record.sql_cs_type_ = session.get_local_collation_connection(); audit_record.ps_stmt_id_ = stmt_id_; + audit_record.ps_inner_stmt_id_ = inner_stmt_id; audit_record.params_value_ = params_value_; audit_record.params_value_len_ = params_value_len_; diff --git a/src/observer/mysql/obmp_stmt_execute.h b/src/observer/mysql/obmp_stmt_execute.h index cb3bfecdb..213596203 100644 --- a/src/observer/mysql/obmp_stmt_execute.h +++ b/src/observer/mysql/obmp_stmt_execute.h @@ -176,7 +176,8 @@ protected: bool &is_diagnostics_stmt, int64_t &execution_id, const bool force_sync_resp, - bool &async_resp_used); + bool &async_resp_used, + ObPsStmtId &inner_stmt_id); virtual bool is_prexecute() const { return false; } inline bool is_execute_ps_cursor() { return ObExecutePsCursorType == ps_cursor_type_; } inline bool is_prexecute_ps_cursor() { return ObPrexecutePsCursorType == ps_cursor_type_; } diff --git a/src/observer/mysql/obmp_stmt_fetch.cpp b/src/observer/mysql/obmp_stmt_fetch.cpp index cc34328ef..45640f7a8 100644 --- a/src/observer/mysql/obmp_stmt_fetch.cpp +++ b/src/observer/mysql/obmp_stmt_fetch.cpp @@ -234,6 +234,7 @@ int ObMPStmtFetch::do_process(ObSQLSessionInfo &session) if (OB_SUCC(session.get_inner_ps_stmt_id(cursor_id_, inner_stmt_id)) && OB_SUCC(session.get_ps_cache()->get_stmt_info_guard(inner_stmt_id, guard)) && OB_NOT_NULL(ps_info = guard.get_stmt_info())) { + audit_record.ps_inner_stmt_id_ = inner_stmt_id; audit_record.sql_ = const_cast(ps_info->get_ps_sql().ptr()); audit_record.sql_len_ = min(ps_info->get_ps_sql().length(), OB_MAX_SQL_LENGTH); } else { diff --git a/src/observer/mysql/obmp_stmt_get_piece_data.cpp b/src/observer/mysql/obmp_stmt_get_piece_data.cpp index 5c449d6ad..d6938d1f5 100644 --- a/src/observer/mysql/obmp_stmt_get_piece_data.cpp +++ b/src/observer/mysql/obmp_stmt_get_piece_data.cpp @@ -292,6 +292,7 @@ int ObMPStmtGetPieceData::do_process(ObSQLSessionInfo &session) if (OB_SUCC(session.get_inner_ps_stmt_id(stmt_id_, inner_stmt_id)) && OB_SUCC(session.get_ps_cache()->get_stmt_info_guard(inner_stmt_id, guard)) && OB_NOT_NULL(ps_info = guard.get_stmt_info())) { + audit_record.ps_inner_stmt_id_ = inner_stmt_id; audit_record.sql_ = const_cast(ps_info->get_ps_sql().ptr()); audit_record.sql_len_ = min(ps_info->get_ps_sql().length(), OB_MAX_SQL_LENGTH); } else { diff --git a/src/observer/mysql/obmp_stmt_prepare.cpp b/src/observer/mysql/obmp_stmt_prepare.cpp index d68939912..e17894193 100644 --- a/src/observer/mysql/obmp_stmt_prepare.cpp +++ b/src/observer/mysql/obmp_stmt_prepare.cpp @@ -403,6 +403,7 @@ int ObMPStmtPrepare::do_process(ObSQLSessionInfo &session, bool is_diagnostics_stmt = false; bool need_response_error = true; const ObString &sql = ctx_.multi_stmt_item_.get_sql(); + ObPsStmtId inner_stmt_id = OB_INVALID_ID; /* !!! * 注意req_timeinfo_guard一定要放在result前面 @@ -448,6 +449,10 @@ int ObMPStmtPrepare::do_process(ObSQLSessionInfo &session, LOG_WARN("run stmt_query failed, check if need retry", K(ret), K(cli_ret), K(retry_ctrl_.need_retry()), K(sql)); ret = cli_ret; + } else if (common::OB_INVALID_ID != result.get_statement_id() + && OB_FAIL(session.get_inner_ps_stmt_id(result.get_statement_id(), inner_stmt_id))) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("ps : get inner stmt id fail.", K(ret), K(result.get_statement_id())); } else { //监控项统计开始 if (enable_perf_event) { @@ -539,6 +544,7 @@ int ObMPStmtPrepare::do_process(ObSQLSessionInfo &session, audit_record.exec_record_.wait_time_end_ = total_wait_desc.time_waited_; audit_record.exec_record_.wait_count_end_ = total_wait_desc.total_waits_; audit_record.ps_stmt_id_ = result.get_statement_id(); + audit_record.ps_inner_stmt_id_ = inner_stmt_id; audit_record.update_stage_stat(); bool need_retry = (THIS_THWORKER.need_retry() || RETRY_TYPE_NONE != retry_ctrl_.get_retry_type()); diff --git a/src/observer/mysql/obmp_stmt_prexecute.cpp b/src/observer/mysql/obmp_stmt_prexecute.cpp index 999973c79..4a5bd4dae 100644 --- a/src/observer/mysql/obmp_stmt_prexecute.cpp +++ b/src/observer/mysql/obmp_stmt_prexecute.cpp @@ -388,7 +388,8 @@ int ObMPStmtPrexecute::execute_response(ObSQLSessionInfo &session, bool &is_diagnostics_stmt, int64_t &execution_id, const bool force_sync_resp, - bool &async_resp_used) + bool &async_resp_used, + ObPsStmtId &inner_stmt_id) { int ret = OB_SUCCESS; if (OB_OCI_EXACT_FETCH != exec_mode_ && stmt::T_SELECT == stmt_type_) { @@ -396,6 +397,7 @@ int ObMPStmtPrexecute::execute_response(ObSQLSessionInfo &session, set_ps_cursor_type(ObPrexecutePsCursorType); ObDbmsCursorInfo *cursor = NULL; bool use_stream = false; + inner_stmt_id = OB_INVALID_ID; // 1.创建cursor ObPsStmtId inner_stmt_id = OB_INVALID_ID; if (OB_NOT_NULL(session.get_cursor(stmt_id_))) { diff --git a/src/observer/mysql/obmp_stmt_prexecute.h b/src/observer/mysql/obmp_stmt_prexecute.h index ccc857a0e..0e3e707c5 100644 --- a/src/observer/mysql/obmp_stmt_prexecute.h +++ b/src/observer/mysql/obmp_stmt_prexecute.h @@ -69,7 +69,8 @@ public: bool &is_diagnostics_stmt, int64_t &execution_id, const bool force_sync_resp, - bool &async_resp_used); + bool &async_resp_used, + ObPsStmtId &inner_stmt_id); int response_query_header(sql::ObSQLSessionInfo &session, const ColumnsFieldIArray *fields, const ParamsFieldIArray *inout_params, diff --git a/src/observer/mysql/obmp_stmt_send_piece_data.cpp b/src/observer/mysql/obmp_stmt_send_piece_data.cpp index c4cb87f1a..f743ea641 100644 --- a/src/observer/mysql/obmp_stmt_send_piece_data.cpp +++ b/src/observer/mysql/obmp_stmt_send_piece_data.cpp @@ -290,6 +290,7 @@ int ObMPStmtSendPieceData::do_process(ObSQLSessionInfo &session) if (OB_SUCC(session.get_inner_ps_stmt_id(stmt_id_, inner_stmt_id)) && OB_SUCC(session.get_ps_cache()->get_stmt_info_guard(inner_stmt_id, guard)) && OB_NOT_NULL(ps_info = guard.get_stmt_info())) { + audit_record.ps_inner_stmt_id_ = inner_stmt_id; audit_record.sql_ = const_cast(ps_info->get_ps_sql().ptr()); audit_record.sql_len_ = min(ps_info->get_ps_sql().length(), OB_MAX_SQL_LENGTH); } else { diff --git a/src/observer/ob_inner_sql_connection.cpp b/src/observer/ob_inner_sql_connection.cpp index 6ff6b4b3a..f80912266 100644 --- a/src/observer/ob_inner_sql_connection.cpp +++ b/src/observer/ob_inner_sql_connection.cpp @@ -519,6 +519,7 @@ int ObInnerSQLConnection::process_record(sql::ObResultSet &result_set, audit_record.user_group_ = THIS_WORKER.get_group_id(); audit_record.execution_id_ = execution_id; audit_record.ps_stmt_id_ = ps_stmt_id; + audit_record.ps_inner_stmt_id_ = ps_stmt_id; if (ps_sql.length() != 0) { audit_record.sql_ = const_cast(ps_sql.ptr()); audit_record.sql_len_ = min(ps_sql.length(), OB_MAX_SQL_LENGTH); diff --git a/src/sql/session/ob_sql_session_info.cpp b/src/sql/session/ob_sql_session_info.cpp index 3a4033a58..99ae43f90 100644 --- a/src/sql/session/ob_sql_session_info.cpp +++ b/src/sql/session/ob_sql_session_info.cpp @@ -1649,14 +1649,6 @@ const ObAuditRecordData &ObSQLSessionInfo::get_final_audit_record( audit_record_.sql_cs_type_ = CS_TYPE_INVALID; } - if (OB_SUCC(ret) && OB_INVALID_STMT_ID != audit_record_.ps_stmt_id_) { - ObPsStmtId inner_stmt_id = OB_INVALID_STMT_ID; - if (OB_SUCC(get_inner_ps_stmt_id(audit_record_.ps_stmt_id_, inner_stmt_id))) { - audit_record_.ps_inner_stmt_id_ = inner_stmt_id; - } else { - ret = OB_SUCCESS; - } - } audit_record_.txn_free_route_flag_ = txn_free_route_ctx_.get_audit_record(); audit_record_.txn_free_route_version_ = txn_free_route_ctx_.get_global_version(); return audit_record_;