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 2020/09/22 11:41:52 UTC

[shardingsphere] branch master updated: Revert "Rename shardingsphere-primary-replica-replication module (#7565)" (#7568)

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 1709499  Revert "Rename shardingsphere-primary-replica-replication module (#7565)" (#7568)
1709499 is described below

commit 17094993a7885e1d49af40a76f83b34fcf0bde95
Author: Liang Zhang <te...@163.com>
AuthorDate: Tue Sep 22 19:41:38 2020 +0800

    Revert "Rename shardingsphere-primary-replica-replication module (#7565)" (#7568)
    
    This reverts commit 9a7e4e305e10ddbd805a88420c8e31a40c33f8f1.
---
 shardingsphere-features/pom.xml                    |   2 +-
 .../pom.xml                                        |  10 ++-
 .../shardingsphere-master-slave-api}/pom.xml       |   4 +-
 .../api/config/MasterSlaveRuleConfiguration.java}  |  29 +++---
 .../MasterSlaveDataSourceRuleConfiguration.java}   |  29 +++---
 .../spi/MasterSlaveLoadBalanceAlgorithm.java       |   0
 .../shardingsphere-master-slave-common}/pom.xml    |  15 +++-
 .../RandomMasterSlaveLoadBalanceAlgorithm.java     |   0
 ...RoundRobinMasterSlaveLoadBalanceAlgorithm.java} |  16 ++--
 ...orithmProvidedMasterSlaveRuleConfiguration.java |   0
 .../masterslave/constant/MasterSlaveOrder.java     |   0
 .../rule/MasterSlaveDataSourceRule.java            |   0
 .../masterslave/rule/MasterSlaveRule.java          |   0
 .../AlgorithmProvidedMasterSlaveRuleBuilder.java   |   0
 .../rule/biulder/MasterSlaveRuleBuilder.java       |   0
 .../config/YamlMasterSlaveRuleConfiguration.java}  |  31 ++++---
 ...YamlMasterSlaveDataSourceRuleConfiguration.java |   0
 ...eAlgorithmProviderConfigurationYamlSwapper.java |   0
 .../MasterSlaveRuleConfigurationYamlSwapper.java}  |  43 +++++----
 ...dingsphere.infra.rule.ShardingSphereRuleBuilder |   0
 ...infra.yaml.swapper.YamlRuleConfigurationSwapper |   0
 ...asterslave.spi.MasterSlaveLoadBalanceAlgorithm} |   3 +-
 .../RandomMasterSlaveLoadBalanceAlgorithmTest.java |   0
 ...dRobinMasterSlaveLoadBalanceAlgorithmTest.java} |  13 +--
 .../rule/MasterSlaveDataSourceRuleTest.java        |   0
 .../masterslave/rule/MasterSlaveRuleTest.java      | 100 +++++++++++++++++++++
 ...lgorithmProvidedMasterSlaveRuleBuilderTest.java |   0
 .../rule/biulder/MasterSlaveRuleBuilderTest.java}  |   6 +-
 ...orithmProviderConfigurationYamlSwapperTest.java |   0
 ...asterSlaveRuleConfigurationYamlSwapperTest.java |   0
 ...onsForYamlMasterSlaveRuleConfigurationTest.java |  82 +++++++++++++++++
 .../src/test/resources/logback-test.xml            |   0
 .../src/test/resources/yaml/master-slave-rule.yaml |   0
 .../shardingsphere-master-slave-route}/pom.xml     |  11 ++-
 .../route/engine/MasterSlaveRouteDecorator.java    |  77 ++++++++++++++++
 .../engine/impl/MasterSlaveDataSourceRouter.java   |   0
 .../route/engine/impl/MasterVisitedManager.java}   |  31 +++++--
 ...dingsphere.infra.route.decorator.RouteDecorator |   0
 .../engine/MasterSlaveRouteDecoratorTest.java      |   0
 .../shardingsphere-master-slave-spring}/pom.xml    |   8 +-
 .../pom.xml                                        |   6 +-
 .../MasterSlaveRuleSpringbootConfiguration.java    |   0
 .../MasterSlaveAlgorithmProvidedBeanRegistry.java  |   0
 .../condition/MasterSlaveSpringBootCondition.java  |  38 ++++++++
 ...YamlMasterSlaveRuleSpringBootConfiguration.java |   0
 .../src/main/resources/META-INF/spring.factories}  |   3 +-
 .../src/main/resources/META-INF/spring.provides    |   2 +-
 .../boot/MasterSlaveSpringBootStarterTest.java     |  65 ++++++++++++++
 .../MasterSlaveSpringBootConditionTest.java        |  60 +++++++++++++
 .../resources/application-masterslave.properties}  |   6 +-
 .../src/test/resources/logback-test.xml            |   0
 .../pom.xml                                        |   6 +-
 ...asterSlaveLoadBalanceAlgorithmFactoryBean.java} |  26 ++----
 .../handler/MasterSlaveNamespaceHandler.java       |  37 ++++++++
 .../MasterSlaveRuleBeanDefinitionParser.java       |   0
 .../tag/LoadBalanceAlgorithmBeanDefinitionTag.java |   0
 .../tag/MasterSlaveRuleBeanDefinitionTag.java      |   0
 .../resources/META-INF/namespace/master-slave.xsd  |   0
 .../src/main/resources/META-INF/spring.handlers}   |   2 +-
 .../src/main/resources/META-INF/spring.schemas     |   0
 .../namespace/MasterSlaveSpringNamespaceTest.java  |  85 ++++++++++++++++++
 .../spring/master-slave-application-context.xml    |   0
 .../src/test/resources/logback-test.xml            |   0
 .../shardingsphere-governance-core-common/pom.xml  |   2 +-
 .../shardingsphere-jdbc-core/pom.xml               |   2 +-
 .../pom.xml                                        |   2 +-
 .../pom.xml                                        |   2 +-
 .../pom.xml                                        |   2 +-
 .../shardingsphere-proxy-backend/pom.xml           |   2 +-
 .../shardingsphere-proxy-common/pom.xml            |   2 +-
 70 files changed, 725 insertions(+), 135 deletions(-)

diff --git a/shardingsphere-features/pom.xml b/shardingsphere-features/pom.xml
index ff60577..8e136be 100644
--- a/shardingsphere-features/pom.xml
+++ b/shardingsphere-features/pom.xml
@@ -31,7 +31,7 @@
     
     <modules>
         <module>shardingsphere-sharding</module>
-        <module>shardingsphere-primary-replica-replication</module>
+        <module>shardingsphere-master-slave</module>
         <module>shardingsphere-encrypt</module>
         <module>shardingsphere-shadow</module>
         <module>shardingsphere-consensus-replication</module>
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/pom.xml b/shardingsphere-features/shardingsphere-master-slave/pom.xml
similarity index 79%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/pom.xml
copy to shardingsphere-features/shardingsphere-master-slave/pom.xml
index febd4c2..74a8a7c 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/pom.xml
+++ b/shardingsphere-features/shardingsphere-master-slave/pom.xml
@@ -22,15 +22,17 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-primary-replica-replication</artifactId>
+        <artifactId>shardingsphere-features</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-primary-replica-replication-spring</artifactId>
+    <artifactId>shardingsphere-master-slave</artifactId>
     <name>${project.artifactId}</name>
     <packaging>pom</packaging>
     
     <modules>
