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 2023/03/31 17:42:24 UTC
[shardingsphere] branch master updated: Fix spot bugs JLM (#24928)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 9cc463ee731 Fix spot bugs JLM (#24928)
9cc463ee731 is described below
commit 9cc463ee73119dd64dcf67795001c21866f2f5b9
Author: Chuxin Chen <ch...@qq.com>
AuthorDate: Sat Apr 1 01:42:16 2023 +0800
Fix spot bugs JLM (#24928)
* Fix spot bugs JLM
---
.../data/pipeline/core/api/PipelineAPIFactory.java | 27 ++--------------------
.../core/execute/ShardingSphereDataJobWorker.java | 9 +-------
src/resources/spotbugs.xml | 15 ------------
3 files changed, 3 insertions(+), 48 deletions(-)
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/PipelineAPIFactory.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/PipelineAPIFactory.java
index 20edaa8f642..d1c536b9dc9 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/PipelineAPIFactory.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/api/PipelineAPIFactory.java
@@ -128,18 +128,7 @@ public final class PipelineAPIFactory {
}
public static ElasticJobAPIHolder getInstance(final PipelineContextKey contextKey) {
- ElasticJobAPIHolder result = INSTANCE_MAP.get(contextKey);
- if (null != result) {
- return result;
- }
- synchronized (INSTANCE_MAP) {
- result = INSTANCE_MAP.get(contextKey);
- if (null == result) {
- result = new ElasticJobAPIHolder(contextKey);
- INSTANCE_MAP.put(contextKey, result);
- }
- }
- return result;
+ return INSTANCE_MAP.computeIfAbsent(contextKey, key -> new ElasticJobAPIHolder(contextKey));
}
}
@@ -148,19 +137,7 @@ public final class PipelineAPIFactory {
private static final Map<PipelineContextKey, CoordinatorRegistryCenter> INSTANCE_MAP = new ConcurrentHashMap<>();
public static CoordinatorRegistryCenter getInstance(final PipelineContextKey contextKey) {
- // TODO Extract common method; Reduce lock time
- CoordinatorRegistryCenter result = INSTANCE_MAP.get(contextKey);
- if (null != result) {
- return result;
- }
- synchronized (INSTANCE_MAP) {
- result = INSTANCE_MAP.get(contextKey);
- if (null == result) {
- result = createRegistryCenter(contextKey);
- INSTANCE_MAP.put(contextKey, result);
- }
- }
- return result;
+ return INSTANCE_MAP.computeIfAbsent(contextKey, key -> createRegistryCenter(contextKey));
}
private static CoordinatorRegistryCenter createRegistryCenter(final PipelineContextKey contextKey) {
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ShardingSphereDataJobWorker.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ShardingSphereDataJobWorker.java
index 5fbd4496a73..fadda08b8e3 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ShardingSphereDataJobWorker.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ShardingSphereDataJobWorker.java
@@ -35,18 +35,11 @@ public final class ShardingSphereDataJobWorker {
* @param contextManager context manager
*/
public static void initialize(final ContextManager contextManager) {
- if (WORKER_INITIALIZED.get()) {
- return;
- }
- synchronized (WORKER_INITIALIZED) {
- if (WORKER_INITIALIZED.get()) {
- return;
- }
+ if (WORKER_INITIALIZED.compareAndSet(false, true)) {
boolean collectorEnabled = contextManager.getMetaDataContexts().getMetaData().getInternalProps().getValue(InternalConfigurationPropertyKey.PROXY_META_DATA_COLLECTOR_ENABLED);
if (collectorEnabled) {
startScheduleThread(contextManager);
}
- WORKER_INITIALIZED.set(true);
}
}
diff --git a/src/resources/spotbugs.xml b/src/resources/spotbugs.xml
index a28552fd12a..22a6461089d 100644
--- a/src/resources/spotbugs.xml
+++ b/src/resources/spotbugs.xml
@@ -112,16 +112,6 @@
<Class name="org.apache.shardingsphere.data.pipeline.mysql.ingest.client.MySQLClient" />
<Bug code="IS" />
</Match>
- <!-- TODO chuxin fix the ignored bug -->
- <Match>
- <Class name="org.apache.shardingsphere.data.pipeline.core.execute.ShardingSphereDataJobWorker" />
- <Bug code="JLM" />
- </Match>
- <!-- TODO chuxin fix the ignored bug -->
- <Match>
- <Class name="org.apache.shardingsphere.data.pipeline.core.execute.PipelineJobWorker" />
- <Bug code="JLM" />
- </Match>
<!-- TODO zhengqiang fix the ignored bug -->
<Match>
<Class name="org.apache.shardingsphere.sqlfederation.original.OriginalSQLFederationExecutor" />
@@ -132,9 +122,4 @@
<Class name="org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.OpenGaussSystemCatalogAdminQueryExecutor" />
<Bug code="ODR" />
</Match>
- <!-- TODO hongsheng fix the ignored bug -->
- <Match>
- <Class name="org.apache.shardingsphere.data.pipeline.core.api.PipelineAPIFactory" />
- <Bug code="JLM" />
- </Match>
</FindBugsFilter>