From e349a542f149478271a8d350c0b1b737001d3897 Mon Sep 17 00:00:00 2001 From: qianchanger Date: Mon, 4 Jul 2022 10:09:50 +0800 Subject: [PATCH] =?UTF-8?q?[C]=20obdumper=E6=8A=BD=E6=95=B0=E5=8D=95?= =?UTF-8?q?=E8=A1=A8=E6=8A=A5=E9=94=994013=20[3.1=5Fopensource=5Frelease?= =?UTF-8?q?=20<=203=5F1=5Fx=5Frelease]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/observer/mysql/ob_query_driver.cpp | 23 ++++++++++++++++------ src/observer/mysql/ob_sync_cmd_driver.cpp | 7 +++++++ src/observer/mysql/ob_sync_plan_driver.cpp | 13 ++++++++++-- src/sql/engine/ob_exec_context.cpp | 18 ++++++++--------- src/sql/engine/ob_exec_context.h | 8 +++++--- 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/observer/mysql/ob_query_driver.cpp b/src/observer/mysql/ob_query_driver.cpp index e549d94f86..006b2fdbf0 100644 --- a/src/observer/mysql/ob_query_driver.cpp +++ b/src/observer/mysql/ob_query_driver.cpp @@ -170,11 +170,17 @@ int ObQueryDriver::convert_string_value_charset(ObObj& value, ObResultSet& resul { int ret = OB_SUCCESS; ObCharsetType charset_type = CHARSET_INVALID; - const ObSQLSessionInfo& my_session = result.get_session(); - if (OB_FAIL(my_session.get_character_set_results(charset_type))) { + const ObSQLSessionInfo &my_session = result.get_session(); + ObArenaAllocator *allocator = NULL; + if (OB_FAIL(result.get_exec_context().get_convert_charset_allocator(allocator))) { + LOG_WARN("fail to get lob fake allocator", K(ret)); + } else if (OB_ISNULL(allocator)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("lob fake allocator is null.", K(ret), K(value)); + } else if (OB_FAIL(my_session.get_character_set_results(charset_type))) { LOG_WARN("fail to get result charset", K(ret)); } else { - OZ(value.convert_string_value_charset(charset_type, result.get_mem_pool())); + OZ (value.convert_string_value_charset(charset_type, *allocator)); } return ret; } @@ -249,8 +255,13 @@ int ObQueryDriver::convert_lob_value_charset(common::ObObj& value, sql::ObResult int32_t header_len = value.get_val_len() - lob_locator->payload_size_; int32_t str_len = lob_locator->payload_size_ * 4; uint32_t result_len = 0; - ObIAllocator& allocator = result.get_mem_pool(); - if (OB_UNLIKELY(NULL == (buf = static_cast(allocator.alloc(header_len + str_len))))) { + ObArenaAllocator *allocator = NULL; + if (OB_FAIL(result.get_exec_context().get_convert_charset_allocator(allocator))) { + LOG_WARN("fail to get lob fake allocator", K(ret)); + } else if (OB_ISNULL(allocator)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("lob fake allocator is null.", K(ret), K(value)); + } else if (OB_UNLIKELY(NULL == (buf = static_cast(allocator->alloc(header_len + str_len))))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_ERROR("alloc memory failed", K(ret), K(header_len), K(str_len)); } else { @@ -330,7 +341,7 @@ int ObQueryDriver::convert_lob_locator_to_longtext(ObObj& value, ObResultSet& re ObArenaAllocator* allocator = NULL; if (OB_FAIL(value.get_string(str))) { STORAGE_LOG(WARN, "Failed to get string from obj", K(ret), K(value)); - } else if (OB_FAIL(result.get_exec_context().get_lob_fake_allocator(allocator))) { + } else if (OB_FAIL(result.get_exec_context().get_convert_charset_allocator(allocator))) { LOG_WARN("fail to get lob fake allocator", K(ret)); } else if (FALSE_IT(allocator->reset())) { } else if (OB_ISNULL(buf = static_cast(allocator->alloc(str.length() + sizeof(ObLobLocator))))) { diff --git a/src/observer/mysql/ob_sync_cmd_driver.cpp b/src/observer/mysql/ob_sync_cmd_driver.cpp index 1d82379de8..4b7e4dba43 100644 --- a/src/observer/mysql/ob_sync_cmd_driver.cpp +++ b/src/observer/mysql/ob_sync_cmd_driver.cpp @@ -258,6 +258,13 @@ int ObSyncCmdDriver::response_query_result(ObMySQLResultSet &result) OMPKRow rp(sm_row); if (OB_FAIL(sender_.response_packet(rp))) { LOG_WARN("response packet fail", K(ret), KP(row)); + } else { + ObArenaAllocator *allocator = NULL; + if (OB_FAIL(result.get_exec_context().get_convert_charset_allocator(allocator))) { + LOG_WARN("fail to get lob fake allocator", K(ret)); + } else if (OB_NOT_NULL(allocator)) { + allocator->reset(); + } } } } diff --git a/src/observer/mysql/ob_sync_plan_driver.cpp b/src/observer/mysql/ob_sync_plan_driver.cpp index 30cc40f6d2..6bb7a8f5ef 100644 --- a/src/observer/mysql/ob_sync_plan_driver.cpp +++ b/src/observer/mysql/ob_sync_plan_driver.cpp @@ -220,6 +220,7 @@ int ObSyncPlanDriver::response_query_result( session_.get_trans_desc().consistency_wait(); MYSQL_PROTOCOL_TYPE protocol_type = result.is_ps_protocol() ? BINARY : TEXT; const common::ColumnsFieldIArray *fields = NULL; + ObArenaAllocator *convert_allocator = NULL; //just for convert charset if (OB_SUCC(ret)) { fields = result.get_field_columns(); if (OB_ISNULL(fields)) { @@ -237,11 +238,19 @@ int ObSyncPlanDriver::response_query_result( LOG_WARN("fail to response query header", K(ret), K(row_num), K(can_retry)); } } + if (OB_SUCC(ret)) { + if (OB_FAIL(result.get_exec_context().get_convert_charset_allocator(convert_allocator))) { + LOG_WARN("fail to get lob fake allocator", K(ret)); + } else if (OB_ISNULL(convert_allocator)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("allocator is unexpected", K(ret)); + } + } for (int64_t i = 0; OB_SUCC(ret) && i < row->get_count(); i++) { ObObj &value = row->get_cell(i); if (result.is_ps_protocol()) { if (value.get_type() != fields->at(i).type_.get_type()) { - ObCastCtx cast_ctx(&result.get_mem_pool(), NULL, CM_WARN_ON_FAIL, CS_TYPE_INVALID); + ObCastCtx cast_ctx(convert_allocator, NULL, CM_WARN_ON_FAIL, CS_TYPE_INVALID); if (OB_FAIL(common::ObObjCaster::to_type(fields->at(i).type_.get_type(), cast_ctx, value, value))) { LOG_WARN("failed to cast object", K(ret), K(value), K(value.get_type()), K(fields->at(i).type_.get_type())); } @@ -270,7 +279,7 @@ int ObSyncPlanDriver::response_query_result( LOG_WARN("response packet fail", K(ret), KP(row), K(row_num), K(can_retry)); // break; } else { - // LOG_DEBUG("response row succ", K(*row)); + convert_allocator->reset(); } if (OB_SUCC(ret)) { ++row_num; diff --git a/src/sql/engine/ob_exec_context.cpp b/src/sql/engine/ob_exec_context.cpp index 524cbd79ab..9c55ccbdc6 100644 --- a/src/sql/engine/ob_exec_context.cpp +++ b/src/sql/engine/ob_exec_context.cpp @@ -156,7 +156,7 @@ ObExecContext::ObExecContext(ObIAllocator& allocator) temp_ctx_(), gi_pruning_info_(), sched_info_(), - lob_fake_allocator_(nullptr), + convert_allocator_(nullptr), root_op_(NULL), pwj_map_(nullptr), calc_type_(CALC_NORMAL), @@ -217,7 +217,7 @@ ObExecContext::ObExecContext() temp_ctx_(), gi_pruning_info_(), sched_info_(), - lob_fake_allocator_(nullptr), + convert_allocator_(nullptr), root_op_(NULL), pwj_map_(nullptr), calc_type_(CALC_NORMAL), @@ -252,9 +252,9 @@ ObExecContext::~ObExecContext() } clean_resolve_ctx(); sqc_handler_ = nullptr; - if (OB_LIKELY(NULL != lob_fake_allocator_)) { - DESTROY_CONTEXT(lob_fake_allocator_); - lob_fake_allocator_ = NULL; + if (OB_LIKELY(NULL != convert_allocator_)) { + DESTROY_CONTEXT(convert_allocator_); + convert_allocator_ = NULL; } iters_.reset(); } @@ -797,11 +797,11 @@ int ObExecContext::get_gi_task_map(GIPrepareTaskMap*& gi_task_map) return ret; } -int ObExecContext::get_lob_fake_allocator(ObArenaAllocator*& allocator) +int ObExecContext::get_convert_charset_allocator(ObArenaAllocator *&allocator) { int ret = OB_SUCCESS; allocator = NULL; - if (OB_ISNULL(lob_fake_allocator_)) { + if (OB_ISNULL(convert_allocator_)) { if (OB_ISNULL(my_session_)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("session is null", K(ret)); @@ -811,13 +811,13 @@ int ObExecContext::get_lob_fake_allocator(ObArenaAllocator*& allocator) .set_mem_attr(my_session_->get_effective_tenant_id(), common::ObModIds::OB_SQL_EXPR_CALC, common::ObCtxIds::DEFAULT_CTX_ID); - if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(lob_fake_allocator_, param))) { + if (OB_FAIL(CURRENT_CONTEXT->CREATE_CONTEXT(convert_allocator_, param))) { SQL_ENG_LOG(WARN, "create entity failed", K(ret)); } } } if (OB_SUCC(ret)) { - allocator = &lob_fake_allocator_->get_arena_allocator(); + allocator = &convert_allocator_->get_arena_allocator(); } return ret; diff --git a/src/sql/engine/ob_exec_context.h b/src/sql/engine/ob_exec_context.h index 444e180477..829381628f 100644 --- a/src/sql/engine/ob_exec_context.h +++ b/src/sql/engine/ob_exec_context.h @@ -165,7 +165,7 @@ public: { return expr_op_size_ > 0 && NULL != expr_op_ctx_store_; } - int get_lob_fake_allocator(common::ObArenaAllocator*& allocator); + int get_convert_charset_allocator(common::ObArenaAllocator *&allocator); int init_eval_ctx(); void destroy_eval_ctx(); @@ -798,8 +798,10 @@ protected: // dynamic partition pruning for right TSC of NLJ ObGIPruningInfo gi_pruning_info_; - ObSchedInfo sched_info_; - lib::MemoryContext lob_fake_allocator_; + ObSchedInfo sched_info_; + + // just for convert charset in query response result + lib::MemoryContext convert_allocator_; // serialize operator inputs of %root_op_ subplan if root_op_ is not NULL const ObPhyOperator* root_op_; -- GitLab