提交 cd043fb8 编写于 作者: O obdev 提交者: ob-robot

Add params value for text ps in sql audit

上级 99db3122
...@@ -74,7 +74,9 @@ ObMPQuery::ObMPQuery(const ObGlobalContext &gctx) ...@@ -74,7 +74,9 @@ ObMPQuery::ObMPQuery(const ObGlobalContext &gctx)
single_process_timestamp_(0), single_process_timestamp_(0),
exec_start_timestamp_(0), exec_start_timestamp_(0),
exec_end_timestamp_(0), exec_end_timestamp_(0),
is_com_filed_list_(false) is_com_filed_list_(false),
params_value_len_(0),
params_value_(NULL)
{ {
ctx_.exec_type_ = MpQuery; ctx_.exec_type_ = MpQuery;
} }
...@@ -717,7 +719,8 @@ OB_INLINE int ObMPQuery::do_process(ObSQLSessionInfo &session, ...@@ -717,7 +719,8 @@ OB_INLINE int ObMPQuery::do_process(ObSQLSessionInfo &session,
ObSqlFatalErrExtraInfoGuard extra_info_guard; ObSqlFatalErrExtraInfoGuard extra_info_guard;
extra_info_guard.set_cur_sql(sql); extra_info_guard.set_cur_sql(sql);
extra_info_guard.set_tenant_id(session.get_effective_tenant_id()); extra_info_guard.set_tenant_id(session.get_effective_tenant_id());
SMART_VAR(ObMySQLResultSet, result, session, CURRENT_CONTEXT->get_arena_allocator()) { ObIAllocator &allocator = CURRENT_CONTEXT->get_arena_allocator();
SMART_VAR(ObMySQLResultSet, result, session, allocator) {
if (OB_FAIL(get_tenant_schema_info_(session.get_effective_tenant_id(), if (OB_FAIL(get_tenant_schema_info_(session.get_effective_tenant_id(),
&cached_schema_info, &cached_schema_info,
schema_guard, schema_guard,
...@@ -951,6 +954,10 @@ OB_INLINE int ObMPQuery::do_process(ObSQLSessionInfo &session, ...@@ -951,6 +954,10 @@ OB_INLINE int ObMPQuery::do_process(ObSQLSessionInfo &session,
audit_record.is_multi_stmt_ = session.get_capability().cap_flags_.OB_CLIENT_MULTI_STATEMENTS; audit_record.is_multi_stmt_ = session.get_capability().cap_flags_.OB_CLIENT_MULTI_STATEMENTS;
audit_record.is_batched_multi_stmt_ = ctx_.multi_stmt_item_.is_batched_multi_stmt(); audit_record.is_batched_multi_stmt_ = ctx_.multi_stmt_item_.is_batched_multi_stmt();
OZ (store_params_value_to_str(allocator, session, result.get_ps_params()));
audit_record.params_value_ = params_value_;
audit_record.params_value_len_ = params_value_len_;
ObPhysicalPlanCtx *plan_ctx = result.get_exec_context().get_physical_plan_ctx(); ObPhysicalPlanCtx *plan_ctx = result.get_exec_context().get_physical_plan_ctx();
if (OB_ISNULL(plan_ctx)) { if (OB_ISNULL(plan_ctx)) {
//do nothing //do nothing
...@@ -1004,6 +1011,38 @@ OB_INLINE int ObMPQuery::do_process(ObSQLSessionInfo &session, ...@@ -1004,6 +1011,38 @@ OB_INLINE int ObMPQuery::do_process(ObSQLSessionInfo &session,
return ret; return ret;
} }
int ObMPQuery::store_params_value_to_str(ObIAllocator &allocator,
sql::ObSQLSessionInfo &session,
common::ParamStore &params)
{
int ret = OB_SUCCESS;
int64_t pos = 0;
int64_t length = OB_MAX_SQL_LENGTH;
CK (OB_NOT_NULL(params_value_ = static_cast<char *>(allocator.alloc(OB_MAX_SQL_LENGTH))));
for (int64_t i = 0; OB_SUCC(ret) && i < params.count(); ++i) {
const common::ObObjParam &param = params.at(i);
if (param.is_ext()) {
pos = 0;
params_value_ = NULL;
params_value_len_ = 0;
break;
} else {
OZ (param.print_sql_literal(params_value_, length, pos, allocator, TZ_INFO(&session)));
if (i != params.count() - 1) {
OZ (databuff_printf(params_value_, length, pos, allocator, ","));
}
}
}
if (OB_FAIL(ret)) {
params_value_ = NULL;
params_value_len_ = 0;
ret = OB_SUCCESS;
} else {
params_value_len_ = pos;
}
return ret;
}
//int ObMPQuery::fill_feedback_session_info(ObMySQLResultSet &result, //int ObMPQuery::fill_feedback_session_info(ObMySQLResultSet &result,
// ObSQLSessionInfo &session) // ObSQLSessionInfo &session)
//{ //{
......
...@@ -106,6 +106,9 @@ private: ...@@ -106,6 +106,9 @@ private:
bool &need_disconnect, bool &need_disconnect,
bool is_ins_multi_val_opt); bool is_ins_multi_val_opt);
int deserialize_com_field_list(); int deserialize_com_field_list();
int store_params_value_to_str(ObIAllocator &allocator,
sql::ObSQLSessionInfo &session,
common::ParamStore &params);
private: private:
DISALLOW_COPY_AND_ASSIGN(ObMPQuery); DISALLOW_COPY_AND_ASSIGN(ObMPQuery);
private: private:
...@@ -119,6 +122,8 @@ private: ...@@ -119,6 +122,8 @@ private:
//由于mysql的COM_FIELD_LIST命令本质上就是获取列的定义信息,只需要返回列定义 //由于mysql的COM_FIELD_LIST命令本质上就是获取列的定义信息,只需要返回列定义
bool is_com_filed_list_; bool is_com_filed_list_;
common::ObString wild_str_;//used to save wildware string in COM_FIELD_LIST common::ObString wild_str_;//used to save wildware string in COM_FIELD_LIST
int64_t params_value_len_;
char *params_value_;
}; // end of class ObMPQuery }; // end of class ObMPQuery
} // end of namespace observer } // end of namespace observer
} // end of namespace oceanbase } // end of namespace oceanbase
......
...@@ -316,6 +316,7 @@ public: ...@@ -316,6 +316,7 @@ public:
bool get_is_com_filed_list() { return is_com_filed_list_; } bool get_is_com_filed_list() { return is_com_filed_list_; }
void set_wildcard_string(common::ObString string) { wild_str_ = string; } void set_wildcard_string(common::ObString string) { wild_str_ = string; }
common::ObString &get_wildcard_string() { return wild_str_;} common::ObString &get_wildcard_string() { return wild_str_;}
common::ParamStore &get_ps_params() { return ps_params_; }
static void replace_lob_type(const ObSQLSessionInfo &session, static void replace_lob_type(const ObSQLSessionInfo &session,
const ObField &field, const ObField &field,
obmysql::ObMySQLField &mfield); obmysql::ObMySQLField &mfield);
...@@ -427,6 +428,7 @@ private: ...@@ -427,6 +428,7 @@ private:
common::ObString wild_str_;//uesd to save filed wildcard in COM_FIELD_LIST; common::ObString wild_str_;//uesd to save filed wildcard in COM_FIELD_LIST;
common::ObString ps_sql_; // for sql in pl common::ObString ps_sql_; // for sql in pl
bool is_init_; bool is_init_;
common::ParamStore ps_params_; // 文本 ps params 记录,用于填入 sql_audit
}; };
...@@ -500,7 +502,8 @@ inline ObResultSet::ObResultSet(ObSQLSessionInfo &session, common::ObIAllocator ...@@ -500,7 +502,8 @@ inline ObResultSet::ObResultSet(ObSQLSessionInfo &session, common::ObIAllocator
need_revert_tx_(false), need_revert_tx_(false),
wild_str_(), wild_str_(),
ps_sql_(), ps_sql_(),
is_init_(false) is_init_(false),
ps_params_(ObWrapperAllocator(&allocator))
{ {
message_[0] = '\0'; message_[0] = '\0';
// Always called in the ObResultSet constructor // Always called in the ObResultSet constructor
......
...@@ -4884,6 +4884,8 @@ int ObSql::handle_text_execute(const ObStmt *basic_stmt, ...@@ -4884,6 +4884,8 @@ int ObSql::handle_text_execute(const ObStmt *basic_stmt,
result, result,
false/*is_inner_sql*/))) { false/*is_inner_sql*/))) {
LOG_WARN("ps execute failed", K(ret)); LOG_WARN("ps execute failed", K(ret));
} else if (OB_FAIL(construct_param_store(param_store, result.get_ps_params()))) {
LOG_WARN("construct ps params failed", K(ret));
} }
} }
LOG_DEBUG("handle text execute done", K(ret), KPC(exec_stmt), K(param_store)); LOG_DEBUG("handle text execute done", K(ret), KPC(exec_stmt), K(param_store));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册