From 2e90867a91005cfed8cb22fb602b75343a7d6b55 Mon Sep 17 00:00:00 2001 From: LuckyPickleZZ Date: Fri, 12 Jul 2024 14:22:36 +0800 Subject: [PATCH] response to CR comments --- ...ExecutorInfo.java => OBExecutionServerInfo.java} | 2 +- .../com/oceanbase/odc/core/sql/util/OBUtils.java | 12 ++++++------ .../odc/service/session/ConnectConsoleService.java | 6 ++++-- ...er.java => OBQueryProfileExecutionListener.java} | 4 ++-- .../connect/obmysql/OBMySQLDiagnoseExtension.java | 13 +++++++------ .../connect/oboracle/OBOracleDiagnoseExtension.java | 9 +++++---- 6 files changed, 25 insertions(+), 21 deletions(-) rename server/odc-core/src/main/java/com/oceanbase/odc/core/shared/model/{ExecutorInfo.java => OBExecutionServerInfo.java} (95%) rename server/odc-service/src/main/java/com/oceanbase/odc/service/session/{OBExecutionListener.java => OBQueryProfileExecutionListener.java} (96%) diff --git a/server/odc-core/src/main/java/com/oceanbase/odc/core/shared/model/ExecutorInfo.java b/server/odc-core/src/main/java/com/oceanbase/odc/core/shared/model/OBExecutionServerInfo.java similarity index 95% rename from server/odc-core/src/main/java/com/oceanbase/odc/core/shared/model/ExecutorInfo.java rename to server/odc-core/src/main/java/com/oceanbase/odc/core/shared/model/OBExecutionServerInfo.java index 513340636c..94a659b769 100644 --- a/server/odc-core/src/main/java/com/oceanbase/odc/core/shared/model/ExecutorInfo.java +++ b/server/odc-core/src/main/java/com/oceanbase/odc/core/shared/model/OBExecutionServerInfo.java @@ -22,7 +22,7 @@ * @date: 2024/7/4 */ @Data -public class ExecutorInfo { +public class OBExecutionServerInfo { private String ip; private String port; diff --git a/server/odc-core/src/main/java/com/oceanbase/odc/core/sql/util/OBUtils.java b/server/odc-core/src/main/java/com/oceanbase/odc/core/sql/util/OBUtils.java index ae0053d2b6..b8796400ba 100644 --- a/server/odc-core/src/main/java/com/oceanbase/odc/core/sql/util/OBUtils.java +++ b/server/odc-core/src/main/java/com/oceanbase/odc/core/sql/util/OBUtils.java @@ -41,7 +41,7 @@ import com.oceanbase.odc.core.shared.constant.ErrorCodes; import com.oceanbase.odc.core.shared.exception.BadRequestException; import com.oceanbase.odc.core.shared.exception.UnexpectedException; -import com.oceanbase.odc.core.shared.model.ExecutorInfo; +import com.oceanbase.odc.core.shared.model.OBExecutionServerInfo; import com.oceanbase.odc.core.shared.model.OBSqlPlan; import com.oceanbase.odc.core.shared.model.SqlExecDetail; import com.oceanbase.odc.core.shared.model.SqlPlanMonitor; @@ -445,7 +445,7 @@ public static String queryTraceIdFromASH(@NonNull Statement statement, * OceanBase only supports ASH views in versions higher than 4.0. Therefore, this method is not * applicable to earlier versions, please use sql_audit instead. */ - public static ExecutorInfo queryPlanIdByTraceIdFromASH(@NonNull Statement statement, String traceId, + public static OBExecutionServerInfo queryPlanIdByTraceIdFromASH(@NonNull Statement statement, String traceId, List sessionIds, ConnectType connectType) throws SQLException { DialectType dialectType = connectType.getDialectType(); SqlBuilder sqlBuilder = getBuilder(connectType) @@ -461,7 +461,7 @@ public static ExecutorInfo queryPlanIdByTraceIdFromASH(@NonNull Statement statem if (!rs.next()) { throw new SQLException("No result found in ASH."); } - ExecutorInfo executorInfo = new ExecutorInfo(); + OBExecutionServerInfo executorInfo = new OBExecutionServerInfo(); executorInfo.setIp(rs.getString("svr_ip")); executorInfo.setPort(rs.getString("svr_port")); executorInfo.setPlanId(rs.getString("plan_id")); @@ -470,7 +470,7 @@ public static ExecutorInfo queryPlanIdByTraceIdFromASH(@NonNull Statement statem } } - public static ExecutorInfo queryPlanIdByTraceIdFromAudit(@NonNull Statement statement, String traceId, + public static OBExecutionServerInfo queryPlanIdByTraceIdFromAudit(@NonNull Statement statement, String traceId, List sessionIds, ConnectType connectType) throws SQLException { DialectType dialectType = connectType.getDialectType(); SqlBuilder sqlBuilder = getBuilder(connectType) @@ -485,7 +485,7 @@ public static ExecutorInfo queryPlanIdByTraceIdFromAudit(@NonNull Statement stat if (!rs.next()) { throw new SQLException("No result found in sql_audit."); } - ExecutorInfo executorInfo = new ExecutorInfo(); + OBExecutionServerInfo executorInfo = new OBExecutionServerInfo(); executorInfo.setIp(rs.getString("svr_ip")); executorInfo.setPort(rs.getString("svr_port")); executorInfo.setPlanId(rs.getString("plan_id")); @@ -495,7 +495,7 @@ public static ExecutorInfo queryPlanIdByTraceIdFromAudit(@NonNull Statement stat } public static List queryOBSqlPlanByPlanId(@NonNull Statement statement, - @NonNull ExecutorInfo executorInfo, ConnectType connectType) throws SQLException { + @NonNull OBExecutionServerInfo executorInfo, ConnectType connectType) throws SQLException { DialectType dialectType = connectType.getDialectType(); SqlBuilder sqlBuilder = getBuilder(connectType) .append("select id, parent_id, operator, object_owner, object_name, object_alias, ") diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/session/ConnectConsoleService.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/session/ConnectConsoleService.java index 419a2aad47..3782e18db2 100644 --- a/server/odc-service/src/main/java/com/oceanbase/odc/service/session/ConnectConsoleService.java +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/session/ConnectConsoleService.java @@ -316,7 +316,8 @@ public SqlAsyncExecuteResp streamExecute(@NotNull String sessionId, statementCallBack.setMaxCachedLines(sessionProperties.getResultSetMaxCachedLines()); statementCallBack.setLocale(LocaleContextHolder.getLocale()); if (connectionSession.getDialectType().isOceanbase() && sqlTuples.size() <= 10) { - statementCallBack.getListeners().add(new OBExecutionListener(connectionSession, profileManager)); + statementCallBack.getListeners() + .add(new OBQueryProfileExecutionListener(connectionSession, profileManager)); } Future> futureResult = connectionSession.getAsyncJdbcExecutor( @@ -594,7 +595,8 @@ private SqlExecuteResult generateResult(@NonNull ConnectionSession connectionSes } try { String version = ConnectionSessionUtil.getVersion(connectionSession); - result.setWithQueryProfile(OBExecutionListener.isSqlTypeSupportProfile(generalResult.getSqlTuple()) && + result.setWithQueryProfile(OBQueryProfileExecutionListener + .isSqlTypeSupportProfile(generalResult.getSqlTuple()) && VersionUtils.isGreaterThanOrEqualsTo(version, OBQueryProfileManager.ENABLE_QUERY_PROFILE_VERSION)); } catch (Exception e) { result.setWithQueryProfile(false); diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/session/OBExecutionListener.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/session/OBQueryProfileExecutionListener.java similarity index 96% rename from server/odc-service/src/main/java/com/oceanbase/odc/service/session/OBExecutionListener.java rename to server/odc-service/src/main/java/com/oceanbase/odc/service/session/OBQueryProfileExecutionListener.java index cf405d0539..a68f93b744 100644 --- a/server/odc-service/src/main/java/com/oceanbase/odc/service/session/OBExecutionListener.java +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/session/OBQueryProfileExecutionListener.java @@ -46,14 +46,14 @@ * @date: 2024/4/23 */ @Slf4j -public class OBExecutionListener implements SqlExecutionListener { +public class OBQueryProfileExecutionListener implements SqlExecutionListener { private static final Long DEFAULT_QUERY_TRACE_ID_WAIT_MILLIS = 1100L; private final ConnectionSession session; private final List sessionIds; private final OBQueryProfileManager profileManager; - public OBExecutionListener(ConnectionSession session, OBQueryProfileManager profileManager) { + public OBQueryProfileExecutionListener(ConnectionSession session, OBQueryProfileManager profileManager) { this.session = session; this.profileManager = profileManager; sessionIds = getSessionIds(); diff --git a/server/plugins/connect-plugin-ob-mysql/src/main/java/com/oceanbase/odc/plugin/connect/obmysql/OBMySQLDiagnoseExtension.java b/server/plugins/connect-plugin-ob-mysql/src/main/java/com/oceanbase/odc/plugin/connect/obmysql/OBMySQLDiagnoseExtension.java index 94a2517c5c..0733cbd952 100644 --- a/server/plugins/connect-plugin-ob-mysql/src/main/java/com/oceanbase/odc/plugin/connect/obmysql/OBMySQLDiagnoseExtension.java +++ b/server/plugins/connect-plugin-ob-mysql/src/main/java/com/oceanbase/odc/plugin/connect/obmysql/OBMySQLDiagnoseExtension.java @@ -44,7 +44,7 @@ import com.oceanbase.odc.core.shared.constant.ErrorCodes; import com.oceanbase.odc.core.shared.exception.OBException; import com.oceanbase.odc.core.shared.exception.UnexpectedException; -import com.oceanbase.odc.core.shared.model.ExecutorInfo; +import com.oceanbase.odc.core.shared.model.OBExecutionServerInfo; import com.oceanbase.odc.core.shared.model.OBSqlPlan; import com.oceanbase.odc.core.shared.model.PlanNode; import com.oceanbase.odc.core.shared.model.SqlExecDetail; @@ -226,7 +226,7 @@ public SqlExecDetail getExecutionDetailBySql(Connection connection, @NonNull Str public SqlExplain getQueryProfileByTraceIdAndSessIds(Connection connection, @NonNull String traceId, @NonNull List sessionIds) throws SQLException { try (Statement stmt = connection.createStatement()) { - ExecutorInfo executorInfo = getPlanIdByTraceIdAndSessIds(stmt, traceId, sessionIds); + OBExecutionServerInfo executorInfo = getPlanIdByTraceIdAndSessIds(stmt, traceId, sessionIds); Verify.notEmpty(executorInfo.getPlanId(), "plan id"); PlanGraph graph = getPlanGraph(stmt, executorInfo); graph.setTraceId(traceId); @@ -253,7 +253,8 @@ public SqlExplain getQueryProfileByTraceIdAndSessIds(Connection connection, @Non } } - protected ExecutorInfo getPlanIdByTraceIdAndSessIds(Statement stmt, String traceId, List sessionIds) + protected OBExecutionServerInfo getPlanIdByTraceIdAndSessIds(Statement stmt, String traceId, + List sessionIds) throws SQLException { try { return OBUtils.queryPlanIdByTraceIdFromASH(stmt, traceId, sessionIds, ConnectType.OB_MYSQL); @@ -262,7 +263,7 @@ protected ExecutorInfo getPlanIdByTraceIdAndSessIds(Statement stmt, String trace } } - protected String getPhysicalPlanByDbmsXplan(Statement stmt, ExecutorInfo executorInfo) + protected String getPhysicalPlanByDbmsXplan(Statement stmt, OBExecutionServerInfo executorInfo) throws SQLException { String sql = String.format("select dbms_xplan.display_cursor(%s,'ALL','%s',%s,%s)", executorInfo.getPlanId(), executorInfo.getIp(), executorInfo.getPort(), executorInfo.getTenantId()); @@ -274,7 +275,7 @@ protected String getPhysicalPlanByDbmsXplan(Statement stmt, ExecutorInfo executo } } - protected PlanGraph getPlanGraph(Statement stmt, ExecutorInfo executorInfo) throws SQLException { + protected PlanGraph getPlanGraph(Statement stmt, OBExecutionServerInfo executorInfo) throws SQLException { List planRecords = OBUtils.queryOBSqlPlanByPlanId(stmt, executorInfo, ConnectType.OB_MYSQL); return PlanGraphBuilder.buildPlanGraph(planRecords); } @@ -300,7 +301,7 @@ protected List getSqlPlanMonitorRecords(Statement stmt, String t * 0 - output... * */ - private SqlExplain innerGetSqlExplainByDbmsXplan(Statement stmt, ExecutorInfo executorInfo) + private SqlExplain innerGetSqlExplainByDbmsXplan(Statement stmt, OBExecutionServerInfo executorInfo) throws SQLException { SqlExplain sqlExplain = new SqlExplain(); sqlExplain.setShowFormatInfo(true); diff --git a/server/plugins/connect-plugin-ob-oracle/src/main/java/com/oceanbase/odc/plugin/connect/oboracle/OBOracleDiagnoseExtension.java b/server/plugins/connect-plugin-ob-oracle/src/main/java/com/oceanbase/odc/plugin/connect/oboracle/OBOracleDiagnoseExtension.java index fb0ea44afb..15723ddad7 100644 --- a/server/plugins/connect-plugin-ob-oracle/src/main/java/com/oceanbase/odc/plugin/connect/oboracle/OBOracleDiagnoseExtension.java +++ b/server/plugins/connect-plugin-ob-oracle/src/main/java/com/oceanbase/odc/plugin/connect/oboracle/OBOracleDiagnoseExtension.java @@ -30,7 +30,7 @@ import com.oceanbase.odc.core.shared.constant.ConnectType; import com.oceanbase.odc.core.shared.constant.ErrorCodes; import com.oceanbase.odc.core.shared.exception.OBException; -import com.oceanbase.odc.core.shared.model.ExecutorInfo; +import com.oceanbase.odc.core.shared.model.OBExecutionServerInfo; import com.oceanbase.odc.core.shared.model.OBSqlPlan; import com.oceanbase.odc.core.shared.model.PlanNode; import com.oceanbase.odc.core.shared.model.SqlExecDetail; @@ -183,7 +183,8 @@ protected SqlExecDetail innerGetExecutionDetail(Connection connection, String ap } @Override - protected ExecutorInfo getPlanIdByTraceIdAndSessIds(Statement stmt, String traceId, List sessionIds) + protected OBExecutionServerInfo getPlanIdByTraceIdAndSessIds(Statement stmt, String traceId, + List sessionIds) throws SQLException { try { return OBUtils.queryPlanIdByTraceIdFromASH(stmt, traceId, sessionIds, ConnectType.OB_ORACLE); @@ -193,7 +194,7 @@ protected ExecutorInfo getPlanIdByTraceIdAndSessIds(Statement stmt, String trace } @Override - protected String getPhysicalPlanByDbmsXplan(Statement stmt, ExecutorInfo executorInfo) + protected String getPhysicalPlanByDbmsXplan(Statement stmt, OBExecutionServerInfo executorInfo) throws SQLException { try (ResultSet rs = stmt.executeQuery("select VALUE from V$NLS_PARAMETERS where PARAMETER='NLS_CHARACTERSET'")) { @@ -215,7 +216,7 @@ protected String getPhysicalPlanByDbmsXplan(Statement stmt, ExecutorInfo executo return builder.toString(); } - protected PlanGraph getPlanGraph(Statement stmt, ExecutorInfo executorInfo) throws SQLException { + protected PlanGraph getPlanGraph(Statement stmt, OBExecutionServerInfo executorInfo) throws SQLException { List planRecords = OBUtils.queryOBSqlPlanByPlanId(stmt, executorInfo, ConnectType.OB_ORACLE); return PlanGraphBuilder.buildPlanGraph(planRecords); }