Replace ps inner stmt id calculated position in sql audit

This commit is contained in:
obdev 2023-04-04 03:41:57 +00:00 committed by ob-robot
parent d223aa2f28
commit 2ad78b0e63
10 changed files with 26 additions and 15 deletions

View File

@ -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_;

View File

@ -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_; }

View File

@ -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<char *>(ps_info->get_ps_sql().ptr());
audit_record.sql_len_ = min(ps_info->get_ps_sql().length(), OB_MAX_SQL_LENGTH);
} else {

View File

@ -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<char *>(ps_info->get_ps_sql().ptr());
audit_record.sql_len_ = min(ps_info->get_ps_sql().length(), OB_MAX_SQL_LENGTH);
} else {

View File

@ -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());

View File

@ -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_))) {

View File

@ -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,

View File

@ -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<char *>(ps_info->get_ps_sql().ptr());
audit_record.sql_len_ = min(ps_info->get_ps_sql().length(), OB_MAX_SQL_LENGTH);
} else {

View File

@ -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<char *>(ps_sql.ptr());
audit_record.sql_len_ = min(ps_sql.length(), OB_MAX_SQL_LENGTH);

View File

@ -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_;