Skip to content

Commit

Permalink
response to CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckyPickleZZ committed Jul 12, 2024
1 parent ac51c27 commit 2e90867
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @date: 2024/7/4
*/
@Data
public class ExecutorInfo {
public class OBExecutionServerInfo {

private String ip;
private String port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> sessionIds, ConnectType connectType) throws SQLException {
DialectType dialectType = connectType.getDialectType();
SqlBuilder sqlBuilder = getBuilder(connectType)
Expand All @@ -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"));
Expand All @@ -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<String> sessionIds, ConnectType connectType) throws SQLException {
DialectType dialectType = connectType.getDialectType();
SqlBuilder sqlBuilder = getBuilder(connectType)
Expand All @@ -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"));
Expand All @@ -495,7 +495,7 @@ public static ExecutorInfo queryPlanIdByTraceIdFromAudit(@NonNull Statement stat
}

public static List<OBSqlPlan> 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, ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<JdbcGeneralResult>> futureResult = connectionSession.getAsyncJdbcExecutor(
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -226,7 +226,7 @@ public SqlExecDetail getExecutionDetailBySql(Connection connection, @NonNull Str
public SqlExplain getQueryProfileByTraceIdAndSessIds(Connection connection, @NonNull String traceId,
@NonNull List<String> 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);
Expand All @@ -253,7 +253,8 @@ public SqlExplain getQueryProfileByTraceIdAndSessIds(Connection connection, @Non
}
}

protected ExecutorInfo getPlanIdByTraceIdAndSessIds(Statement stmt, String traceId, List<String> sessionIds)
protected OBExecutionServerInfo getPlanIdByTraceIdAndSessIds(Statement stmt, String traceId,
List<String> sessionIds)
throws SQLException {
try {
return OBUtils.queryPlanIdByTraceIdFromASH(stmt, traceId, sessionIds, ConnectType.OB_MYSQL);
Expand All @@ -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());
Expand All @@ -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<OBSqlPlan> planRecords = OBUtils.queryOBSqlPlanByPlanId(stmt, executorInfo, ConnectType.OB_MYSQL);
return PlanGraphBuilder.buildPlanGraph(planRecords);
}
Expand All @@ -300,7 +301,7 @@ protected List<SqlPlanMonitor> getSqlPlanMonitorRecords(Statement stmt, String t
* 0 - output...
* </pre>
*/
private SqlExplain innerGetSqlExplainByDbmsXplan(Statement stmt, ExecutorInfo executorInfo)
private SqlExplain innerGetSqlExplainByDbmsXplan(Statement stmt, OBExecutionServerInfo executorInfo)
throws SQLException {
SqlExplain sqlExplain = new SqlExplain();
sqlExplain.setShowFormatInfo(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -183,7 +183,8 @@ protected SqlExecDetail innerGetExecutionDetail(Connection connection, String ap
}

@Override
protected ExecutorInfo getPlanIdByTraceIdAndSessIds(Statement stmt, String traceId, List<String> sessionIds)
protected OBExecutionServerInfo getPlanIdByTraceIdAndSessIds(Statement stmt, String traceId,
List<String> sessionIds)
throws SQLException {
try {
return OBUtils.queryPlanIdByTraceIdFromASH(stmt, traceId, sessionIds, ConnectType.OB_ORACLE);
Expand All @@ -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'")) {
Expand All @@ -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<OBSqlPlan> planRecords = OBUtils.queryOBSqlPlanByPlanId(stmt, executorInfo, ConnectType.OB_ORACLE);
return PlanGraphBuilder.buildPlanGraph(planRecords);
}
Expand Down

0 comments on commit 2e90867

Please sign in to comment.