feat(oceanbase-oracle): split execution time from client wait
This commit is contained in:
1 parent
1294708eea
commit
33afb0b432
58 files changed
+843
-11
No files matched your search
@@ -595,6 +595,10 @@ public abstract class AbstractJdbcAgent extends BaseDatabaseAgent {
|
||||
protected void beforeQueryExecution(Connection connection, int timeoutSecs) throws Exception {
|
||||
}
|
||||
|
||||
/** Called for each session RPC before its SQL can replace the connection's last trace ID. */
|
||||
protected void beforeAgentMethod(String method, String querySessionId) {
|
||||
}
|
||||
|
||||
protected boolean advancePastUpdateCounts() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,11 @@ public final class JdbcExecutor {
|
||||
return AgentExecutionContext.jdbcExecutor();
|
||||
}
|
||||
|
||||
public static int statementMaxRows(int maxRows) {
|
||||
int effectiveMaxRows = Math.max(maxRows, 1);
|
||||
return effectiveMaxRows == Integer.MAX_VALUE ? Integer.MAX_VALUE : effectiveMaxRows + 1;
|
||||
}
|
||||
|
||||
public QueryResult execute(Connection conn, String sql, String schema, Function<String, String> setSchemaSql) {
|
||||
return execute(conn, sql, schema, setSchemaSql, DEFAULT_MAX_ROWS, null, this::defaultResultValue);
|
||||
}
|
||||
@@ -141,7 +146,7 @@ public final class JdbcExecutor {
|
||||
activeStatements.add(stmt);
|
||||
try {
|
||||
int effectiveMaxRows = Math.max(maxRows, 1);
|
||||
stmt.setMaxRows(effectiveMaxRows + 1);
|
||||
stmt.setMaxRows(statementMaxRows(maxRows));
|
||||
applyQueryTimeout(stmt, timeoutSecs);
|
||||
if (fetchSize != null && fetchSize > 0) {
|
||||
stmt.setFetchSize(fetchSize);
|
||||
@@ -734,7 +739,7 @@ public final class JdbcExecutor {
|
||||
while (rows.size() < effectivePageSize && session.rowsRead < session.maxRows) {
|
||||
if (!session.resultSet.next()) {
|
||||
closeSession(targetSessions, session.id);
|
||||
return new QueryPageResult(session.columns, session.columnTypes, rows, 0L, executionTimeMs, false, null, false);
|
||||
return sessionPageResult(session, rows, executionTimeMs, false, null, false);
|
||||
}
|
||||
rows.add(rowValues(session.resultSet, session.valueReader, session.sqlTypeByIndex, session.typeNameByIndex));
|
||||
session.rowsRead += 1;
|
||||
@@ -743,21 +748,34 @@ public final class JdbcExecutor {
|
||||
if (session.rowsRead >= session.maxRows) {
|
||||
boolean truncated = session.resultSet.next();
|
||||
closeSession(targetSessions, session.id);
|
||||
return new QueryPageResult(session.columns, session.columnTypes, rows, 0L, executionTimeMs, truncated, null, false);
|
||||
return sessionPageResult(session, rows, executionTimeMs, truncated, null, false);
|
||||
}
|
||||
|
||||
boolean hasMore = session.resultSet.next();
|
||||
if (!hasMore) {
|
||||
closeSession(targetSessions, session.id);
|
||||
return new QueryPageResult(session.columns, session.columnTypes, rows, 0L, executionTimeMs, false, null, false);
|
||||
return sessionPageResult(session, rows, executionTimeMs, false, null, false);
|
||||
}
|
||||
|
||||
session.pendingRow = rowValues(session.resultSet, session.valueReader, session.sqlTypeByIndex, session.typeNameByIndex);
|
||||
session.rowsRead += 1;
|
||||
return new QueryPageResult(session.columns, session.columnTypes, rows, 0L, executionTimeMs, false, session.id, true);
|
||||
return sessionPageResult(session, rows, executionTimeMs, false, session.id, true);
|
||||
});
|
||||
}
|
||||
|
||||
private static QueryPageResult sessionPageResult(
|
||||
QuerySession session,
|
||||
List<List<Object>> rows,
|
||||
long executionTimeMs,
|
||||
boolean truncated,
|
||||
String sessionId,
|
||||
boolean hasMore
|
||||
) {
|
||||
QueryPageResult result = new QueryPageResult(session.columns, session.columnTypes, rows, 0L, executionTimeMs, truncated, sessionId, hasMore);
|
||||
result.setCursor_rows_read(session.rowsRead);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void closeAllSessions(ConcurrentHashMap<String, QuerySession> targetSessions) {
|
||||
List<String> ids = new ArrayList<>(targetSessions.keySet());
|
||||
for (String id : ids) {
|
||||
|
||||
@@ -151,6 +151,9 @@ public final class JsonRpcServer {
|
||||
}
|
||||
|
||||
private Object dispatch(String method, JsonObject params) throws Exception {
|
||||
if (agent instanceof AbstractJdbcAgent observingAgent) {
|
||||
observingAgent.beforeAgentMethod(method, stringOrNull(params, "sessionId"));
|
||||
}
|
||||
if (AgentProtocol.METHOD_HANDSHAKE.equals(method)) {
|
||||
return AgentProtocol.handshakeResult();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ public final class QueryPageResult {
|
||||
private List<List<Object>> rows;
|
||||
private long affected_rows;
|
||||
private long execution_time_ms;
|
||||
private Long server_execute_time_us;
|
||||
/** Number of rows read by this JDBC cursor across all pages; never sent over JSON RPC. */
|
||||
private transient long cursor_rows_read;
|
||||
private boolean truncated;
|
||||
private String session_id;
|
||||
private boolean has_more;
|
||||
@@ -97,6 +100,14 @@ public final class QueryPageResult {
|
||||
return execution_time_ms;
|
||||
}
|
||||
|
||||
public Long getServer_execute_time_us() {
|
||||
return server_execute_time_us;
|
||||
}
|
||||
|
||||
public long getCursor_rows_read() {
|
||||
return cursor_rows_read;
|
||||
}
|
||||
|
||||
public boolean getTruncated() {
|
||||
return truncated;
|
||||
}
|
||||
@@ -140,6 +151,14 @@ public final class QueryPageResult {
|
||||
this.execution_time_ms = execution_time_ms;
|
||||
}
|
||||
|
||||
public void setServer_execute_time_us(Long server_execute_time_us) {
|
||||
this.server_execute_time_us = server_execute_time_us;
|
||||
}
|
||||
|
||||
public void setCursor_rows_read(long cursor_rows_read) {
|
||||
this.cursor_rows_read = cursor_rows_read;
|
||||
}
|
||||
|
||||
public void setTruncated(boolean truncated) {
|
||||
this.truncated = truncated;
|
||||
}
|
||||
@@ -159,6 +178,7 @@ public final class QueryPageResult {
|
||||
QueryPageResult that = (QueryPageResult) other;
|
||||
return affected_rows == that.affected_rows
|
||||
&& execution_time_ms == that.execution_time_ms
|
||||
&& Objects.equals(server_execute_time_us, that.server_execute_time_us)
|
||||
&& truncated == that.truncated
|
||||
&& has_more == that.has_more
|
||||
&& Objects.equals(columns, that.columns)
|
||||
@@ -171,7 +191,7 @@ public final class QueryPageResult {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(columns, column_types, spatial_columns, spatial_values, rows, affected_rows, execution_time_ms, truncated, session_id, has_more);
|
||||
return Objects.hash(columns, column_types, spatial_columns, spatial_values, rows, affected_rows, execution_time_ms, server_execute_time_us, truncated, session_id, has_more);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,6 +203,7 @@ public final class QueryPageResult {
|
||||
+ ", rows=" + rows
|
||||
+ ", affected_rows=" + affected_rows
|
||||
+ ", execution_time_ms=" + execution_time_ms
|
||||
+ ", server_execute_time_us=" + server_execute_time_us
|
||||
+ ", truncated=" + truncated
|
||||
+ ", session_id=" + session_id
|
||||
+ ", has_more=" + has_more
|
||||
|
||||
@@ -17,6 +17,7 @@ public final class QueryResult {
|
||||
private List<List<Object>> rows;
|
||||
private long affected_rows;
|
||||
private long execution_time_ms;
|
||||
private Long server_execute_time_us;
|
||||
private boolean truncated;
|
||||
|
||||
public QueryResult() {
|
||||
@@ -84,6 +85,10 @@ public final class QueryResult {
|
||||
return execution_time_ms;
|
||||
}
|
||||
|
||||
public Long getServer_execute_time_us() {
|
||||
return server_execute_time_us;
|
||||
}
|
||||
|
||||
public boolean getTruncated() {
|
||||
return truncated;
|
||||
}
|
||||
@@ -119,6 +124,10 @@ public final class QueryResult {
|
||||
this.execution_time_ms = execution_time_ms;
|
||||
}
|
||||
|
||||
public void setServer_execute_time_us(Long server_execute_time_us) {
|
||||
this.server_execute_time_us = server_execute_time_us;
|
||||
}
|
||||
|
||||
public void setTruncated(boolean truncated) {
|
||||
this.truncated = truncated;
|
||||
}
|
||||
@@ -190,6 +199,7 @@ public final class QueryResult {
|
||||
QueryResult that = (QueryResult) other;
|
||||
return affected_rows == that.affected_rows
|
||||
&& execution_time_ms == that.execution_time_ms
|
||||
&& Objects.equals(server_execute_time_us, that.server_execute_time_us)
|
||||
&& truncated == that.truncated
|
||||
&& Objects.equals(columns, that.columns)
|
||||
&& Objects.equals(column_types, that.column_types)
|
||||
@@ -200,7 +210,7 @@ public final class QueryResult {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(columns, column_types, spatial_columns, spatial_values, rows, affected_rows, execution_time_ms, truncated);
|
||||
return Objects.hash(columns, column_types, spatial_columns, spatial_values, rows, affected_rows, execution_time_ms, server_execute_time_us, truncated);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -212,6 +222,7 @@ public final class QueryResult {
|
||||
+ ", rows=" + rows
|
||||
+ ", affected_rows=" + affected_rows
|
||||
+ ", execution_time_ms=" + execution_time_ms
|
||||
+ ", server_execute_time_us=" + server_execute_time_us
|
||||
+ ", truncated=" + truncated
|
||||
+ ")";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user