From 317ca7bb4171f2b05f89a10df9c0741c51d17d31 Mon Sep 17 00:00:00 2001 From: haohao022 Date: Mon, 17 Jun 2024 13:17:53 +0000 Subject: [PATCH] [to #56534142] test: error injection for pr-exec protocol --- .../oblib/src/lib/utility/ob_tracepoint_def.h | 7 ++++ src/observer/mysql/obmp_stmt_prexecute.cpp | 35 +++++-------------- src/sql/ob_sql.cpp | 17 +++++++-- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/deps/oblib/src/lib/utility/ob_tracepoint_def.h b/deps/oblib/src/lib/utility/ob_tracepoint_def.h index ce1771970..b1340f180 100644 --- a/deps/oblib/src/lib/utility/ob_tracepoint_def.h +++ b/deps/oblib/src/lib/utility/ob_tracepoint_def.h @@ -543,4 +543,11 @@ GLOBAL_ERRSIM_POINT_DEF(2304, EN_TRACEPOINT_TEST, "For testing new versions of t GLOBAL_ERRSIM_POINT_DEF(2400, EN_SQL_FORCE_DUMP, "For testing force dump once"); GLOBAL_ERRSIM_POINT_DEF(2401, EN_TEST_FOR_HASH_UNION, "Used to control whether to turn off the vectorization 2.0 hash set operator. It is turned on by default."); +// Protocol begin 2450 - 2500 +// pr-exec protocol +GLOBAL_ERRSIM_POINT_DEF(2450, COM_STMT_PREXECUTE_PREPARE_ERROR, "inject error at prepare stage for pr-exec protocol"); +GLOBAL_ERRSIM_POINT_DEF(2451, COM_STMT_PREXECUTE_PS_CURSOR_OPEN_ERROR, "inject error at cursor open stage for pr-exec protocol"); +GLOBAL_ERRSIM_POINT_DEF(2452, COM_STMT_PREXECUTE_EXECUTE_ERROR, "inject error at execute stage for pr-exec protocol"); +// Protocol end + #endif /*GLOBAL_ERRSIM_POINT_DEF*/ diff --git a/src/observer/mysql/obmp_stmt_prexecute.cpp b/src/observer/mysql/obmp_stmt_prexecute.cpp index 1553d771c..4413da26e 100644 --- a/src/observer/mysql/obmp_stmt_prexecute.cpp +++ b/src/observer/mysql/obmp_stmt_prexecute.cpp @@ -62,13 +62,6 @@ using namespace sql; using namespace pl; namespace observer { - -#ifdef ERRSIM -ERRSIM_POINT_DEF(COM_STMT_PREXECUTE_PREPARE_ERROR); -ERRSIM_POINT_DEF(COM_STMT_PREXECUTE_PS_CURSOR_OPEN_ERROR); -ERRSIM_POINT_DEF(COM_STMT_PREXECUTE_EXECUTE_ERROR); -#endif - ObMPStmtPrexecute::ObMPStmtPrexecute(const ObGlobalContext &gctx) : ObMPStmtExecute(gctx), sql_(), @@ -251,15 +244,10 @@ int ObMPStmtPrexecute::before_process() LOG_WARN("fail to set session active", K(ret)); } if (OB_SUCC(ret)) { - if ( -#ifdef ERRSIM - OB_FAIL(COM_STMT_PREXECUTE_PREPARE_ERROR) || -#endif - OB_FAIL(gctx_.sql_engine_->stmt_prepare(sql_, + if (OB_FAIL(gctx_.sql_engine_->stmt_prepare(sql_, get_ctx(), result, - false /*is_inner_sql*/)) - ) { + false /*is_inner_sql*/))) { set_exec_start_timestamp(ObTimeUtility::current_time()); int cli_ret = OB_SUCCESS; get_retry_ctrl().test_and_save_retry_state(gctx_, @@ -487,7 +475,7 @@ int ObMPStmtPrexecute::execute_response(ObSQLSessionInfo &session, get_ctx().cur_sql_ = sql_; if ( #ifdef ERRSIM - OB_FAIL(COM_STMT_PREXECUTE_PS_CURSOR_OPEN_ERROR) || + OB_FAIL(common::EventTable::COM_STMT_PREXECUTE_PS_CURSOR_OPEN_ERROR) || #endif OB_FAIL(ObSPIService::dbms_dynamic_open(&pl_ctx, *cursor)) ) { @@ -617,17 +605,12 @@ int ObMPStmtPrexecute::execute_response(ObSQLSessionInfo &session, ret = tmp_ret; LOG_WARN("execute server cursor failed.", K(ret)); } - } else if ( -#ifdef ERRSIM - OB_FAIL(COM_STMT_PREXECUTE_EXECUTE_ERROR) || -#endif - OB_FAIL(gctx_.sql_engine_->stmt_execute(stmt_id_, - stmt_type_, - params, - ctx, - result, - false /* is_inner_sql */)) - ) { + } else if (OB_FAIL(gctx_.sql_engine_->stmt_execute(stmt_id_, + stmt_type_, + params, + ctx, + result, + false /* is_inner_sql */))) { set_exec_start_timestamp(ObTimeUtility::current_time()); if (!THIS_WORKER.need_retry()) { int cli_ret = OB_SUCCESS; diff --git a/src/sql/ob_sql.cpp b/src/sql/ob_sql.cpp index 4833cab21..621f506c4 100644 --- a/src/sql/ob_sql.cpp +++ b/src/sql/ob_sql.cpp @@ -273,8 +273,14 @@ int ObSql::stmt_execute(const ObPsStmtId stmt_id, LOG_WARN("failed to do sanity check", K(ret)); } else if (OB_FAIL(init_result_set(context, result))) { LOG_WARN("failed to init result set", K(ret)); - } else if (OB_FAIL(handle_ps_execute(stmt_id, stmt_type, params, - context, result, is_inner_sql))) { + } else if ( +#ifdef ERRSIM + // inject error for pr-ex protocol only + // inject after `init_result_set` because retry test would check session ptr in the exec ctx, + // which is initialized by `init_result_set`. + OB_FAIL(EVENT_CALL(common::EventTable::COM_STMT_PREXECUTE_EXECUTE_ERROR, context.is_pre_execute_)) || +#endif + OB_FAIL(handle_ps_execute(stmt_id, stmt_type, params, context, result, is_inner_sql))) { if (OB_ERR_PROXY_REROUTE != ret) { LOG_WARN("failed to handle ps execute", K(stmt_id), K(ret)); } @@ -1791,6 +1797,13 @@ int ObSql::handle_ps_prepare(const ObString &stmt, LOG_WARN("failed to init result set", K(ret)); } +#ifdef ERRSIM + // inject error for pr-ex protocol only + if (OB_SUCC(ret)) { + ret = OB_E(common::EventTable::COM_STMT_PREXECUTE_PREPARE_ERROR, context.is_pre_execute_) OB_SUCCESS; + } +#endif + if (OB_SUCC(ret)) { ObSQLSessionInfo &session = result.get_session(); ObPsCache *ps_cache = session.get_ps_cache();