You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/01/29 12:11:33 UTC

[shardingsphere] branch master updated: Add ClusterPersistRepositoryFactory (#15200)

This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang 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 6b874db  Add ClusterPersistRepositoryFactory (#15200)
6b874db is described below

commit 6b874db6a58058435c449ba997e77b1c12ccea7d
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Jan 29 20:10:40 2022 +0800

    Add ClusterPersistRepositoryFactory (#15200)
---
 .../cluster/ClusterContextManagerBuilder.java      | 17 ++-------------
 .../cluster/ClusterPersistRepositoryFactory.java}  | 25 +++++++++++-----------
 .../StandalonePersistRepositoryFactory.java        |  8 +++----
 3 files changed, 19 insertions(+), 31 deletions(-)

diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 6c9f486..2fe5af3 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.mode.manager.cluster;
 
-import com.google.common.base.Preconditions;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.schema.SchemaConfiguration;
@@ -41,9 +40,8 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder;
 import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
 import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
 import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
+import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryFactory;
 import org.apache.shardingsphere.schedule.core.api.ModeScheduleContextFactory;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
 import org.apache.shardingsphere.transaction.context.TransactionContexts;
 import org.apache.shardingsphere.transaction.context.TransactionContextsBuilder;
 
@@ -62,10 +60,6 @@ import java.util.stream.Collectors;
 @Slf4j
 public final class ClusterContextManagerBuilder implements ContextManagerBuilder {
     
-    static {
-        ShardingSphereServiceLoader.register(ClusterPersistRepository.class);
-    }
-    
     private RegistryCenter registryCenter;
     
     private MetaDataPersistService metaDataPersistService;
@@ -88,7 +82,7 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder
     }
     
     private void beforeBuildContextManager(final ContextManagerBuilderParameter parameter) throws SQLException {
-        ClusterPersistRepository repository = createClusterPersistRepository((ClusterPersistRepositoryConfiguration) parameter.getModeConfig().getRepository());
+        ClusterPersistRepository repository = ClusterPersistRepositoryFactory.newInstance((ClusterPersistRepositoryConfiguration) parameter.getModeConfig().getRepository());
         registryCenter = new RegistryCenter(repository);
         ModeScheduleContextFactory.getInstance().init(parameter.getInstanceDefinition().getInstanceId().getId(), parameter.getModeConfig());
         metaDataPersistService = new MetaDataPersistService(repository);
@@ -110,13 +104,6 @@ public final class ClusterContextManagerBuilder implements ContextManagerBuilder
                 parameter.getInstanceDefinition()), new ClusterWorkerIdGenerator(repository, metaDataPersistService, parameter.getInstanceDefinition()), getType());
     }
     
-    private ClusterPersistRepository createClusterPersistRepository(final ClusterPersistRepositoryConfiguration config) {
-        Preconditions.checkNotNull(config, "Cluster persist repository configuration cannot be null.");
-        ClusterPersistRepository result = TypedSPIRegistry.getRegisteredService(ClusterPersistRepository.class, config.getType(), config.getProps());
-        result.init(config);
-        return result;
-    }
-    
     private void persistConfigurations(final MetaDataPersistService metaDataPersistService, final Map<String, ? extends SchemaConfiguration> schemaConfigs, 
                                        final Collection<RuleConfiguration> globalRuleConfigs, final Properties props, final boolean overwrite) {
         if (!isEmptyLocalConfiguration(schemaConfigs, globalRuleConfigs, props)) {
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/standalone/StandalonePersistRepositoryFactory.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/reposit [...]
similarity index 53%
copy from shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/standalone/StandalonePersistRepositoryFactory.java
copy to shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/ClusterPersistRepositoryFactory.java
index bf10e35..bfbd646 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/standalone/StandalonePersistRepositoryFactory.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/ClusterPersistRepositoryFactory.java
@@ -15,33 +15,34 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.mode.repository.standalone;
+package org.apache.shardingsphere.mode.repository.cluster;
 
+import com.google.common.base.Preconditions;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
 import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.required.RequiredSPIRegistry;
 import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
 
 /**
- * Standalone persist repository factory.
+ * Cluster persist repository factory.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class StandalonePersistRepositoryFactory {
+public final class ClusterPersistRepositoryFactory {
     
     static {
-        ShardingSphereServiceLoader.register(StandalonePersistRepository.class);
+        ShardingSphereServiceLoader.register(ClusterPersistRepository.class);
     }
     
     /**
-     * Create new instance of standalone persist repository.
+     * Create new instance of cluster persist repository.
      * 
-     * @param repositoryConfig persist repository configuration
-     * @return new instance of standalone persist repository
+     * @param config persist repository configuration
+     * @return new instance of cluster persist repository
      */
-    public static StandalonePersistRepository newInstance(final PersistRepositoryConfiguration repositoryConfig) {
-        return null == repositoryConfig ? RequiredSPIRegistry.getRegisteredService(StandalonePersistRepository.class)
-                : TypedSPIRegistry.getRegisteredService(StandalonePersistRepository.class, repositoryConfig.getType(), repositoryConfig.getProps());
+    public static ClusterPersistRepository newInstance(final ClusterPersistRepositoryConfiguration config) {
+        Preconditions.checkNotNull(config, "Cluster persist repository configuration cannot be null.");
+        ClusterPersistRepository result = TypedSPIRegistry.getRegisteredService(ClusterPersistRepository.class, config.getType(), config.getProps());
+        result.init(config);
+        return result;
     }
 }
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/standalone/StandalonePersistRepositoryFactory.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-api/src/main/java/org/apache/shardingsphere/mod [...]
index bf10e35..fc8a6cd 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/standalone/StandalonePersistRepositoryFactory.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-repository/shardingsphere-standalone-mode-repository-api/src/main/java/org/apache/shardingsphere/mode/repository/standalone/StandalonePersistRepositoryFactory.java
@@ -37,11 +37,11 @@ public final class StandalonePersistRepositoryFactory {
     /**
      * Create new instance of standalone persist repository.
      * 
-     * @param repositoryConfig persist repository configuration
+     * @param config persist repository configuration
      * @return new instance of standalone persist repository
      */
-    public static StandalonePersistRepository newInstance(final PersistRepositoryConfiguration repositoryConfig) {
-        return null == repositoryConfig ? RequiredSPIRegistry.getRegisteredService(StandalonePersistRepository.class)
-                : TypedSPIRegistry.getRegisteredService(StandalonePersistRepository.class, repositoryConfig.getType(), repositoryConfig.getProps());
+    public static StandalonePersistRepository newInstance(final PersistRepositoryConfiguration config) {
+        return null == config ? RequiredSPIRegistry.getRegisteredService(StandalonePersistRepository.class)
+                : TypedSPIRegistry.getRegisteredService(StandalonePersistRepository.class, config.getType(), config.getProps());
     }
 }