From a4d3ae7db7e488edb45bcf06b4f22496b227346f Mon Sep 17 00:00:00 2001 From: leslieyuchen Date: Tue, 15 Mar 2022 12:02:28 +0800 Subject: [PATCH] fix print remote sql info coredump --- src/sql/engine/ob_physical_plan_ctx.cpp | 27 ++++++++++++++++++++++++- src/sql/engine/ob_physical_plan_ctx.h | 5 +++-- src/sql/executor/ob_task.cpp | 1 + src/sql/ob_sql.cpp | 2 ++ src/sql/ob_sql_utils.cpp | 8 +------- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/sql/engine/ob_physical_plan_ctx.cpp b/src/sql/engine/ob_physical_plan_ctx.cpp index 47ee9d1243..3350005c27 100644 --- a/src/sql/engine/ob_physical_plan_ctx.cpp +++ b/src/sql/engine/ob_physical_plan_ctx.cpp @@ -21,12 +21,37 @@ #include "sql/engine/ob_exec_context.h" #include "sql/engine/ob_physical_plan.h" #include "sql/engine/px/ob_dfo.h" +#include "lib/utility/ob_print_utils.h" namespace oceanbase { using namespace common; using namespace share; using namespace transaction; namespace sql { -ObPhysicalPlanCtx::ObPhysicalPlanCtx(common::ObIAllocator& allocator) +DEF_TO_STRING(ObRemoteSqlInfo) +{ + int64_t pos = 0; + J_OBJ_START(); + J_KV(K_(use_ps), K_(is_batched_stmt), K_(ps_param_cnt), K_(remote_sql)); + J_COMMA(); + J_NAME("ps_params"); + J_COLON(); + if (OB_ISNULL(ps_params_) || ps_param_cnt_ <= 0) { + J_NULL(); + } else { + J_ARRAY_START(); + for (int64_t i = 0; pos < buf_len && i < ps_param_cnt_; ++i) { + BUF_PRINTO(ps_params_->at(i)); + if (i != ps_param_cnt_ - 1) { + J_COMMA(); + } + } + J_ARRAY_END(); + } + J_OBJ_END(); + return pos; +} + +ObPhysicalPlanCtx::ObPhysicalPlanCtx(common::ObIAllocator &allocator) : allocator_(allocator), tenant_id_(OB_INVALID_ID), tsc_snapshot_timestamp_(0), diff --git a/src/sql/engine/ob_physical_plan_ctx.h b/src/sql/engine/ob_physical_plan_ctx.h index ff931cf1d9..a696b85c4b 100644 --- a/src/sql/engine/ob_physical_plan_ctx.h +++ b/src/sql/engine/ob_physical_plan_ctx.h @@ -43,13 +43,14 @@ typedef common::ObFixedArray BatchParam typedef common::ObFixedArray ImplicitCursorInfoArray; struct ObRemoteSqlInfo { - ObRemoteSqlInfo() : use_ps_(false), is_batched_stmt_(false), remote_sql_(), ps_params_(nullptr) + ObRemoteSqlInfo() : use_ps_(false), is_batched_stmt_(false), ps_param_cnt_(0), remote_sql_(), ps_params_(nullptr) {} - TO_STRING_KV(K_(use_ps), K_(is_batched_stmt), K_(remote_sql), KPC_(ps_params)); + DECLARE_TO_STRING; bool use_ps_; bool is_batched_stmt_; + int32_t ps_param_cnt_; common::ObString remote_sql_; ParamStore* ps_params_; }; diff --git a/src/sql/executor/ob_task.cpp b/src/sql/executor/ob_task.cpp index 0d2a1b1392..30f96c15bb 100644 --- a/src/sql/executor/ob_task.cpp +++ b/src/sql/executor/ob_task.cpp @@ -684,6 +684,7 @@ OB_DEF_DESERIALIZE(ObRemoteTask) *ps_params, tenant_id); if (OB_SUCC(ret)) { + remote_sql_info_->ps_param_cnt_ = static_cast(ps_params->count()); if (OB_FAIL(exec_ctx_->create_my_session(tenant_id))) { LOG_WARN("create my session failed", K(ret), K(tenant_id)); } else { diff --git a/src/sql/ob_sql.cpp b/src/sql/ob_sql.cpp index 73d43826c1..417081b0f4 100644 --- a/src/sql/ob_sql.cpp +++ b/src/sql/ob_sql.cpp @@ -3066,6 +3066,7 @@ int ObSql::after_get_plan(ObPlanCacheCtx &pc_ctx, ObSQLSessionInfo &session, ObP pctx->get_remote_sql_info().use_ps_ = true; pctx->get_remote_sql_info().remote_sql_ = pc_ctx.sql_ctx_.cur_sql_; pctx->get_remote_sql_info().ps_params_ = ¶m_store; + pctx->get_remote_sql_info().ps_param_cnt_ = static_cast(param_store.count()); } else if (phy_plan->temp_sql_can_prepare() && pc_ctx.neg_param_index_.is_empty() && !pc_ctx.sql_ctx_.multi_stmt_item_.is_batched_multi_stmt()) { LOG_DEBUG("after get plan", @@ -3079,6 +3080,7 @@ int ObSql::after_get_plan(ObPlanCacheCtx &pc_ctx, ObSQLSessionInfo &session, ObP pctx->get_remote_sql_info().use_ps_ = true; pctx->get_remote_sql_info().remote_sql_ = phy_plan->get_constructed_sql(); pctx->get_remote_sql_info().ps_params_ = ¶m_store; + pctx->get_remote_sql_info().ps_param_cnt_ = static_cast(param_store.count()); } else { param_store.reset(); pctx->get_remote_sql_info().use_ps_ = false; diff --git a/src/sql/ob_sql_utils.cpp b/src/sql/ob_sql_utils.cpp index 4b078c7297..3bf26fb707 100644 --- a/src/sql/ob_sql_utils.cpp +++ b/src/sql/ob_sql_utils.cpp @@ -108,9 +108,6 @@ int ObSQLUtils::md5(const ObString& stmt, char* sql_id, int32_t len) reinterpret_cast(md5_sum_buf)); if (OB_ISNULL(res)) { // MD5() in openssl always return an pointer not NULL, so we need not check return value. - // see: - // http://www.openssl.org/docs/crypto/md5.html#DESCRIPTION - // http://www.openssl.org/docs/crypto/md5.html#RETURN_VALUES // Even so, we HAVE TO check it here. You know it. ret = OB_ERR_UNEXPECTED; LOG_WARN("md5 res null pointer", K(ret), K(res)); @@ -3237,10 +3234,7 @@ int ObVirtualTableResultConverter::convert_key_ranges(ObIArray& key_ if (!key_ranges.empty()) { common::ObArray tmp_range; OZ(tmp_range.reserve(key_ranges.count())); - if (OB_ISNULL(key_types_)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("key mapping is null", K(ret)); - } + CK(OB_NOT_NULL(key_types_)); for (int64_t i = 0; OB_SUCC(ret) && i < key_ranges.count(); ++i) { ObNewRange new_range; new_range.table_id_ = key_ranges.at(i).table_id_; -- GitLab