You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2023/04/29 14:44:11 UTC
[shardingsphere] branch master updated: Refactor ProcessReporter.reportComplete() (#25413)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new d0a3c5eb0e6 Refactor ProcessReporter.reportComplete() (#25413)
d0a3c5eb0e6 is described below
commit d0a3c5eb0e68c51deba86020e79bbeb771cea6d9
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 29 22:44:04 2023 +0800
Refactor ProcessReporter.reportComplete() (#25413)
---
.../sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java | 2 +-
.../sql/execute/engine/raw/callback/RawSQLExecutorCallback.java | 5 +----
.../shardingsphere/infra/executor/sql/process/ProcessContext.java | 8 +++++---
.../shardingsphere/infra/executor/sql/process/ProcessEngine.java | 6 ++++--
.../infra/executor/sql/process/ProcessReporter.java | 5 +++--
.../infra/executor/sql/process/ProcessReporterTest.java | 2 +-
6 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java
index ce41216f46a..eb26d4003a5 100644
--- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java
+++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutorCallback.java
@@ -84,7 +84,7 @@ public abstract class JDBCExecutorCallback<T> implements ExecutorCallback<JDBCEx
sqlExecutionHook.start(jdbcExecutionUnit.getExecutionUnit().getDataSourceName(), sqlUnit.getSql(), sqlUnit.getParameters(), dataSourceMetaData, isTrunkThread);
T result = executeSQL(sqlUnit.getSql(), jdbcExecutionUnit.getStorageResource(), jdbcExecutionUnit.getConnectionMode(), storageType);
sqlExecutionHook.finishSuccess();
- new ProcessEngine().finishExecution();
+ new ProcessEngine().finishExecution(1);
return result;
} catch (final SQLException ex) {
if (!storageType.equals(protocolType)) {
diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawSQLExecutorCallback.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawSQLExecutorCallback.java
index fda9ae97ed0..9aedb8f4f1d 100644
--- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawSQLExecutorCallback.java
+++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/raw/callback/RawSQLExecutorCallback.java
@@ -46,10 +46,7 @@ public final class RawSQLExecutorCallback implements ExecutorCallback<RawSQLExec
public Collection<ExecuteResult> execute(final Collection<RawSQLExecutionUnit> inputs, final boolean isTrunkThread) throws SQLException {
Collection<ExecuteResult> result = callbacks.iterator().next().execute(inputs, isTrunkThread);
if (!ExecuteIDContext.isEmpty()) {
- ProcessEngine processEngine = new ProcessEngine();
- for (int i = 0; i < inputs.size(); i++) {
- processEngine.finishExecution();
- }
+ new ProcessEngine().finishExecution(inputs.size());
}
return result;
}
diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessContext.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessContext.java
index 671a86298f7..dcb5b939475 100644
--- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessContext.java
+++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessContext.java
@@ -90,10 +90,12 @@ public final class ProcessContext {
}
/**
- * Complete one execute unit.
+ * Complete execution units.
+ *
+ * @param completedExecutionUnitCount completed execution unit count
*/
- public void completeOne() {
- completedUnitCount.incrementAndGet();
+ public void completeExecutionUnits(final int completedExecutionUnitCount) {
+ completedUnitCount.addAndGet(completedExecutionUnitCount);
}
/**
diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngine.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngine.java
index 23cd0e1d098..46ab40cb4dc 100644
--- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngine.java
+++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngine.java
@@ -68,12 +68,14 @@ public final class ProcessEngine {
/**
* Finish execution.
+ *
+ * @param completedExecutionUnitCount completed execution unit count
*/
- public void finishExecution() {
+ public void finishExecution(final int completedExecutionUnitCount) {
if (ExecuteIDContext.isEmpty()) {
return;
}
- reporter.reportComplete(ExecuteIDContext.get());
+ reporter.reportComplete(ExecuteIDContext.get(), completedExecutionUnitCount);
}
/**
diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessReporter.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessReporter.java
index 9f10715abae..e5c70a88e95 100644
--- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessReporter.java
+++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessReporter.java
@@ -61,9 +61,10 @@ public final class ProcessReporter {
* Report complete execution unit.
*
* @param executionID execution ID
+ * @param completedExecutionUnitCount completed execution unit count
*/
- public void reportComplete(final String executionID) {
- ShowProcessListManager.getInstance().getProcessContext(executionID).completeOne();
+ public void reportComplete(final String executionID, final int completedExecutionUnitCount) {
+ ShowProcessListManager.getInstance().getProcessContext(executionID).completeExecutionUnits(completedExecutionUnitCount);
}
/**
diff --git a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessReporterTest.java b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessReporterTest.java
index 4642b82ef2d..5fdbf0890d5 100644
--- a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessReporterTest.java
+++ b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessReporterTest.java
@@ -67,7 +67,7 @@ class ProcessReporterTest {
@Test
void assertReportUnit() {
when(showProcessListManager.getProcessContext("foo_id")).thenReturn(mock(ProcessContext.class));
- new ProcessReporter().reportComplete("foo_id");
+ new ProcessReporter().reportComplete("foo_id", 1);
verify(showProcessListManager).getProcessContext("foo_id");
}