You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/05/01 13:27:55 UTC
[shardingsphere] branch master updated: Add RowBasedJobLockFactory and RuleBasedJobLockFactory (#17258)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 ad8e6c79190 Add RowBasedJobLockFactory and RuleBasedJobLockFactory (#17258)
ad8e6c79190 is described below
commit ad8e6c79190aa922b55191e55e6cce346c16caa8
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun May 1 21:27:46 2022 +0800
Add RowBasedJobLockFactory and RuleBasedJobLockFactory (#17258)
---
.../pipeline/spi/lock/RowBasedJobLockFactory.java | 43 ++++++++++++++++++++++
.../pipeline/spi/lock/RuleBasedJobLockFactory.java | 43 ++++++++++++++++++++++
.../scenario/rulealtered/RuleAlteredContext.java | 19 ++++------
3 files changed, 93 insertions(+), 12 deletions(-)
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/lock/RowBasedJobLockFactory.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/lock/RowBasedJobLockFactory.java
new file mode 100644
index 00000000000..9d57faf1d0c
--- /dev/null
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/lock/RowBasedJobLockFactory.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.spi.lock;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.required.RequiredSPIRegistry;
+
+/**
+ * Row based job lock factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class RowBasedJobLockFactory {
+
+ static {
+ ShardingSphereServiceLoader.register(RowBasedJobLock.class);
+ }
+
+ /**
+ * Create new instance of row based job lock.
+ *
+ * @return new instance of row based job lock
+ */
+ public static RowBasedJobLock newInstance() {
+ return RequiredSPIRegistry.getRegisteredService(RowBasedJobLock.class);
+ }
+}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/lock/RuleBasedJobLockFactory.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/lock/RuleBasedJobLockFactory.java
new file mode 100644
index 00000000000..279e99eceb3
--- /dev/null
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/lock/RuleBasedJobLockFactory.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.spi.lock;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.required.RequiredSPIRegistry;
+
+/**
+ * Rule based job lock factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class RuleBasedJobLockFactory {
+
+ static {
+ ShardingSphereServiceLoader.register(RuleBasedJobLock.class);
+ }
+
+ /**
+ * Create new instance of rule based job lock.
+ *
+ * @return new instance of rule based job lock
+ */
+ public static RuleBasedJobLock newInstance() {
+ return RequiredSPIRegistry.getRegisteredService(RuleBasedJobLock.class);
+ }
+}
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 a6240b4d81d..a8c29e0edf2 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
@@ -29,7 +29,9 @@ import org.apache.shardingsphere.data.pipeline.spi.detect.JobCompletionDetectAlg
import org.apache.shardingsphere.data.pipeline.spi.ingest.channel.PipelineChannelCreator;
import org.apache.shardingsphere.data.pipeline.spi.ingest.channel.PipelineChannelCreatorFactory;
import org.apache.shardingsphere.data.pipeline.spi.lock.RowBasedJobLock;
+import org.apache.shardingsphere.data.pipeline.spi.lock.RowBasedJobLockFactory;
import org.apache.shardingsphere.data.pipeline.spi.lock.RuleBasedJobLock;
+import org.apache.shardingsphere.data.pipeline.spi.lock.RuleBasedJobLockFactory;
import org.apache.shardingsphere.data.pipeline.spi.ratelimit.JobRateLimitAlgorithm;
import org.apache.shardingsphere.data.pipeline.spi.ratelimit.JobRateLimitAlgorithmFactory;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
@@ -41,8 +43,6 @@ import org.apache.shardingsphere.infra.yaml.config.pojo.rulealtered.YamlOnRuleAl
import org.apache.shardingsphere.infra.yaml.config.pojo.rulealtered.YamlOnRuleAlteredActionConfiguration.YamlInputConfiguration;
import org.apache.shardingsphere.infra.yaml.config.pojo.rulealtered.YamlOnRuleAlteredActionConfiguration.YamlOutputConfiguration;
import org.apache.shardingsphere.infra.yaml.config.swapper.rulealtered.OnRuleAlteredActionConfigurationYamlSwapper;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.type.required.RequiredSPIRegistry;
import java.util.Properties;
@@ -54,12 +54,7 @@ import java.util.Properties;
// TODO extract Pipeline Context
public final class RuleAlteredContext {
- private static final OnRuleAlteredActionConfigurationYamlSwapper ACTION_CONFIG_YAML_SWAPPER = new OnRuleAlteredActionConfigurationYamlSwapper();
-
- static {
- ShardingSphereServiceLoader.register(RowBasedJobLock.class);
- ShardingSphereServiceLoader.register(RuleBasedJobLock.class);
- }
+ private static final OnRuleAlteredActionConfigurationYamlSwapper SWAPPER = new OnRuleAlteredActionConfigurationYamlSwapper();
private final OnRuleAlteredActionConfiguration onRuleAlteredActionConfig;
@@ -101,15 +96,15 @@ public final class RuleAlteredContext {
dataConsistencyCalculateAlgorithm = null != dataConsistencyCheckerConfig
? DataConsistencyCalculateAlgorithmFactory.newInstance(dataConsistencyCheckerConfig.getType(), dataConsistencyCheckerConfig.getProps())
: null;
- rowBasedJobLock = RequiredSPIRegistry.getRegisteredService(RowBasedJobLock.class);
- ruleBasedJobLock = RequiredSPIRegistry.getRegisteredService(RuleBasedJobLock.class);
+ rowBasedJobLock = RowBasedJobLockFactory.newInstance();
+ ruleBasedJobLock = RuleBasedJobLockFactory.newInstance();
inventoryDumperExecuteEngine = ExecuteEngine.newFixedThreadInstance(inputConfig.getWorkerThread());
incrementalDumperExecuteEngine = ExecuteEngine.newCachedThreadInstance();
importerExecuteEngine = ExecuteEngine.newFixedThreadInstance(outputConfig.getWorkerThread());
}
private OnRuleAlteredActionConfiguration convertActionConfig(final OnRuleAlteredActionConfiguration actionConfig) {
- YamlOnRuleAlteredActionConfiguration yamlActionConfig = ACTION_CONFIG_YAML_SWAPPER.swapToYamlConfiguration(actionConfig);
+ YamlOnRuleAlteredActionConfiguration yamlActionConfig = SWAPPER.swapToYamlConfiguration(actionConfig);
if (null == yamlActionConfig.getInput()) {
yamlActionConfig.setInput(YamlInputConfiguration.buildWithDefaultValue());
}
@@ -119,6 +114,6 @@ public final class RuleAlteredContext {
if (null == yamlActionConfig.getStreamChannel()) {
yamlActionConfig.setStreamChannel(new YamlShardingSphereAlgorithmConfiguration(MemoryPipelineChannelCreator.TYPE, new Properties()));
}
- return ACTION_CONFIG_YAML_SWAPPER.swapToObject(yamlActionConfig);
+ return SWAPPER.swapToObject(yamlActionConfig);
}
}