You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/05/13 09:42:26 UTC
[shardingsphere] branch master updated: Make Scaling threads' name unique (#17633)
This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 a6c954a648d Make Scaling threads' name unique (#17633)
a6c954a648d is described below
commit a6c954a648d9ae182a01b44930fd068f34eaa85d
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Fri May 13 17:42:19 2022 +0800
Make Scaling threads' name unique (#17633)
---
.../data/pipeline/core/execute/ExecuteEngine.java | 16 +++++++++++-----
.../scenario/rulealtered/RuleAlteredContext.java | 14 ++++++++++----
.../scenario/rulealtered/RuleAlteredJobWorker.java | 2 +-
.../data/pipeline/core/execute/ExecuteEngineTest.java | 4 ++--
.../data/pipeline/core/util/PipelineContextUtil.java | 2 +-
5 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngine.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngine.java
index aed8c4a3f7e..aea7e3b9964 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngine.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngine.java
@@ -40,27 +40,33 @@ import java.util.concurrent.Future;
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class ExecuteEngine {
- public static final String THREAD_NAME_FORMAT = "Scaling-execute-%d";
+ private static final String SCALING_THREAD_PREFIX = "Scaling-";
+
+ private static final String SCALING_THREAD_SUFFIX = "-%d";
private final ListeningExecutorService executorService;
/**
* Create task execute engine instance with cached thread pool.
*
+ * @param threadName thread name
* @return task execute engine instance
*/
- public static ExecuteEngine newCachedThreadInstance() {
- return new ExecuteEngine(MoreExecutors.listeningDecorator(Executors.newCachedThreadPool(ExecutorThreadFactoryBuilder.build(THREAD_NAME_FORMAT))));
+ public static ExecuteEngine newCachedThreadInstance(final String threadName) {
+ String threadNameFormat = SCALING_THREAD_PREFIX + threadName + SCALING_THREAD_SUFFIX;
+ return new ExecuteEngine(MoreExecutors.listeningDecorator(Executors.newCachedThreadPool(ExecutorThreadFactoryBuilder.build(threadNameFormat))));
}
/**
* Create task execute engine instance with fixed thread pool.
*
* @param threadNumber thread number
+ * @param threadName thread name
* @return task execute engine instance
*/
- public static ExecuteEngine newFixedThreadInstance(final int threadNumber) {
- return new ExecuteEngine(MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threadNumber, ExecutorThreadFactoryBuilder.build(THREAD_NAME_FORMAT))));
+ public static ExecuteEngine newFixedThreadInstance(final int threadNumber, final String threadName) {
+ String threadNameFormat = SCALING_THREAD_PREFIX + threadName + SCALING_THREAD_SUFFIX;
+ return new ExecuteEngine(MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threadNumber, ExecutorThreadFactoryBuilder.build(threadNameFormat))));
}
/**
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredContext.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredContext.java
index a7c0f8a8469..3d0761a9365 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredContext.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredContext.java
@@ -54,6 +54,12 @@ import java.util.Properties;
// TODO extract Pipeline Context
public final class RuleAlteredContext {
+ private static final String INVENTORY_THREAD_PREFIX = "Inventory-";
+
+ private static final String INCREMENTAL_THREAD_PREFIX = "Incremental-";
+
+ private static final String IMPORTER_THREAD_PREFIX = "Importer-";
+
private static final OnRuleAlteredActionConfigurationYamlSwapper SWAPPER = new OnRuleAlteredActionConfigurationYamlSwapper();
private final OnRuleAlteredActionConfiguration onRuleAlteredActionConfig;
@@ -79,7 +85,7 @@ public final class RuleAlteredContext {
private final ExecuteEngine importerExecuteEngine;
@SuppressWarnings("unchecked")
- public RuleAlteredContext(final OnRuleAlteredActionConfiguration actionConfig) {
+ public RuleAlteredContext(final String jobId, final OnRuleAlteredActionConfiguration actionConfig) {
OnRuleAlteredActionConfiguration onRuleAlteredActionConfig = convertActionConfig(actionConfig);
this.onRuleAlteredActionConfig = onRuleAlteredActionConfig;
InputConfiguration inputConfig = onRuleAlteredActionConfig.getInput();
@@ -98,9 +104,9 @@ public final class RuleAlteredContext {
: null;
rowBasedJobLock = RowBasedJobLockFactory.getInstance();
ruleBasedJobLock = RuleBasedJobLockFactory.getInstance();
- inventoryDumperExecuteEngine = ExecuteEngine.newFixedThreadInstance(inputConfig.getWorkerThread());
- incrementalDumperExecuteEngine = ExecuteEngine.newCachedThreadInstance();
- importerExecuteEngine = ExecuteEngine.newFixedThreadInstance(outputConfig.getWorkerThread());
+ inventoryDumperExecuteEngine = ExecuteEngine.newFixedThreadInstance(inputConfig.getWorkerThread(), INVENTORY_THREAD_PREFIX + jobId);
+ incrementalDumperExecuteEngine = ExecuteEngine.newCachedThreadInstance(INCREMENTAL_THREAD_PREFIX + jobId);
+ importerExecuteEngine = ExecuteEngine.newFixedThreadInstance(outputConfig.getWorkerThread(), IMPORTER_THREAD_PREFIX + jobId);
}
private OnRuleAlteredActionConfiguration convertActionConfig(final OnRuleAlteredActionConfiguration actionConfig) {
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorker.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorker.java
index 2a457aa8ed8..9f9adfbac22 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorker.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorker.java
@@ -139,7 +139,7 @@ public final class RuleAlteredJobWorker {
log.error("rule altered action enabled but actor is not configured, ignored, ruleConfig={}", ruleConfig);
throw new PipelineJobCreationException("rule altered actor not configured");
}
- return new RuleAlteredContext(onRuleAlteredActionConfig.get());
+ return new RuleAlteredContext(jobConfig.getJobId(), onRuleAlteredActionConfig.get());
}
/**
diff --git a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngineTest.java b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngineTest.java
index 9a1d0b7f410..dc6a816e387 100644
--- a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngineTest.java
+++ b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/execute/ExecuteEngineTest.java
@@ -32,7 +32,7 @@ public final class ExecuteEngineTest {
@Test
public void assertSubmitMoreThanMaxWorkerNumber() {
- ExecuteEngine executeEngine = ExecuteEngine.newFixedThreadInstance(2);
+ ExecuteEngine executeEngine = ExecuteEngine.newFixedThreadInstance(2, ExecuteEngineTest.class.getSimpleName());
try {
for (int i = 0; i < 5; i++) {
Future<?> submit = executeEngine.submit(mockScalingExecutor());
@@ -45,7 +45,7 @@ public final class ExecuteEngineTest {
@Test
public void assertSubmitAllMoreThanMaxWorkerNumber() {
- ExecuteEngine executeEngine = ExecuteEngine.newFixedThreadInstance(2);
+ ExecuteEngine executeEngine = ExecuteEngine.newFixedThreadInstance(2, ExecuteEngineTest.class.getSimpleName());
try {
for (int i = 0; i < 5; i++) {
Future<?> submit = executeEngine.submitAll(Collections.singletonList(mockScalingExecutor()), mockExecuteCallback());
diff --git a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java
index f422196ec16..3915b3502ad 100644
--- a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java
+++ b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineContextUtil.java
@@ -48,7 +48,7 @@ import java.util.Properties;
public final class PipelineContextUtil {
- private static final ExecuteEngine EXECUTE_ENGINE = ExecuteEngine.newCachedThreadInstance();
+ private static final ExecuteEngine EXECUTE_ENGINE = ExecuteEngine.newCachedThreadInstance(PipelineContextUtil.class.getSimpleName());
private static final PipelineChannelCreator PIPELINE_CHANNEL_CREATOR = new MemoryPipelineChannelCreator();