-        <module>shardingsphere-primary-replica-replication-spring-namespace</module>
-        <module>shardingsphere-primary-replica-replication-spring-boot-starter</module>
+        <module>shardingsphere-master-slave-api</module>
+        <module>shardingsphere-master-slave-common</module>
+        <module>shardingsphere-master-slave-route</module>
+        <module>shardingsphere-master-slave-spring</module>
     </modules>
 </project>
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/pom.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/pom.xml
similarity index 91%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/pom.xml
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/pom.xml
index 10e5918..f9c19e5 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/pom.xml
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/pom.xml
@@ -22,10 +22,10 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-primary-replica-replication</artifactId>
+        <artifactId>shardingsphere-master-slave</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-primary-replica-replication-api</artifactId>
+    <artifactId>shardingsphere-master-slave-api</artifactId>
     <name>${project.artifactId}</name>
     
     <dependencies>
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/src/main/java/org/apache/shardingsphere/masterslave/spi/MasterSlaveLoadBalanceAlgorithm.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/MasterSlaveRuleConfiguration.java
similarity index 56%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/src/main/java/org/apache/shardingsphere/masterslave/spi/MasterSlaveLoadBalanceAlgorithm.java
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/MasterSlaveRuleConfiguration.java
index 8dedecd..13aaf14 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/src/main/java/org/apache/shardingsphere/masterslave/spi/MasterSlaveLoadBalanceAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/MasterSlaveRuleConfiguration.java
@@ -15,24 +15,25 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.masterslave.spi;
+package org.apache.shardingsphere.masterslave.api.config;
 
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
 
-import java.util.List;
+import java.util.Collection;
+import java.util.Map;
 
 /**
- * Master-slave database load-balance algorithm.
+ * Master-slave rule configuration.
  */
-public interface MasterSlaveLoadBalanceAlgorithm extends ShardingSphereAlgorithm {
+@RequiredArgsConstructor
+@Getter
+public final class MasterSlaveRuleConfiguration implements RuleConfiguration {
     
-    /**
-     * Get data source.
-     * 
-     * @param name master-slave logic data source name
-     * @param masterDataSourceName name of master data sources
-     * @param slaveDataSourceNames names of slave data sources
-     * @return name of selected data source
-     */
-    String getDataSource(String name, String masterDataSourceName, List<String> slaveDataSourceNames);
+    private final Collection<MasterSlaveDataSourceRuleConfiguration> dataSources;
+    
+    private final Map<String, ShardingSphereAlgorithmConfiguration> loadBalancers;
 }
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/constant/MasterSlaveOrder.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/rule/MasterSlaveDataSourceRuleConfiguration.java
similarity index 63%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/constant/MasterSlaveOrder.java
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/rule/MasterSlaveDataSourceRuleConfiguration.java
index 1f56303..32008fd 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/constant/MasterSlaveOrder.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/api/config/rule/MasterSlaveDataSourceRuleConfiguration.java
@@ -15,24 +15,25 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.masterslave.constant;
+package org.apache.shardingsphere.masterslave.api.config.rule;
 
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+import java.util.List;
 
 /**
- * Master-slave order.
+ * Master-slave data source rule configuration.
  */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MasterSlaveOrder {
+@RequiredArgsConstructor
+@Getter
+public final class MasterSlaveDataSourceRuleConfiguration {
+    
+    private final String name;
+    
+    private final String masterDataSourceName;
     
-    /**
-     * Master-slave order.
-     */
-    public static final int ORDER = 10;
+    private final List<String> slaveDataSourceNames;
     
-    /**
-     * Algorithm provider master-slave order.
-     */
-    public static final int ALGORITHM_PROVIDER_MASTER_SLAVE_ORDER = 11;
+    private final String loadBalancerName;
 }
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/src/main/java/org/apache/shardingsphere/masterslave/spi/MasterSlaveLoadBalanceAlgorithm.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/spi/MasterSlaveLoadBalanceAlgorithm.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/src/main/java/org/apache/shardingsphere/masterslave/spi/MasterSlaveLoadBalanceAlgorithm.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-api/src/main/java/org/apache/shardingsphere/masterslave/spi/MasterSlaveLoadBalanceAlgorithm.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/pom.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/pom.xml
similarity index 76%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/pom.xml
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/pom.xml
index 10e5918..3e521d6 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/pom.xml
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/pom.xml
@@ -22,17 +22,26 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-primary-replica-replication</artifactId>
+        <artifactId>shardingsphere-master-slave</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-primary-replica-replication-api</artifactId>
+    <artifactId>shardingsphere-master-slave-common</artifactId>
     <name>${project.artifactId}</name>
     
     <dependencies>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-infra-common</artifactId>
+            <artifactId>shardingsphere-master-slave-api</artifactId>
             <version>${project.version}</version>
         </dependency>
+        
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.zaxxer</groupId>
+            <artifactId>HikariCP</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithm.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithm.java
similarity index 100%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithm.java
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithm.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithm.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RoundRobinMasterSlaveLoadBalanceAlgorithm.java
similarity index 65%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithm.java
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RoundRobinMasterSlaveLoadBalanceAlgorithm.java
index 9b94076..6106213 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RoundRobinMasterSlaveLoadBalanceAlgorithm.java
@@ -23,24 +23,30 @@ import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm
 
 import java.util.List;
 import java.util.Properties;
-import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
- * Random slave database load-balance algorithm.
+ * Round-robin slave database load-balance algorithm.
  */
 @Getter
 @Setter
-public final class RandomMasterSlaveLoadBalanceAlgorithm implements MasterSlaveLoadBalanceAlgorithm {
+public final class RoundRobinMasterSlaveLoadBalanceAlgorithm implements MasterSlaveLoadBalanceAlgorithm {
+    
+    private static final ConcurrentHashMap<String, AtomicInteger> COUNTS = new ConcurrentHashMap<>();
     
     private Properties props = new Properties();
     
     @Override
     public String getDataSource(final String name, final String masterDataSourceName, final List<String> slaveDataSourceNames) {
-        return slaveDataSourceNames.get(ThreadLocalRandom.current().nextInt(slaveDataSourceNames.size()));
+        AtomicInteger count = COUNTS.containsKey(name) ? COUNTS.get(name) : new AtomicInteger(0);
+        COUNTS.putIfAbsent(name, count);
+        count.compareAndSet(slaveDataSourceNames.size(), 0);
+        return slaveDataSourceNames.get(Math.abs(count.getAndIncrement()) % slaveDataSourceNames.size());
     }
     
     @Override
     public String getType() {
-        return "RANDOM";
+        return "ROUND_ROBIN";
     }
 }
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/config/AlgorithmProvidedMasterSlaveRuleConfiguration.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/config/AlgorithmProvidedMasterSlaveRuleConfiguration.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/config/AlgorithmProvidedMasterSlaveRuleConfiguration.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/config/AlgorithmProvidedMasterSlaveRuleConfiguration.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/constant/MasterSlaveOrder.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/constant/MasterSlaveOrder.java
similarity index 100%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/constant/MasterSlaveOrder.java
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/constant/MasterSlaveOrder.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRule.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRule.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRule.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRule.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRule.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRule.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRule.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRule.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilder.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilder.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilder.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilder.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilder.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilder.java
similarity index 100%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilder.java
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilder.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilder.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/config/YamlMasterSlaveRuleConfiguration.java
similarity index 53%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilder.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/config/YamlMasterSlaveRuleConfiguration.java
index f39bc1f..40e0cf8 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilder.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/config/YamlMasterSlaveRuleConfiguration.java
@@ -15,32 +15,31 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.masterslave.rule.biulder;
+package org.apache.shardingsphere.masterslave.yaml.config;
 
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.infra.yaml.config.YamlRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRuleBuilder;
-import org.apache.shardingsphere.masterslave.constant.MasterSlaveOrder;
-import org.apache.shardingsphere.masterslave.rule.MasterSlaveRule;
+import org.apache.shardingsphere.masterslave.yaml.config.rule.YamlMasterSlaveDataSourceRuleConfiguration;
 
-import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 /**
- * Master-slave rule builder.
+ * Master-slave rule configuration for YAML.
  */
-public final class MasterSlaveRuleBuilder implements ShardingSphereRuleBuilder<MasterSlaveRule, MasterSlaveRuleConfiguration> {
+@Getter
+@Setter
+public final class YamlMasterSlaveRuleConfiguration implements YamlRuleConfiguration {
     
-    @Override
-    public MasterSlaveRule build(final MasterSlaveRuleConfiguration ruleConfiguration, final Collection<String> dataSourceNames) {
-        return new MasterSlaveRule(ruleConfiguration);
-    }
+    private Map<String, YamlMasterSlaveDataSourceRuleConfiguration> dataSources = new LinkedHashMap<>();
     
-    @Override
-    public int getOrder() {
-        return MasterSlaveOrder.ORDER;
-    }
+    private Map<String, YamlShardingSphereAlgorithmConfiguration> loadBalancers = new LinkedHashMap<>();
     
     @Override
-    public Class<MasterSlaveRuleConfiguration> getTypeClass() {
+    public Class<MasterSlaveRuleConfiguration> getRuleConfigurationType() {
         return MasterSlaveRuleConfiguration.class;
     }
 }
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/config/rule/YamlMasterSlaveDataSourceRuleConfiguration.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/config/rule/YamlMasterSlaveDataSourceRuleConfiguration.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/config/rule/YamlMasterSlaveDataSourceRuleConfiguration.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/config/rule/YamlMasterSlaveDataSourceRuleConfiguration.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper.java
similarity index 100%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper.java
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapper.java
similarity index 69%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapper.java
index 8eb919d..c070ee8 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapper.java
@@ -17,31 +17,36 @@
 
 package org.apache.shardingsphere.masterslave.yaml.swapper;
 
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-import org.apache.shardingsphere.infra.yaml.config.algorithm.YamlShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper;
-import org.apache.shardingsphere.masterslave.algorithm.config.AlgorithmProvidedMasterSlaveRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.swapper.algorithm.ShardingSphereAlgorithmConfigurationYamlSwapper;
+import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
 import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
 import org.apache.shardingsphere.masterslave.constant.MasterSlaveOrder;
 import org.apache.shardingsphere.masterslave.yaml.config.YamlMasterSlaveRuleConfiguration;
 import org.apache.shardingsphere.masterslave.yaml.config.rule.YamlMasterSlaveDataSourceRuleConfiguration;
 
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
 /**
  * Master-slave rule configuration YAML swapper.
  */
-public final class MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper implements YamlRuleConfigurationSwapper<YamlMasterSlaveRuleConfiguration, AlgorithmProvidedMasterSlaveRuleConfiguration> {
+public final class MasterSlaveRuleConfigurationYamlSwapper implements YamlRuleConfigurationSwapper<YamlMasterSlaveRuleConfiguration, MasterSlaveRuleConfiguration> {
+    
+    private final ShardingSphereAlgorithmConfigurationYamlSwapper algorithmSwapper = new ShardingSphereAlgorithmConfigurationYamlSwapper();
     
     @Override
-    public YamlMasterSlaveRuleConfiguration swapToYamlConfiguration(final AlgorithmProvidedMasterSlaveRuleConfiguration data) {
+    public YamlMasterSlaveRuleConfiguration swapToYamlConfiguration(final MasterSlaveRuleConfiguration data) {
         YamlMasterSlaveRuleConfiguration result = new YamlMasterSlaveRuleConfiguration();
         result.setDataSources(data.getDataSources().stream().collect(
                 Collectors.toMap(MasterSlaveDataSourceRuleConfiguration::getName, this::swapToYamlConfiguration, (a, b) -> b, LinkedHashMap::new)));
-        if (null != data.getLoadBalanceAlgorithms()) {
-            data.getLoadBalanceAlgorithms().forEach((key, value) -> result.getLoadBalancers().put(key, YamlShardingSphereAlgorithmConfiguration.buildByTypedSPI(value)));
+        if (null != data.getLoadBalancers()) {
+            data.getLoadBalancers().forEach((key, value) -> result.getLoadBalancers().put(key, algorithmSwapper.swapToYamlConfiguration(value)));
         }
         return result;
     }
@@ -56,14 +61,16 @@ public final class MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper impl
     }
     
     @Override
-    public AlgorithmProvidedMasterSlaveRuleConfiguration swapToObject(final YamlMasterSlaveRuleConfiguration yamlConfig) {
+    public MasterSlaveRuleConfiguration swapToObject(final YamlMasterSlaveRuleConfiguration yamlConfig) {
         Collection<MasterSlaveDataSourceRuleConfiguration> dataSources = new LinkedList<>();
         for (Entry<String, YamlMasterSlaveDataSourceRuleConfiguration> entry : yamlConfig.getDataSources().entrySet()) {
             dataSources.add(swapToObject(entry.getKey(), entry.getValue()));
         }
-        AlgorithmProvidedMasterSlaveRuleConfiguration ruleConfiguration = new AlgorithmProvidedMasterSlaveRuleConfiguration();
-        ruleConfiguration.setDataSources(dataSources);
-        return ruleConfiguration;
+        Map<String, ShardingSphereAlgorithmConfiguration> loadBalancers = new LinkedHashMap<>(yamlConfig.getLoadBalancers().entrySet().size(), 1);
+        if (null != yamlConfig.getLoadBalancers()) {
+            yamlConfig.getLoadBalancers().forEach((key, value) -> loadBalancers.put(key, algorithmSwapper.swapToObject(value)));
+        }
+        return new MasterSlaveRuleConfiguration(dataSources, loadBalancers);
     }
     
     private MasterSlaveDataSourceRuleConfiguration swapToObject(final String name, final YamlMasterSlaveDataSourceRuleConfiguration yamlDataSourceRuleConfiguration) {
@@ -72,8 +79,8 @@ public final class MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper impl
     }
     
     @Override
-    public Class<AlgorithmProvidedMasterSlaveRuleConfiguration> getTypeClass() {
-        return AlgorithmProvidedMasterSlaveRuleConfiguration.class;
+    public Class<MasterSlaveRuleConfiguration> getTypeClass() {
+        return MasterSlaveRuleConfiguration.class;
     }
     
     @Override
@@ -83,6 +90,6 @@ public final class MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapper impl
     
     @Override
     public int getOrder() {
-        return MasterSlaveOrder.ALGORITHM_PROVIDER_MASTER_SLAVE_ORDER;
+        return MasterSlaveOrder.ORDER;
     }
 }
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.ShardingSphereRuleBuilder b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.ShardingSphereRuleBuilder
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.ShardingSphereRuleBuilder
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.ShardingSphereRuleBuilder
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapper
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm
similarity index 81%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm
index f3fc6a9..aaa245d 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/main/resources/META-INF/services/org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm
@@ -15,4 +15,5 @@
 # limitations under the License.
 #
 
-provides: shardingsphere-primary-replica-replication-spring-boot-starter
+org.apache.shardingsphere.masterslave.algorithm.RoundRobinMasterSlaveLoadBalanceAlgorithm
+org.apache.shardingsphere.masterslave.algorithm.RandomMasterSlaveLoadBalanceAlgorithm
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithmTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithmTest.java
similarity index 100%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithmTest.java
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithmTest.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithmTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/algorithm/RoundRobinMasterSlaveLoadBalanceAlgorithmTest.java
similarity index 62%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithmTest.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/algorithm/RoundRobinMasterSlaveLoadBalanceAlgorithmTest.java
index d5d65f2..2d6b61e 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithmTest.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/algorithm/RoundRobinMasterSlaveLoadBalanceAlgorithmTest.java
@@ -22,11 +22,12 @@ import org.junit.Test;
 import java.util.Arrays;
 import java.util.List;
 
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 
-public final class RandomMasterSlaveLoadBalanceAlgorithmTest {
+public final class RoundRobinMasterSlaveLoadBalanceAlgorithmTest {
     
-    private final RandomMasterSlaveLoadBalanceAlgorithm randomMasterSlaveLoadBalanceAlgorithm = new RandomMasterSlaveLoadBalanceAlgorithm();
+    private final RoundRobinMasterSlaveLoadBalanceAlgorithm roundRobinMasterSlaveLoadBalanceAlgorithm = new RoundRobinMasterSlaveLoadBalanceAlgorithm();
     
     @Test
     public void assertGetDataSource() {
@@ -34,8 +35,8 @@ public final class RandomMasterSlaveLoadBalanceAlgorithmTest {
         String slaveDataSourceName1 = "test_ds_slave_1";
         String slaveDataSourceName2 = "test_ds_slave_2";
         List<String> slaveDataSourceNames = Arrays.asList(slaveDataSourceName1, slaveDataSourceName2);
-        assertTrue(slaveDataSourceNames.contains(randomMasterSlaveLoadBalanceAlgorithm.getDataSource("ds", masterDataSourceName, slaveDataSourceNames)));
-        assertTrue(slaveDataSourceNames.contains(randomMasterSlaveLoadBalanceAlgorithm.getDataSource("ds", masterDataSourceName, slaveDataSourceNames)));
-        assertTrue(slaveDataSourceNames.contains(randomMasterSlaveLoadBalanceAlgorithm.getDataSource("ds", masterDataSourceName, slaveDataSourceNames)));
+        assertThat(roundRobinMasterSlaveLoadBalanceAlgorithm.getDataSource("ds", masterDataSourceName, slaveDataSourceNames), is(slaveDataSourceName1));
+        assertThat(roundRobinMasterSlaveLoadBalanceAlgorithm.getDataSource("ds", masterDataSourceName, slaveDataSourceNames), is(slaveDataSourceName2));
+        assertThat(roundRobinMasterSlaveLoadBalanceAlgorithm.getDataSource("ds", masterDataSourceName, slaveDataSourceNames), is(slaveDataSourceName1));
     }
 }
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRuleTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRuleTest.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRuleTest.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveDataSourceRuleTest.java
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRuleTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRuleTest.java
new file mode 100644
index 0000000..8bab229
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/MasterSlaveRuleTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.masterslave.rule;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
+import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
+import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class MasterSlaveRuleTest {
+    
+    @Test(expected = IllegalArgumentException.class)
+    public void assertNewWithEmptyDataSourceRule() {
+        new MasterSlaveRule(new MasterSlaveRuleConfiguration(Collections.emptyList(), Collections.emptyMap()));
+    }
+    
+    @Test
+    public void assertFindDataSourceRule() {
+        Optional<MasterSlaveDataSourceRule> actual = createMasterSlaveRule().findDataSourceRule("test_ms");
+        assertTrue(actual.isPresent());
+        assertDataSourceRule(actual.get());
+    }
+    
+    @Test
+    public void assertGetSingleDataSourceRule() {
+        assertDataSourceRule(createMasterSlaveRule().getSingleDataSourceRule());
+    }
+    
+    private MasterSlaveRule createMasterSlaveRule() {
+        MasterSlaveDataSourceRuleConfiguration configuration = new MasterSlaveDataSourceRuleConfiguration("test_ms", "master_db", Arrays.asList("slave_db_0", "slave_db_1"), "random");
+        return new MasterSlaveRule(new MasterSlaveRuleConfiguration(
+                Collections.singleton(configuration), ImmutableMap.of("random", new ShardingSphereAlgorithmConfiguration("RANDOM", new Properties()))));
+    }
+    
+    private void assertDataSourceRule(final MasterSlaveDataSourceRule actual) {
+        assertThat(actual.getName(), is("test_ms"));
+        assertThat(actual.getMasterDataSourceName(), is("master_db"));
+        assertThat(actual.getSlaveDataSourceNames(), is(Arrays.asList("slave_db_0", "slave_db_1")));
+        assertThat(actual.getLoadBalancer().getType(), is("RANDOM"));
+    }
+    
+    @Test
+    public void assertUpdateRuleStatusWithNotExistDataSource() {
+        MasterSlaveRule masterSlaveRule = createMasterSlaveRule();
+        masterSlaveRule.updateRuleStatus(new DataSourceNameDisabledEvent("slave_db", true));
+        assertThat(masterSlaveRule.getSingleDataSourceRule().getSlaveDataSourceNames(), is(Arrays.asList("slave_db_0", "slave_db_1")));
+    }
+    
+    @Test
+    public void assertUpdateRuleStatus() {
+        MasterSlaveRule masterSlaveRule = createMasterSlaveRule();
+        masterSlaveRule.updateRuleStatus(new DataSourceNameDisabledEvent("slave_db_0", true));
+        assertThat(masterSlaveRule.getSingleDataSourceRule().getSlaveDataSourceNames(), is(Collections.singletonList("slave_db_1")));
+    }
+    
+    @Test
+    public void assertUpdateRuleStatusWithEnable() {
+        MasterSlaveRule masterSlaveRule = createMasterSlaveRule();
+        masterSlaveRule.updateRuleStatus(new DataSourceNameDisabledEvent("slave_db_0", true));
+        assertThat(masterSlaveRule.getSingleDataSourceRule().getSlaveDataSourceNames(), is(Collections.singletonList("slave_db_1")));
+        masterSlaveRule.updateRuleStatus(new DataSourceNameDisabledEvent("slave_db_0", false));
+        assertThat(masterSlaveRule.getSingleDataSourceRule().getSlaveDataSourceNames(), is(Arrays.asList("slave_db_0", "slave_db_1")));
+    }
+    
+    @Test
+    public void assertGetDataSourceMapper() {
+        MasterSlaveRule masterSlaveRule = createMasterSlaveRule();
+        Map<String, Collection<String>> actual = masterSlaveRule.getDataSourceMapper();
+        Map<String, Collection<String>> expected = ImmutableMap.of("test_ms", Arrays.asList("master_db", "slave_db_0", "slave_db_1"));
+        assertThat(actual, is(expected));
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilderTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilderTest.java
similarity index 100%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilderTest.java
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilderTest.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilderTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilderTest.java
similarity index 88%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilderTest.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilderTest.java
index 177562a..e19a174 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/AlgorithmProvidedMasterSlaveRuleBuilderTest.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilderTest.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.masterslave.rule.biulder;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRuleBuilder;
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.infra.spi.order.OrderedSPIRegistry;
-import org.apache.shardingsphere.masterslave.algorithm.config.AlgorithmProvidedMasterSlaveRuleConfiguration;
+import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
 import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
 import org.apache.shardingsphere.masterslave.rule.MasterSlaveRule;
 import org.junit.Test;
@@ -32,7 +32,7 @@ import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-public final class AlgorithmProvidedMasterSlaveRuleBuilderTest {
+public final class MasterSlaveRuleBuilderTest {
     
     static {
         ShardingSphereServiceLoader.register(ShardingSphereRuleBuilder.class);
@@ -40,7 +40,7 @@ public final class AlgorithmProvidedMasterSlaveRuleBuilderTest {
     
     @Test
     public void assertBuild() {
-        AlgorithmProvidedMasterSlaveRuleConfiguration ruleConfig = mock(AlgorithmProvidedMasterSlaveRuleConfiguration.class);
+        MasterSlaveRuleConfiguration ruleConfig = mock(MasterSlaveRuleConfiguration.class);
         MasterSlaveDataSourceRuleConfiguration ruleConfiguration = new MasterSlaveDataSourceRuleConfiguration("name", "masterDataSourceName",
                 Collections.singletonList("name"), "loadBalancerName");
         when(ruleConfig.getDataSources()).thenReturn(Collections.singletonList(ruleConfiguration));
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapperTest.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapperTest.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleAlgorithmProviderConfigurationYamlSwapperTest.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapperTest.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapperTest.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/MasterSlaveRuleConfigurationYamlSwapperTest.java
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/YamlRootRuleConfigurationsForYamlMasterSlaveRuleConfigurationTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/YamlRootRuleConfigurationsForYamlMasterSlaveRuleConfigurationTest.java
new file mode 100644
index 0000000..37b0b5c
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/yaml/swapper/YamlRootRuleConfigurationsForYamlMasterSlaveRuleConfigurationTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.masterslave.yaml.swapper;
+
+import org.apache.shardingsphere.infra.yaml.config.YamlRootRuleConfigurations;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
+import org.apache.shardingsphere.masterslave.yaml.config.YamlMasterSlaveRuleConfiguration;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Arrays;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+public final class YamlRootRuleConfigurationsForYamlMasterSlaveRuleConfigurationTest {
+    
+    @Test
+    public void assertUnmarshalWithYamlFile() throws IOException {
+        URL url = getClass().getClassLoader().getResource("yaml/master-slave-rule.yaml");
+        assertNotNull(url);
+        YamlRootRuleConfigurations rootRuleConfigurations = YamlEngine.unmarshal(new File(url.getFile()), YamlRootRuleConfigurations.class);
+        assertThat(rootRuleConfigurations.getRules().size(), is(1));
+        assertMasterSlaveRule((YamlMasterSlaveRuleConfiguration) rootRuleConfigurations.getRules().iterator().next());
+    }
+    
+    @Test
+    public void assertUnmarshalWithYamlBytes() throws IOException {
+        URL url = getClass().getClassLoader().getResource("yaml/master-slave-rule.yaml");
+        assertNotNull(url);
+        StringBuilder yamlContent = new StringBuilder();
+        try (
+                FileReader fileReader = new FileReader(url.getFile());
+                BufferedReader reader = new BufferedReader(fileReader)) {
+            String line;
+            while (null != (line = reader.readLine())) {
+                yamlContent.append(line).append(System.lineSeparator());
+            }
+        }
+        YamlRootRuleConfigurations rootRuleConfigs = YamlEngine.unmarshal(yamlContent.toString().getBytes(), YamlRootRuleConfigurations.class);
+        assertThat(rootRuleConfigs.getRules().size(), is(1));
+        assertMasterSlaveRule((YamlMasterSlaveRuleConfiguration) rootRuleConfigs.getRules().iterator().next());
+    }
+    
+    private void assertMasterSlaveRule(final YamlMasterSlaveRuleConfiguration actual) {
+        assertThat(actual.getDataSources().size(), is(2));
+        assertMasterSlaveRuleForDs0(actual);
+        assertMasterSlaveRuleForDs1(actual);
+    }
+    
+    private void assertMasterSlaveRuleForDs0(final YamlMasterSlaveRuleConfiguration actual) {
+        assertThat(actual.getDataSources().get("ds_0").getMasterDataSourceName(), is("master_ds_0"));
+        assertThat(actual.getDataSources().get("ds_0").getSlaveDataSourceNames(), is(Arrays.asList("master_ds_0_slave_0", "master_ds_0_slave_1")));
+        assertThat(actual.getDataSources().get("ds_0").getLoadBalancerName(), is("roundRobin"));
+    }
+    
+    private void assertMasterSlaveRuleForDs1(final YamlMasterSlaveRuleConfiguration actual) {
+        assertThat(actual.getDataSources().get("ds_1").getMasterDataSourceName(), is("master_ds_1"));
+        assertThat(actual.getDataSources().get("ds_1").getSlaveDataSourceNames(), is(Arrays.asList("master_ds_1_slave_0", "master_ds_1_slave_1")));
+        assertThat(actual.getDataSources().get("ds_1").getLoadBalancerName(), is("random"));
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/resources/logback-test.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/resources/logback-test.xml
similarity index 100%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/resources/logback-test.xml
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/resources/logback-test.xml
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/resources/yaml/master-slave-rule.yaml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/resources/yaml/master-slave-rule.yaml
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/resources/yaml/master-slave-rule.yaml
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/resources/yaml/master-slave-rule.yaml
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/pom.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/pom.xml
similarity index 78%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/pom.xml
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/pom.xml
index 10e5918..3e18c9c 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-api/pom.xml
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/pom.xml
@@ -22,16 +22,21 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-primary-replica-replication</artifactId>
+        <artifactId>shardingsphere-master-slave</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-primary-replica-replication-api</artifactId>
+    <artifactId>shardingsphere-master-slave-route</artifactId>
     <name>${project.artifactId}</name>
     
     <dependencies>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-infra-common</artifactId>
+            <artifactId>shardingsphere-infra-route</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-master-slave-common</artifactId>
             <version>${project.version}</version>
         </dependency>
     </dependencies>
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/main/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecorator.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/main/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecorator.java
new file mode 100644
index 0000000..24f67ba
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/main/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecorator.java
@@ -0,0 +1,77 @@
+/*
+ * 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.masterslave.route.engine;
+
+import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import org.apache.shardingsphere.infra.database.DefaultSchema;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.route.context.DefaultRouteStageContext;
+import org.apache.shardingsphere.infra.route.context.RouteContext;
+import org.apache.shardingsphere.infra.route.context.RouteMapper;
+import org.apache.shardingsphere.infra.route.context.RouteResult;
+import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import org.apache.shardingsphere.infra.route.decorator.RouteDecorator;
+import org.apache.shardingsphere.masterslave.constant.MasterSlaveOrder;
+import org.apache.shardingsphere.masterslave.route.engine.impl.MasterSlaveDataSourceRouter;
+import org.apache.shardingsphere.masterslave.rule.MasterSlaveDataSourceRule;
+import org.apache.shardingsphere.masterslave.rule.MasterSlaveRule;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Optional;
+
+/**
+ * Route decorator for master-slave.
+ */
+public final class MasterSlaveRouteDecorator implements RouteDecorator<MasterSlaveRule> {
+    
+    @Override
+    public RouteContext decorate(final RouteContext routeContext, final ShardingSphereMetaData metaData, final MasterSlaveRule masterSlaveRule, final ConfigurationProperties props) {
+        if (routeContext.getRouteResult().getRouteUnits().isEmpty()) {
+            String dataSourceName = new MasterSlaveDataSourceRouter(masterSlaveRule.getSingleDataSourceRule()).route(routeContext.getSqlStatementContext().getSqlStatement());
+            RouteResult routeResult = new RouteResult();
+            routeResult.getRouteUnits().add(new RouteUnit(new RouteMapper(DefaultSchema.LOGIC_NAME, dataSourceName), Collections.emptyList()));
+            return new RouteContext(routeContext, routeResult, new DefaultRouteStageContext(), getTypeClass());
+        }
+        Collection<RouteUnit> toBeRemoved = new LinkedList<>();
+        Collection<RouteUnit> toBeAdded = new LinkedList<>();
+        for (RouteUnit each : routeContext.getRouteResult().getRouteUnits()) {
+            String dataSourceName = each.getDataSourceMapper().getLogicName();
+            Optional<MasterSlaveDataSourceRule> dataSourceRule = masterSlaveRule.findDataSourceRule(dataSourceName);
+            if (dataSourceRule.isPresent() && dataSourceRule.get().getName().equalsIgnoreCase(each.getDataSourceMapper().getActualName())) {
+                toBeRemoved.add(each);
+                String actualDataSourceName = new MasterSlaveDataSourceRouter(dataSourceRule.get()).route(routeContext.getSqlStatementContext().getSqlStatement());
+                toBeAdded.add(new RouteUnit(new RouteMapper(each.getDataSourceMapper().getLogicName(), actualDataSourceName), each.getTableMappers()));
+            }
+        }
+        routeContext.getRouteResult().getRouteUnits().removeAll(toBeRemoved);
+        routeContext.getRouteResult().getRouteUnits().addAll(toBeAdded);
+        return routeContext;
+    }
+    
+    @Override
+    public int getOrder() {
+        return MasterSlaveOrder.ORDER;
+    }
+    
+    @Override
+    public Class<MasterSlaveRule> getTypeClass() {
+        return MasterSlaveRule.class;
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-route/src/main/java/org/apache/shardingsphere/masterslave/route/engine/impl/MasterSlaveDataSourceRouter.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/main/java/org/apache/shardingsphere/masterslave/route/engine/impl/MasterSlaveDataSourceRouter.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-route/src/main/java/org/apache/shardingsphere/masterslave/route/engine/impl/MasterSlaveDataSourceRouter.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/main/java/org/apache/shardingsphere/masterslave/route/engine/impl/MasterSlaveDataSourceRouter.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/constant/MasterSlaveOrder.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/main/java/org/apache/shardingsphere/masterslave/route/engine/impl/MasterVisitedManager.java
similarity index 53%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/constant/MasterSlaveOrder.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/main/java/org/apache/shardingsphere/masterslave/route/engine/impl/MasterVisitedManager.java
index 1f56303..5b1b0df 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/constant/MasterSlaveOrder.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/main/java/org/apache/shardingsphere/masterslave/route/engine/impl/MasterVisitedManager.java
@@ -15,24 +15,41 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.masterslave.constant;
+package org.apache.shardingsphere.masterslave.route.engine.impl;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 
 /**
- * Master-slave order.
+ * Master data source visited manager.
+ * 
+ * <p>Trace master data source visited or not in current thread.</p>
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MasterSlaveOrder {
+public final class MasterVisitedManager {
+    
+    private static final ThreadLocal<Boolean> MASTER_VISITED = ThreadLocal.withInitial(() -> false);
+    
+    /**
+     * Judge master data source visited in current thread.
+     * 
+     * @return master data source visited or not in current thread
+     */
+    public static boolean isMasterVisited() {
+        return MASTER_VISITED.get();
+    }
     
     /**
-     * Master-slave order.
+     * Set master data source visited in current thread.
      */
-    public static final int ORDER = 10;
+    public static void setMasterVisited() {
+        MASTER_VISITED.set(true);
+    }
     
     /**
-     * Algorithm provider master-slave order.
+     * Clear master data source visited.
      */
-    public static final int ALGORITHM_PROVIDER_MASTER_SLAVE_ORDER = 11;
+    public static void clear() {
+        MASTER_VISITED.remove();
+    }
 }
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-route/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.decorator.RouteDecorator b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.decorator.RouteDecorator
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-route/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.decorator.RouteDecorator
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.route.decorator.RouteDecorator
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-route/src/test/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecoratorTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/test/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecoratorTest.java
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-route/src/test/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecoratorTest.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-route/src/test/java/org/apache/shardingsphere/masterslave/route/engine/MasterSlaveRouteDecoratorTest.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/pom.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/pom.xml
similarity index 80%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/pom.xml
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/pom.xml
index febd4c2..9e3701b 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/pom.xml
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/pom.xml
@@ -22,15 +22,15 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-primary-replica-replication</artifactId>
+        <artifactId>shardingsphere-master-slave</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-primary-replica-replication-spring</artifactId>
+    <artifactId>shardingsphere-master-slave-spring</artifactId>
     <name>${project.artifactId}</name>
     <packaging>pom</packaging>
     
     <modules>
-        <module>shardingsphere-primary-replica-replication-spring-namespace</module>
-        <module>shardingsphere-primary-replica-replication-spring-boot-starter</module>
+        <module>shardingsphere-master-slave-spring-namespace</module>
+        <module>shardingsphere-master-slave-spring-boot-starter</module>
     </modules>
 </project>
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/pom.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/pom.xml
similarity index 90%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/pom.xml
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/pom.xml
index 5bdda6d..fd2c57f 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/pom.xml
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/pom.xml
@@ -22,16 +22,16 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-primary-replica-replication-spring</artifactId>
+        <artifactId>shardingsphere-master-slave-spring</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-primary-replica-replication-spring-boot-starter</artifactId>
+    <artifactId>shardingsphere-master-slave-spring-boot-starter</artifactId>
     <name>${project.artifactId}</name>
 
     <dependencies>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-primary-replica-replication-common</artifactId>
+            <artifactId>shardingsphere-master-slave-common</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveRuleSpringbootConfiguration.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spr [...]
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveRuleSpringbootConfiguration.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveRuleSpringbootConfiguration.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/algorithm/MasterSlaveAlgorithmProvidedBeanRegistry.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/mas [...]
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/algorithm/MasterSlaveAlgorithmProvidedBeanRegistry.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/algorithm/MasterSlaveAlgorithmProvidedBeanRegistry.java
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/condition/MasterSlaveSpringBootCondition.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/condition/MasterSlaveSpringBootCon [...]
new file mode 100644
index 0000000..5a31e26
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/condition/MasterSlaveSpringBootCondition.java
@@ -0,0 +1,38 @@
+/*
+ * 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.masterslave.spring.boot.condition;
+
+import org.apache.shardingsphere.spring.boot.util.PropertyUtil;
+import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
+import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+/**
+ * Spring boot condition for master-slave .
+ */
+public final class MasterSlaveSpringBootCondition extends SpringBootCondition {
+    
+    private static final String MASTER_SLAVE_PREFIX = "spring.shardingsphere.rules.master-slave";
+    
+    @Override
+    public ConditionOutcome getMatchOutcome(final ConditionContext conditionContext, final AnnotatedTypeMetadata annotatedTypeMetadata) {
+        return PropertyUtil.containPropertyPrefix(conditionContext.getEnvironment(), MASTER_SLAVE_PREFIX)
+                ? ConditionOutcome.match() : ConditionOutcome.noMatch("Can't find ShardingSphere master-slave rule configuration in local file.");
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/rule/YamlMasterSlaveRuleSpringBootConfiguration.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/master [...]
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/rule/YamlMasterSlaveRuleSpringBootConfiguration.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/java/org/apache/shardingsphere/masterslave/spring/boot/rule/YamlMasterSlaveRuleSpringBootConfiguration.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/resources/META-INF/spring.factories
similarity index 83%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/resources/META-INF/spring.factories
index f3fc6a9..769ba76 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/resources/META-INF/spring.factories
@@ -15,4 +15,5 @@
 # limitations under the License.
 #
 
-provides: shardingsphere-primary-replica-replication-spring-boot-starter
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.shardingsphere.masterslave.spring.boot.MasterSlaveRuleSpringbootConfiguration
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/resources/META-INF/spring.provides
similarity index 91%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/resources/META-INF/spring.provides
index f3fc6a9..3e6b55f 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/main/resources/META-INF/spring.provides
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-provides: shardingsphere-primary-replica-replication-spring-boot-starter
+provides: shardingsphere-master-slave-spring-boot-starter
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootStarterTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootStarterTest.java
new file mode 100644
index 0000000..f1058aa
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/MasterSlaveSpringBootStarterTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.masterslave.spring.boot;
+
+import org.apache.shardingsphere.masterslave.algorithm.RandomMasterSlaveLoadBalanceAlgorithm;
+import org.apache.shardingsphere.masterslave.algorithm.config.AlgorithmProvidedMasterSlaveRuleConfiguration;
+import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.annotation.Resource;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest(classes = MasterSlaveSpringBootStarterTest.class)
+@SpringBootApplication
+@ActiveProfiles("masterslave")
+public class MasterSlaveSpringBootStarterTest {
+    
+    @Resource
+    private RandomMasterSlaveLoadBalanceAlgorithm random;
+    
+    @Resource
+    private AlgorithmProvidedMasterSlaveRuleConfiguration masterSlaveRuleConfiguration;
+    
+    @Test
+    public void assertLoadBalanceAlgorithm() {
+        assertTrue(random.getProps().isEmpty());
+    }
+    
+    @Test
+    public void assertMasterSlaveRuleConfiguration() {
+        assertThat(masterSlaveRuleConfiguration.getDataSources().size(), is(1));
+        MasterSlaveDataSourceRuleConfiguration masterSlaveDataSourceRuleConfiguration = masterSlaveRuleConfiguration.getDataSources().stream().findFirst().get();
+        assertThat(masterSlaveDataSourceRuleConfiguration.getName(), is("ds_ms"));
+        assertThat(masterSlaveDataSourceRuleConfiguration.getMasterDataSourceName(), is("ds_master"));
+        assertThat(masterSlaveDataSourceRuleConfiguration.getLoadBalancerName(), is("random"));
+        assertThat(masterSlaveDataSourceRuleConfiguration.getSlaveDataSourceNames().size(), is(2));
+        assertTrue(masterSlaveRuleConfiguration.getDataSources().contains(masterSlaveDataSourceRuleConfiguration));
+        assertThat(masterSlaveRuleConfiguration.getLoadBalanceAlgorithms().size(), is(1));
+        assertTrue(masterSlaveRuleConfiguration.getLoadBalanceAlgorithms().containsKey("random"));
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/condition/MasterSlaveSpringBootConditionTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/condition/MasterSlaveSpringBoo [...]
new file mode 100644
index 0000000..3a7d43a
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/java/org/apache/shardingsphere/masterslave/spring/boot/condition/MasterSlaveSpringBootConditionTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.masterslave.spring.boot.condition;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+import org.springframework.mock.env.MockEnvironment;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class MasterSlaveSpringBootConditionTest {
+    
+    @Test
+    public void assertNotMatch() {
+        MockEnvironment mockEnvironment = new MockEnvironment();
+        mockEnvironment.setProperty("spring.shardingsphere.rules.encrypt.encryptors.aes_encryptor.type", "AES");
+        mockEnvironment.setProperty("spring.shardingsphere.rules.shadow.column", "user_id");
+        ConditionContext context = mock(ConditionContext.class);
+        AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class);
+        when(context.getEnvironment()).thenReturn(mockEnvironment);
+        MasterSlaveSpringBootCondition condition = new MasterSlaveSpringBootCondition();
+        ConditionOutcome matchOutcome = condition.getMatchOutcome(context, metadata);
+        assertFalse(matchOutcome.isMatch());
+    }
+    
+    @Test
+    public void assertMatch() {
+        MockEnvironment mockEnvironment = new MockEnvironment();
+        mockEnvironment.setProperty("spring.shardingsphere.rules.master-slave.data-sources.ds_ms.master-data-source-name", "ds_master");
+        ConditionContext context = mock(ConditionContext.class);
+        AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class);
+        when(context.getEnvironment()).thenReturn(mockEnvironment);
+        MasterSlaveSpringBootCondition condition = new MasterSlaveSpringBootCondition();
+        ConditionOutcome matchOutcome = condition.getMatchOutcome(context, metadata);
+        assertTrue(matchOutcome.isMatch());
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/application-masterslave.properties
similarity index 68%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/application-masterslave.properties
index f3fc6a9..067dd1f 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-boot-starter/src/main/resources/META-INF/spring.provides
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/application-masterslave.properties
@@ -15,4 +15,8 @@
 # limitations under the License.
 #
 
-provides: shardingsphere-primary-replica-replication-spring-boot-starter
+spring.shardingsphere.rules.master-slave.load-balancers.random.type=RANDOM
+
+spring.shardingsphere.rules.master-slave.data-sources.ds_ms.master-data-source-name=ds_master
+spring.shardingsphere.rules.master-slave.data-sources.ds_ms.slave-data-source-names=ds_slave_0,ds_slave_1
+spring.shardingsphere.rules.master-slave.data-sources.ds_ms.load-balancer-name=random
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/resources/logback-test.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/logback-test.xml
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/test/resources/logback-test.xml
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-boot-starter/src/test/resources/logback-test.xml
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/pom.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/pom.xml
similarity index 88%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/pom.xml
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/pom.xml
index 1303f49..e2fb788 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/pom.xml
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/pom.xml
@@ -22,16 +22,16 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.shardingsphere</groupId>
-        <artifactId>shardingsphere-primary-replica-replication-spring</artifactId>
+        <artifactId>shardingsphere-master-slave-spring</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-primary-replica-replication-spring-namespace</artifactId>
+    <artifactId>shardingsphere-master-slave-spring-namespace</artifactId>
     <name>${project.artifactId}</name>
     
     <dependencies>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-primary-replica-replication-common</artifactId>
+            <artifactId>shardingsphere-master-slave-common</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithm.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/factorybean/MasterSlaveLoadBalanceAlgorithmFactoryBean.java
similarity index 57%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithm.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/factorybean/MasterSlaveLoadBalanceAlgorithmFactoryBean.java
index 9b94076..5c550cb 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-common/src/main/java/org/apache/shardingsphere/masterslave/algorithm/RandomMasterSlaveLoadBalanceAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/factorybean/MasterSlaveLoadBalanceAlgorithmFactoryBean.java
@@ -15,32 +15,24 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.masterslave.algorithm;
+package org.apache.shardingsphere.masterslave.spring.namespace.factorybean;
 
-import lombok.Getter;
-import lombok.Setter;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm;
+import org.apache.shardingsphere.spring.namespace.factorybean.ShardingSphereAlgorithmFactoryBean;
 
-import java.util.List;
 import java.util.Properties;
-import java.util.concurrent.ThreadLocalRandom;
 
 /**
- * Random slave database load-balance algorithm.
+ * Master-slave load balance algorithm factory bean.
  */
-@Getter
-@Setter
-public final class RandomMasterSlaveLoadBalanceAlgorithm implements MasterSlaveLoadBalanceAlgorithm {
+public final class MasterSlaveLoadBalanceAlgorithmFactoryBean extends ShardingSphereAlgorithmFactoryBean<MasterSlaveLoadBalanceAlgorithm> {
     
-    private Properties props = new Properties();
-    
-    @Override
-    public String getDataSource(final String name, final String masterDataSourceName, final List<String> slaveDataSourceNames) {
-        return slaveDataSourceNames.get(ThreadLocalRandom.current().nextInt(slaveDataSourceNames.size()));
+    static {
+        ShardingSphereServiceLoader.register(MasterSlaveLoadBalanceAlgorithm.class);
     }
     
-    @Override
-    public String getType() {
-        return "RANDOM";
+    public MasterSlaveLoadBalanceAlgorithmFactoryBean(final String type, final Properties props) {
+        super(MasterSlaveLoadBalanceAlgorithm.class, type, props);
     }
 }
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/handler/MasterSlaveNamespaceHandler.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/handler/MasterSlaveNamespaceHandler.java
new file mode 100644
index 0000000..2eaf491
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/handler/MasterSlaveNamespaceHandler.java
@@ -0,0 +1,37 @@
+/*
+ * 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.masterslave.spring.namespace.handler;
+
+import org.apache.shardingsphere.masterslave.spring.namespace.factorybean.MasterSlaveLoadBalanceAlgorithmFactoryBean;
+import org.apache.shardingsphere.masterslave.spring.namespace.parser.MasterSlaveRuleBeanDefinitionParser;
+import org.apache.shardingsphere.masterslave.spring.namespace.tag.LoadBalanceAlgorithmBeanDefinitionTag;
+import org.apache.shardingsphere.masterslave.spring.namespace.tag.MasterSlaveRuleBeanDefinitionTag;
+import org.apache.shardingsphere.spring.namespace.parser.ShardingSphereAlgorithmBeanDefinitionParser;
+import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
+
+/**
+ * Spring namespace handler for master-slave.
+ */
+public final class MasterSlaveNamespaceHandler extends NamespaceHandlerSupport {
+    
+    @Override
+    public void init() {
+        registerBeanDefinitionParser(MasterSlaveRuleBeanDefinitionTag.ROOT_TAG, new MasterSlaveRuleBeanDefinitionParser());
+        registerBeanDefinitionParser(LoadBalanceAlgorithmBeanDefinitionTag.ROOT_TAG, new ShardingSphereAlgorithmBeanDefinitionParser(MasterSlaveLoadBalanceAlgorithmFactoryBean.class));
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveRuleBeanDefinitionParser.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/ [...]
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveRuleBeanDefinitionParser.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/parser/MasterSlaveRuleBeanDefinitionParser.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/tag/LoadBalanceAlgorithmBeanDefinitionTag.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/s [...]
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/tag/LoadBalanceAlgorithmBeanDefinitionTag.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/tag/LoadBalanceAlgorithmBeanDefinitionTag.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/tag/MasterSlaveRuleBeanDefinitionTag.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring [...]
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/tag/MasterSlaveRuleBeanDefinitionTag.java
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/java/org/apache/shardingsphere/masterslave/spring/namespace/tag/MasterSlaveRuleBeanDefinitionTag.java
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/resources/META-INF/namespace/master-slave.xsd b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/resources/META-INF/namespace/master-slave.xsd
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/resources/META-INF/namespace/master-slave.xsd
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/resources/META-INF/namespace/master-slave.xsd
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/resources/META-INF/spring.schemas b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/resources/META-INF/spring.handlers
similarity index 89%
copy from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/resources/META-INF/spring.schemas
copy to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/resources/META-INF/spring.handlers
index 847cd0c..2b51f38 100644
--- a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/resources/META-INF/spring.schemas
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/resources/META-INF/spring.handlers
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-http\://shardingsphere.apache.org/schema/shardingsphere/masterslave/master-slave.xsd=META-INF/namespace/master-slave.xsd
+http\://shardingsphere.apache.org/schema/shardingsphere/masterslave=org.apache.shardingsphere.masterslave.spring.namespace.handler.MasterSlaveNamespaceHandler
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/resources/META-INF/spring.schemas b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/resources/META-INF/spring.schemas
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/main/resources/META-INF/spring.schemas
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/main/resources/META-INF/spring.schemas
diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/test/java/org/apache/shardingsphere/masterslave/spring/namespace/MasterSlaveSpringNamespaceTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/test/java/org/apache/shardingsphere/masterslave/spring/namespace/MasterSlaveSpringNamespaceTest.java
new file mode 100644
index 0000000..f449ec4
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/test/java/org/apache/shardingsphere/masterslave/spring/namespace/MasterSlaveSpringNamespaceTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.masterslave.spring.namespace;
+
+import org.apache.shardingsphere.masterslave.algorithm.RandomMasterSlaveLoadBalanceAlgorithm;
+import org.apache.shardingsphere.masterslave.algorithm.config.AlgorithmProvidedMasterSlaveRuleConfiguration;
+import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
+import org.apache.shardingsphere.masterslave.spi.MasterSlaveLoadBalanceAlgorithm;
+import org.junit.Test;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import javax.annotation.Resource;
+import java.util.Arrays;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+@ContextConfiguration(locations = "classpath:META-INF/spring/master-slave-application-context.xml")
+public final class MasterSlaveSpringNamespaceTest extends AbstractJUnit4SpringContextTests {
+    
+    @Resource
+    private MasterSlaveLoadBalanceAlgorithm randomLoadbalancer;
+    
+    @Resource
+    private AlgorithmProvidedMasterSlaveRuleConfiguration defaultMasterSlaveRule;
+    
+    @Resource
+    private AlgorithmProvidedMasterSlaveRuleConfiguration randomMasterSlaveRule;
+    
+    @Test
+    public void assertRandomLoadbalancer() {
+        assertThat(randomLoadbalancer.getType(), is("RANDOM"));
+    }
+    
+    @Test
+    public void assertDefaultMaserSlaveDataSource() {
+        assertLoadBalancers(defaultMasterSlaveRule.getLoadBalanceAlgorithms());
+        assertThat(defaultMasterSlaveRule.getDataSources().size(), is(1));
+        assertDefaultMasterSlaveDataSourceRule(defaultMasterSlaveRule.getDataSources().iterator().next());
+    }
+    
+    private void assertLoadBalancers(final Map<String, MasterSlaveLoadBalanceAlgorithm> loadBalances) {
+        assertThat(loadBalances.size(), is(1));
+        assertThat(loadBalances.get("randomLoadbalancer"), instanceOf(RandomMasterSlaveLoadBalanceAlgorithm.class));
+    }
+    
+    private void assertDefaultMasterSlaveDataSourceRule(final MasterSlaveDataSourceRuleConfiguration dataSourceRuleConfig) {
+        assertThat(dataSourceRuleConfig.getName(), is("default_ds"));
+        assertThat(dataSourceRuleConfig.getMasterDataSourceName(), is("master_ds"));
+        assertThat(dataSourceRuleConfig.getSlaveDataSourceNames(), is(Arrays.asList("slave_ds_0", "slave_ds_1")));
+        assertThat(dataSourceRuleConfig.getLoadBalancerName(), is(""));
+    }
+    
+    @Test
+    public void assertRandomMaserSlaveDataSource() {
+        assertLoadBalancers(randomMasterSlaveRule.getLoadBalanceAlgorithms());
+        assertThat(randomMasterSlaveRule.getDataSources().size(), is(1));
+        assertRandomMasterSlaveDataSourceRule(randomMasterSlaveRule.getDataSources().iterator().next());
+    }
+    
+    private void assertRandomMasterSlaveDataSourceRule(final MasterSlaveDataSourceRuleConfiguration dataSourceRuleConfig) {
+        assertThat(dataSourceRuleConfig.getName(), is("random_ds"));
+        assertThat(dataSourceRuleConfig.getMasterDataSourceName(), is("master_ds"));
+        assertThat(dataSourceRuleConfig.getSlaveDataSourceNames(), is(Arrays.asList("slave_ds_0", "slave_ds_1")));
+        assertThat(dataSourceRuleConfig.getLoadBalancerName(), is("randomLoadbalancer"));
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/test/resources/META-INF/spring/master-slave-application-context.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/test/resources/META-INF/spring/master-slave-application-context.xml
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/test/resources/META-INF/spring/master-slave-application-context.xml
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/test/resources/META-INF/spring/master-slave-application-context.xml
diff --git a/shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/test/resources/logback-test.xml b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/test/resources/logback-test.xml
similarity index 100%
rename from shardingsphere-features/shardingsphere-primary-replica-replication/shardingsphere-primary-replica-replication-spring/shardingsphere-primary-replica-replication-spring-namespace/src/test/resources/logback-test.xml
rename to shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-spring/shardingsphere-master-slave-spring-namespace/src/test/resources/logback-test.xml
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-common/pom.xml b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-common/pom.xml
index f691a91..b894242 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-common/pom.xml
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-common/pom.xml
@@ -39,7 +39,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-primary-replica-replication-common</artifactId>
+            <artifactId>shardingsphere-master-slave-common</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/pom.xml b/shardingsphere-jdbc/shardingsphere-jdbc-core/pom.xml
index 9d02d8a..c736f30 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/pom.xml
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/pom.xml
@@ -69,7 +69,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-primary-replica-replication-route</artifactId>
+            <artifactId>shardingsphere-master-slave-route</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/pom.xml b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/pom.xml
index 906c589..2f26129 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/pom.xml
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/pom.xml
@@ -44,7 +44,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-primary-replica-replication-spring-boot-starter</artifactId>
+            <artifactId>shardingsphere-master-slave-spring-boot-starter</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/pom.xml b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/pom.xml
index 86ef15c..43292b5 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/pom.xml
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/pom.xml
@@ -40,7 +40,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-primary-replica-replication-spring-namespace</artifactId>
+            <artifactId>shardingsphere-master-slave-spring-namespace</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/pom.xml b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/pom.xml
index a54a7d4..c0184b4 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/pom.xml
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-governance-spring/shardingsphere-jdbc-governance-spring-boot-starter/pom.xml
@@ -44,7 +44,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-primary-replica-replication-spring-boot-starter</artifactId>
+            <artifactId>shardingsphere-master-slave-spring-boot-starter</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
index 4f8c70e..caa5b9e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
@@ -79,7 +79,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-primary-replica-replication-route</artifactId>
+            <artifactId>shardingsphere-master-slave-route</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml b/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
index 3e28017..68575c7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
@@ -49,7 +49,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-primary-replica-replication-common</artifactId>
+            <artifactId>shardingsphere-master-slave-common</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>