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

chengzhang 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 ccc03ae3d3f Replace load balancer algorithm with infra load balancer 
algorithm (#30310)
ccc03ae3d3f is described below

commit ccc03ae3d3f44fce2b2229afe4f1a0faf2193c92
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Tue Feb 27 13:39:35 2024 +0800

    Replace load balancer algorithm with infra load balancer algorithm (#30310)
---
 .../spi/ReadQueryLoadBalanceAlgorithm.java         |  38 ------
 features/readwrite-splitting/core/pom.xml          |  15 +++
 .../RandomReadQueryLoadBalanceAlgorithm.java       |  39 ------
 .../RoundRobinReadQueryLoadBalanceAlgorithm.java   |  46 -------
 .../WeightReadQueryLoadBalanceAlgorithm.java       | 135 ---------------------
 ...ReadwriteSplittingRuleConfigurationChecker.java |  22 ++--
 .../InvalidReadDatabaseWeightException.java        |  33 -----
 ...oadBalanceAlgorithmInitializationExcpetion.java |  30 -----
 ...MissingRequiredReadDatabaseWeightException.java |   2 +-
 ...StandardReadwriteSplittingDataSourceRouter.java |   2 +-
 .../rule/ReadwriteSplittingDataSourceRule.java     |   6 +-
 .../rule/ReadwriteSplittingRule.java               |  16 +--
 ...ritesplitting.spi.ReadQueryLoadBalanceAlgorithm |  20 ---
 .../RandomReadQueryLoadBalanceAlgorithmTest.java   |  49 --------
 ...oundRobinReadQueryLoadBalanceAlgorithmTest.java |  50 --------
 .../WeightReadQueryLoadBalanceAlgorithmTest.java   |  66 ----------
 ...SplittingTransactionalDataSourceRouterTest.java |   6 +-
 ...dardReadwriteSplittingDataSourceRouterTest.java |   4 +-
 .../filter/DisabledReadDataSourcesFilterTest.java  |   4 +-
 .../rule/ReadwriteSplittingDataSourceRuleTest.java |   4 +-
 .../ReadwriteSplittingRuleStatementChecker.java    |   6 +-
 ...ueryLoadBalanceAlgorithmTypeAndClassMapper.java |   6 +-
 ...istSQLReadQueryLoadBalanceAlgorithmFixture.java |   8 +-
 ...iteSplittingRuleConfigurationImportChecker.java |   6 +-
 24 files changed, 61 insertions(+), 552 deletions(-)

diff --git 
a/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/spi/ReadQueryLoadBalanceAlgorithm.java
 
b/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/spi/ReadQueryLoadBalanceAlgorithm.java
deleted file mode 100644
index 7ede832d8b4..00000000000
--- 
a/features/readwrite-splitting/api/src/main/java/org/apache/shardingsphere/readwritesplitting/spi/ReadQueryLoadBalanceAlgorithm.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.readwritesplitting.spi;
-
-import org.apache.shardingsphere.infra.algorithm.core.ShardingSphereAlgorithm;
-
-import java.util.List;
-
-/**
- * Read query load-balance algorithm.
- */
-public interface ReadQueryLoadBalanceAlgorithm extends ShardingSphereAlgorithm 
{
-    
-    /**
-     * Get data source.
-     * 
-     * @param name read query logic data source name
-     * @param writeDataSourceName name of write data source
-     * @param readDataSourceNames names of read data sources
-     * @return name of selected data source
-     */
-    String getDataSource(String name, String writeDataSourceName, List<String> 
readDataSourceNames);
-}
diff --git a/features/readwrite-splitting/core/pom.xml 
b/features/readwrite-splitting/core/pom.xml
index 19ce0ab88ec..cf71068225d 100644
--- a/features/readwrite-splitting/core/pom.xml
+++ b/features/readwrite-splitting/core/pom.xml
@@ -53,6 +53,21 @@
             <artifactId>shardingsphere-infra-expr-core</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            
<artifactId>shardingsphere-infra-algorithm-load-balancer-random</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            
<artifactId>shardingsphere-infra-algorithm-load-balancer-round-robin</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            
<artifactId>shardingsphere-infra-algorithm-load-balancer-weight</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RandomReadQueryLoadBalanceAlgorithm.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RandomReadQueryLoadBalanceAlgorithm.java
deleted file mode 100644
index c9494400dc9..00000000000
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RandomReadQueryLoadBalanceAlgorithm.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.readwritesplitting.algorithm.loadbalance;
-
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
-
-import java.util.List;
-import java.util.concurrent.ThreadLocalRandom;
-
-/**
- * Random read query load-balance algorithm.
- */
-public final class RandomReadQueryLoadBalanceAlgorithm implements 
ReadQueryLoadBalanceAlgorithm {
-    
-    @Override
-    public String getDataSource(final String name, final String 
writeDataSourceName, final List<String> readDataSourceNames) {
-        return 
readDataSourceNames.get(ThreadLocalRandom.current().nextInt(readDataSourceNames.size()));
-    }
-    
-    @Override
-    public String getType() {
-        return "RANDOM";
-    }
-}
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RoundRobinReadQueryLoadBalanceAlgorithm.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RoundRobinReadQueryLoadBalanceAlgorithm.java
deleted file mode 100644
index 8484d1433fb..00000000000
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RoundRobinReadQueryLoadBalanceAlgorithm.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.readwritesplitting.algorithm.loadbalance;
-
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
-
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Round-robin read query load-balance algorithm.
- */
-public final class RoundRobinReadQueryLoadBalanceAlgorithm implements 
ReadQueryLoadBalanceAlgorithm {
-    
-    private final AtomicInteger count = new AtomicInteger(0);
-    
-    @Override
-    public String getDataSource(final String name, final String 
writeDataSourceName, final List<String> readDataSourceNames) {
-        return readDataSourceNames.get(Math.abs(count.getAndIncrement()) % 
readDataSourceNames.size());
-    }
-    
-    @Override
-    public String getType() {
-        return "ROUND_ROBIN";
-    }
-    
-    @Override
-    public boolean isDefault() {
-        return true;
-    }
-}
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithm.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithm.java
deleted file mode 100644
index 0c1a8a8b6c9..00000000000
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithm.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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.readwritesplitting.algorithm.loadbalance;
-
-import com.google.common.base.Preconditions;
-import lombok.Getter;
-import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import 
org.apache.shardingsphere.readwritesplitting.exception.algorithm.InvalidReadDatabaseWeightException;
-import 
org.apache.shardingsphere.readwritesplitting.exception.algorithm.ReadQueryLoadBalanceAlgorithmInitializationExcpetion;
-import 
org.apache.shardingsphere.readwritesplitting.exception.algorithm.MissingRequiredReadDatabaseWeightException;
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ThreadLocalRandom;
-
-/**
- * Weight read query load-balance algorithm.
- */
-public final class WeightReadQueryLoadBalanceAlgorithm implements 
ReadQueryLoadBalanceAlgorithm {
-    
-    private static final double ACCURACY_THRESHOLD = 0.0001;
-    
-    private final Map<String, double[]> weightMap = new ConcurrentHashMap<>();
-    
-    private Properties props;
-    
-    @Getter
-    private Collection<String> dataSourceNames;
-    
-    @Override
-    public void init(final Properties props) {
-        this.props = props;
-        dataSourceNames = props.stringPropertyNames();
-        ShardingSpherePreconditions.checkState(!dataSourceNames.isEmpty(), () 
-> new ReadQueryLoadBalanceAlgorithmInitializationExcpetion(getType(), "Read 
data source is required"));
-        for (String dataSourceName : dataSourceNames) {
-            String weight = props.getProperty(dataSourceName);
-            ShardingSpherePreconditions.checkNotNull(weight,
-                    () -> new 
MissingRequiredReadDatabaseWeightException(getType(), String.format("Read 
database `%s` access weight is not configured.", dataSourceName)));
-            try {
-                Double.parseDouble(weight);
-            } catch (final NumberFormatException ex) {
-                throw new InvalidReadDatabaseWeightException(weight);
-            }
-        }
-    }
-    
-    @Override
-    public String getDataSource(final String name, final String 
writeDataSourceName, final List<String> readDataSourceNames) {
-        double[] weight = weightMap.containsKey(name) && 
weightMap.get(name).length == readDataSourceNames.size() ? weightMap.get(name) 
: initWeight(readDataSourceNames);
-        weightMap.put(name, weight);
-        return getDataSourceName(readDataSourceNames, weight);
-    }
-    
-    private String getDataSourceName(final List<String> readDataSourceNames, 
final double[] weight) {
-        double randomWeight = ThreadLocalRandom.current().nextDouble(0, 1);
-        int index = Arrays.binarySearch(weight, randomWeight);
-        if (index < 0) {
-            index = -index - 1;
-            return index < weight.length && randomWeight < weight[index] ? 
readDataSourceNames.get(index) : 
readDataSourceNames.get(readDataSourceNames.size() - 1);
-        }
-        return readDataSourceNames.get(index);
-    }
-    
-    private double[] initWeight(final List<String> readDataSourceNames) {
-        double[] result = getWeights(readDataSourceNames);
-        Preconditions.checkState(!(0 != result.length && 
Math.abs(result[result.length - 1] - 1.0D) >= ACCURACY_THRESHOLD),
-                "The cumulative weight is calculated incorrectly, and the sum 
of the probabilities is not equal to 1");
-        return result;
-    }
-    
-    private double[] getWeights(final List<String> readDataSourceNames) {
-        double[] exactWeights = new double[readDataSourceNames.size()];
-        int index = 0;
-        double sum = 0D;
-        for (String readDataSourceName : readDataSourceNames) {
-            double weight = getWeightValue(readDataSourceName);
-            exactWeights[index++] = weight;
-            sum += weight;
-        }
-        for (int i = 0; i < index; i++) {
-            if (exactWeights[i] <= 0) {
-                continue;
-            }
-            exactWeights[i] = exactWeights[i] / sum;
-        }
-        return calculateWeight(exactWeights);
-    }
-    
-    private double[] calculateWeight(final double[] exactWeights) {
-        double[] result = new double[exactWeights.length];
-        double randomRange = 0D;
-        for (int i = 0; i < result.length; i++) {
-            result[i] = randomRange + exactWeights[i];
-            randomRange += exactWeights[i];
-        }
-        return result;
-    }
-    
-    private double getWeightValue(final String readDataSourceName) {
-        Object weightObject = props.get(readDataSourceName);
-        double result = Double.parseDouble(weightObject.toString());
-        if (Double.isInfinite(result)) {
-            result = 10000.0D;
-        }
-        if (Double.isNaN(result)) {
-            result = 1.0D;
-        }
-        return result;
-    }
-    
-    @Override
-    public String getType() {
-        return "WEIGHT";
-    }
-}
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
index 932396f5ea7..c94594d0280 100644
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
+++ 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
@@ -18,25 +18,25 @@
 package org.apache.shardingsphere.readwritesplitting.checker;
 
 import com.google.common.base.Strings;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.core.LoadBalanceAlgorithm;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.weight.WeightLoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import 
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import 
org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.WeightReadQueryLoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingOrder;
-import 
org.apache.shardingsphere.readwritesplitting.exception.algorithm.MissingRequiredReadDatabaseWeightException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.DataSourceNameNotExistedException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.DuplicateDataSourceException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.InvalidWeightLoadBalancerConfigurationException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.LoadBalancerAlgorithmNotFoundException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredDataSourceNameException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredReadDataSourceNamesException;
+import 
org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredReadDatabaseWeightException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredWriteDataSourceNameException;
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
 
 import javax.sql.DataSource;
 import java.util.Collection;
@@ -107,26 +107,26 @@ public final class 
ReadwriteSplittingRuleConfigurationChecker implements RuleCon
     }
     
     private void checkLoadBalancerDataSourceName(final String databaseName, 
final Collection<ReadwriteSplittingDataSourceRuleConfiguration> configs,
-                                                 final Map<String, 
ReadQueryLoadBalanceAlgorithm> loadBalancers) {
+                                                 final Map<String, 
LoadBalanceAlgorithm> loadBalancers) {
         for (ReadwriteSplittingDataSourceRuleConfiguration each : configs) {
             if (Strings.isNullOrEmpty(each.getLoadBalancerName())) {
                 continue;
             }
-            ReadQueryLoadBalanceAlgorithm loadBalancer = 
loadBalancers.get(each.getLoadBalancerName());
+            LoadBalanceAlgorithm loadBalancer = 
loadBalancers.get(each.getLoadBalancerName());
             ShardingSpherePreconditions.checkNotNull(loadBalancer, () -> new 
LoadBalancerAlgorithmNotFoundException(databaseName));
-            if (loadBalancer instanceof WeightReadQueryLoadBalanceAlgorithm) {
-                
ShardingSpherePreconditions.checkState(!((WeightReadQueryLoadBalanceAlgorithm) 
loadBalancer).getDataSourceNames().isEmpty(),
+            if (loadBalancer instanceof WeightLoadBalanceAlgorithm) {
+                
ShardingSpherePreconditions.checkState(!((WeightLoadBalanceAlgorithm) 
loadBalancer).getAvailableTargetNames().isEmpty(),
                         () -> new 
MissingRequiredReadDatabaseWeightException(loadBalancer.getType(), 
String.format("Read data source weight config are required in database `%s`", 
databaseName)));
                 Collection<String> dataSourceNames = 
each.getReadDataSourceNames();
-                ((WeightReadQueryLoadBalanceAlgorithm) 
loadBalancer).getDataSourceNames().forEach(dataSourceName -> 
ShardingSpherePreconditions.checkState(dataSourceNames.contains(dataSourceName),
+                ((WeightLoadBalanceAlgorithm) 
loadBalancer).getAvailableTargetNames().forEach(dataSourceName -> 
ShardingSpherePreconditions.checkState(dataSourceNames.contains(dataSourceName),
                         () -> new 
InvalidWeightLoadBalancerConfigurationException(databaseName)));
             }
         }
     }
     
-    private Map<String, ReadQueryLoadBalanceAlgorithm> getLoadBalancer(final 
ReadwriteSplittingRuleConfiguration config) {
-        Map<String, ReadQueryLoadBalanceAlgorithm> result = new 
LinkedHashMap<>(config.getLoadBalancers().size(), 1F);
-        config.getLoadBalancers().forEach((key, value) -> result.put(key, 
TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, value.getType(), 
value.getProps())));
+    private Map<String, LoadBalanceAlgorithm> getLoadBalancer(final 
ReadwriteSplittingRuleConfiguration config) {
+        Map<String, LoadBalanceAlgorithm> result = new 
LinkedHashMap<>(config.getLoadBalancers().size(), 1F);
+        config.getLoadBalancers().forEach((key, value) -> result.put(key, 
TypedSPILoader.getService(LoadBalanceAlgorithm.class, value.getType(), 
value.getProps())));
         return result;
     }
     
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/InvalidReadDatabaseWeightException.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/InvalidReadDatabaseWeightException.java
deleted file mode 100644
index dc431917672..00000000000
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/InvalidReadDatabaseWeightException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.readwritesplitting.exception.algorithm;
-
-import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-import 
org.apache.shardingsphere.readwritesplitting.exception.ReadwriteSplittingSQLException;
-
-/**
- * Invalid read database weight exception.
- */
-public final class InvalidReadDatabaseWeightException extends 
ReadwriteSplittingSQLException {
-    
-    private static final long serialVersionUID = -846600820893274188L;
-    
-    public InvalidReadDatabaseWeightException(final Object weight) {
-        super(XOpenSQLState.INVALID_DATA_TYPE, 80, "Invalid read database 
weight `%s`.", weight);
-    }
-}
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/ReadQueryLoadBalanceAlgorithmInitializationExcpetion.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/ReadQueryLoadBalanceAlgorithmInitializationExcpetion.java
deleted file mode 100644
index 1bb2d37460c..00000000000
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/ReadQueryLoadBalanceAlgorithmInitializationExcpetion.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.readwritesplitting.exception.algorithm;
-
-import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-import 
org.apache.shardingsphere.readwritesplitting.exception.ReadwriteSplittingSQLException;
-
-public class ReadQueryLoadBalanceAlgorithmInitializationExcpetion extends 
ReadwriteSplittingSQLException {
-    
-    private static final long serialVersionUID = -8673960967175624027L;
-    
-    public ReadQueryLoadBalanceAlgorithmInitializationExcpetion(final String 
loadBalanceAlgorithmType, final String reason) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 83, "'%s' read query load 
balance algorithm initialization failed, reason is: %s.", 
loadBalanceAlgorithmType, reason);
-    }
-}
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/MissingRequiredReadDatabaseWeightException.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/MissingRequiredReadDatabaseWeightException.java
similarity index 95%
rename from 
features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/MissingRequiredReadDatabaseWeightException.java
rename to 
features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/MissingRequiredReadDatabaseWeightException.java
index e05249e34d5..b61f09bdf30 100644
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/MissingRequiredReadDatabaseWeightException.java
+++ 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/checker/MissingRequiredReadDatabaseWeightException.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.readwritesplitting.exception.algorithm;
+package org.apache.shardingsphere.readwritesplitting.exception.checker;
 
 import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
 import 
org.apache.shardingsphere.readwritesplitting.exception.ReadwriteSplittingSQLException;
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/standard/StandardReadwriteSplittingDataSourceRouter.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/standard/StandardReadwriteSplittingDataSourceRouter.java
index f7b5a20e233..03f7d641e86 100644
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/standard/StandardReadwriteSplittingDataSourceRouter.java
+++ 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/route/standard/StandardReadwriteSplittingDataSourceRouter.java
@@ -35,7 +35,7 @@ public final class StandardReadwriteSplittingDataSourceRouter 
{
      * @return routed data source name
      */
     public String route(final ReadwriteSplittingDataSourceRule rule) {
-        return rule.getLoadBalancer().getDataSource(rule.getName(), 
rule.getWriteDataSource(), getFilteredReadDataSources(rule));
+        return rule.getLoadBalancer().getAvailableTargetName(rule.getName(), 
getFilteredReadDataSources(rule));
     }
     
     private List<String> getFilteredReadDataSources(final 
ReadwriteSplittingDataSourceRule rule) {
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
index 0cee8049a20..59bd0007e7a 100644
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
+++ 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRule.java
@@ -18,9 +18,9 @@
 package org.apache.shardingsphere.readwritesplitting.rule;
 
 import lombok.Getter;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.core.LoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.readwritesplitting.group.ReadwriteSplittingGroup;
 import 
org.apache.shardingsphere.readwritesplitting.group.type.StaticReadwriteSplittingGroup;
 
@@ -37,14 +37,14 @@ public final class ReadwriteSplittingDataSourceRule {
     
     private final TransactionalReadQueryStrategy 
transactionalReadQueryStrategy;
     
-    private final ReadQueryLoadBalanceAlgorithm loadBalancer;
+    private final LoadBalanceAlgorithm loadBalancer;
     
     private final ReadwriteSplittingGroup readwriteSplittingGroup;
     
     private final Collection<String> disabledDataSourceNames = new HashSet<>();
     
     public ReadwriteSplittingDataSourceRule(final 
ReadwriteSplittingDataSourceRuleConfiguration config, final 
TransactionalReadQueryStrategy transactionalReadQueryStrategy,
-                                            final 
ReadQueryLoadBalanceAlgorithm loadBalancer) {
+                                            final LoadBalanceAlgorithm 
loadBalancer) {
         name = config.getName();
         this.transactionalReadQueryStrategy = transactionalReadQueryStrategy;
         this.loadBalancer = loadBalancer;
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
index 75d8d0d820f..7981e800294 100644
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
+++ 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.readwritesplitting.rule;
 import com.google.common.base.Preconditions;
 import lombok.Getter;
 import 
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.core.LoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory;
 import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -40,7 +41,6 @@ import 
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleCo
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.exception.rule.InvalidInlineExpressionDataSourceNameException;
 import 
org.apache.shardingsphere.readwritesplitting.group.type.StaticReadwriteSplittingGroup;
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
 
 import java.util.Collection;
 import java.util.HashMap;
@@ -61,7 +61,7 @@ public final class ReadwriteSplittingRule implements 
DatabaseRule, DataSourceCon
     @Getter
     private final ReadwriteSplittingRuleConfiguration configuration;
     
-    private final Map<String, ReadQueryLoadBalanceAlgorithm> loadBalancers;
+    private final Map<String, LoadBalanceAlgorithm> loadBalancers;
     
     @Getter
     private final Map<String, ReadwriteSplittingDataSourceRule> 
dataSourceRules;
@@ -76,12 +76,12 @@ public final class ReadwriteSplittingRule implements 
DatabaseRule, DataSourceCon
         dataSourceRules = createDataSourceRules(ruleConfig);
     }
     
-    private Map<String, ReadQueryLoadBalanceAlgorithm> 
createLoadBalancers(final ReadwriteSplittingRuleConfiguration ruleConfig) {
-        Map<String, ReadQueryLoadBalanceAlgorithm> result = new 
LinkedHashMap<>(ruleConfig.getDataSources().size(), 1F);
+    private Map<String, LoadBalanceAlgorithm> createLoadBalancers(final 
ReadwriteSplittingRuleConfiguration ruleConfig) {
+        Map<String, LoadBalanceAlgorithm> result = new 
LinkedHashMap<>(ruleConfig.getDataSources().size(), 1F);
         for (ReadwriteSplittingDataSourceRuleConfiguration each : 
ruleConfig.getDataSources()) {
             if 
(ruleConfig.getLoadBalancers().containsKey(each.getLoadBalancerName())) {
                 AlgorithmConfiguration algorithmConfig = 
ruleConfig.getLoadBalancers().get(each.getLoadBalancerName());
-                result.put(each.getName() + "." + each.getLoadBalancerName(), 
TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, 
algorithmConfig.getType(), algorithmConfig.getProps()));
+                result.put(each.getName() + "." + each.getLoadBalancerName(), 
TypedSPILoader.getService(LoadBalanceAlgorithm.class, 
algorithmConfig.getType(), algorithmConfig.getProps()));
             }
         }
         return result;
@@ -96,13 +96,13 @@ public final class ReadwriteSplittingRule implements 
DatabaseRule, DataSourceCon
     }
     
     private Map<String, ReadwriteSplittingDataSourceRule> 
createDataSourceRules(final ReadwriteSplittingDataSourceRuleConfiguration 
config) {
-        ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = 
loadBalancers.getOrDefault(
-                config.getName() + "." + config.getLoadBalancerName(), 
TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, null));
+        LoadBalanceAlgorithm loadBalanceAlgorithm = loadBalancers.getOrDefault(
+                config.getName() + "." + config.getLoadBalancerName(), 
TypedSPILoader.getService(LoadBalanceAlgorithm.class, null));
         return createStaticDataSourceRules(config, loadBalanceAlgorithm);
     }
     
     private Map<String, ReadwriteSplittingDataSourceRule> 
createStaticDataSourceRules(final ReadwriteSplittingDataSourceRuleConfiguration 
config,
-                                                                               
       final ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm) {
+                                                                               
       final LoadBalanceAlgorithm loadBalanceAlgorithm) {
         List<String> inlineReadwriteDataSourceNames = 
InlineExpressionParserFactory.newInstance(config.getName()).splitAndEvaluate();
         List<String> inlineWriteDatasourceNames = 
InlineExpressionParserFactory.newInstance(config.getWriteDataSourceName()).splitAndEvaluate();
         List<List<String>> inlineReadDatasourceNames = 
config.getReadDataSourceNames().stream()
diff --git 
a/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm
 
b/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm
deleted file mode 100644
index 7dcea8c82eb..00000000000
--- 
a/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# 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.
-#
-
-org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.RoundRobinReadQueryLoadBalanceAlgorithm
-org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.RandomReadQueryLoadBalanceAlgorithm
-org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.WeightReadQueryLoadBalanceAlgorithm
diff --git 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RandomReadQueryLoadBalanceAlgorithmTest.java
 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RandomReadQueryLoadBalanceAlgorithmTest.java
deleted file mode 100644
index 4472b136a27..00000000000
--- 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RandomReadQueryLoadBalanceAlgorithmTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.readwritesplitting.algorithm.loadbalance;
-
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class RandomReadQueryLoadBalanceAlgorithmTest {
-    
-    @Test
-    void assertGetDataSourceWithDefaultStrategy() {
-        ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = 
TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, "RANDOM", new 
Properties());
-        String writeDataSourceName = "test_write_ds";
-        String readDataSourceName1 = "test_read_ds_1";
-        String readDataSourceName2 = "test_read_ds_2";
-        List<String> readDataSourceNames = Arrays.asList(readDataSourceName1, 
readDataSourceName2);
-        assertRandomReadQueryLoadBalance(readDataSourceNames, 
loadBalanceAlgorithm, writeDataSourceName);
-        
assertTrue(readDataSourceNames.contains(loadBalanceAlgorithm.getDataSource("ds",
 writeDataSourceName, readDataSourceNames)));
-        
assertTrue(readDataSourceNames.contains(loadBalanceAlgorithm.getDataSource("ds",
 writeDataSourceName, readDataSourceNames)));
-    }
-    
-    private void assertRandomReadQueryLoadBalance(final List<String> 
readDataSourceNames, final ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm, 
final String writeDataSourceName) {
-        
assertTrue(readDataSourceNames.contains(loadBalanceAlgorithm.getDataSource("ds",
 writeDataSourceName, readDataSourceNames)));
-        
assertTrue(readDataSourceNames.contains(loadBalanceAlgorithm.getDataSource("ds",
 writeDataSourceName, readDataSourceNames)));
-        
assertTrue(readDataSourceNames.contains(loadBalanceAlgorithm.getDataSource("ds",
 writeDataSourceName, readDataSourceNames)));
-    }
-}
diff --git 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RoundRobinReadQueryLoadBalanceAlgorithmTest.java
 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RoundRobinReadQueryLoadBalanceAlgorithmTest.java
deleted file mode 100644
index b8b25656a14..00000000000
--- 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/RoundRobinReadQueryLoadBalanceAlgorithmTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.readwritesplitting.algorithm.loadbalance;
-
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-class RoundRobinReadQueryLoadBalanceAlgorithmTest {
-    
-    @Test
-    void assertGetDataSourceWithDefaultStrategy() {
-        ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = 
TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, "ROUND_ROBIN", 
new Properties());
-        String writeDataSourceName = "test_write_ds";
-        String readDataSourceName1 = "test_read_ds_1";
-        String readDataSourceName2 = "test_read_ds_2";
-        List<String> readDataSourceNames = Arrays.asList(readDataSourceName1, 
readDataSourceName2);
-        assertRoundRobinReadQueryLoadBalance(writeDataSourceName, 
readDataSourceName1, readDataSourceName2, loadBalanceAlgorithm, 
readDataSourceNames);
-    }
-    
-    private void assertRoundRobinReadQueryLoadBalance(final String 
writeDataSourceName, final String readDataSourceName1, final String 
readDataSourceName2,
-                                                      final 
ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm, final List<String> 
readDataSourceNames) {
-        assertThat(loadBalanceAlgorithm.getDataSource("ds", 
writeDataSourceName, readDataSourceNames), is(readDataSourceName1));
-        assertThat(loadBalanceAlgorithm.getDataSource("ds", 
writeDataSourceName, readDataSourceNames), is(readDataSourceName2));
-        assertThat(loadBalanceAlgorithm.getDataSource("ds", 
writeDataSourceName, readDataSourceNames), is(readDataSourceName1));
-        assertThat(loadBalanceAlgorithm.getDataSource("ds", 
writeDataSourceName, readDataSourceNames), is(readDataSourceName2));
-    }
-}
diff --git 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithmTest.java
 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithmTest.java
deleted file mode 100644
index a006e14bf9b..00000000000
--- 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithmTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.readwritesplitting.algorithm.loadbalance;
-
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-class WeightReadQueryLoadBalanceAlgorithmTest {
-    
-    @Test
-    void assertGetSingleReadDataSource() {
-        ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = 
TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class, "WEIGHT", 
PropertiesBuilder.build(new Property("test_read_ds_1", "5")));
-        assertThat(loadBalanceAlgorithm.getDataSource("ds", "test_write_ds", 
Collections.singletonList("test_read_ds_1")), is("test_read_ds_1"));
-    }
-    
-    @Test
-    void assertGetMultipleReadDataSources() {
-        ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = 
TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class,
-                "WEIGHT", PropertiesBuilder.build(new 
Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5")));
-        String writeDataSourceName = "test_write_ds";
-        String readDataSourceName1 = "test_read_ds_1";
-        String readDataSourceName2 = "test_read_ds_2";
-        List<String> readDataSourceNames = Arrays.asList(readDataSourceName1, 
readDataSourceName2);
-        assertWeightReadQueryLoadBalance(loadBalanceAlgorithm, 
writeDataSourceName, readDataSourceNames);
-    }
-    
-    private void assertWeightReadQueryLoadBalance(final 
ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm, final String 
writeDataSourceName, final List<String> readDataSourceNames) {
-        assertThat(loadBalanceAlgorithm.getDataSource("ds", 
writeDataSourceName, readDataSourceNames), notNullValue());
-        assertThat(loadBalanceAlgorithm.getDataSource("ds", 
writeDataSourceName, readDataSourceNames), notNullValue());
-        assertThat(loadBalanceAlgorithm.getDataSource("ds", 
writeDataSourceName, readDataSourceNames), notNullValue());
-    }
-    
-    @Test
-    void assertGetDataSourceWhenReadDataSourceChanged() {
-        ReadQueryLoadBalanceAlgorithm loadBalanceAlgorithm = 
TypedSPILoader.getService(ReadQueryLoadBalanceAlgorithm.class,
-                "WEIGHT", PropertiesBuilder.build(new 
Property("test_read_ds_1", "5"), new Property("test_read_ds_2", "5")));
-        loadBalanceAlgorithm.getDataSource("ds", "test_write_ds", 
Arrays.asList("test_read_ds_1", "test_read_ds_1"));
-        assertThat(loadBalanceAlgorithm.getDataSource("ds", "test_write_ds", 
Collections.singletonList("test_read_ds_1")), is("test_read_ds_1"));
-    }
-}
diff --git 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/qualified/type/QualifiedReadwriteSplittingTransactionalDataSourceRouterTest.java
 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/qualified/type/QualifiedReadwriteSplittingTransactionalDataSourceRouterTest.java
index 29d059ed68b..2080f3c17ae 100644
--- 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/qualified/type/QualifiedReadwriteSplittingTransactionalDataSourceRouterTest.java
+++ 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/qualified/type/QualifiedReadwriteSplittingTransactionalDataSourceRouterTest.java
@@ -17,10 +17,10 @@
 
 package org.apache.shardingsphere.readwritesplitting.route.qualified.type;
 
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.round.robin.RoundRobinLoadBalanceAlgorithm;
 import org.apache.shardingsphere.infra.hint.HintValueContext;
 import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
 import 
org.apache.shardingsphere.infra.session.connection.transaction.TransactionConnectionContext;
-import 
org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.RoundRobinReadQueryLoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
 import 
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceRule;
@@ -62,9 +62,9 @@ class 
QualifiedReadwriteSplittingTransactionalDataSourceRouterTest {
         ReadwriteSplittingDataSourceRule rule;
         rule = new 
ReadwriteSplittingDataSourceRule(readwriteSplittingDataSourceRuleConfig, 
TransactionalReadQueryStrategy.PRIMARY, null);
         assertThat(new 
QualifiedReadwriteSplittingTransactionalDataSourceRouter(new 
ConnectionContext()).route(rule), is("write_ds"));
-        rule = new 
ReadwriteSplittingDataSourceRule(readwriteSplittingDataSourceRuleConfig, 
TransactionalReadQueryStrategy.FIXED, new 
RoundRobinReadQueryLoadBalanceAlgorithm());
+        rule = new 
ReadwriteSplittingDataSourceRule(readwriteSplittingDataSourceRuleConfig, 
TransactionalReadQueryStrategy.FIXED, new RoundRobinLoadBalanceAlgorithm());
         assertThat(new 
QualifiedReadwriteSplittingTransactionalDataSourceRouter(new 
ConnectionContext()).route(rule), is("read_ds_0"));
-        rule = new 
ReadwriteSplittingDataSourceRule(readwriteSplittingDataSourceRuleConfig, 
TransactionalReadQueryStrategy.DYNAMIC, new 
RoundRobinReadQueryLoadBalanceAlgorithm());
+        rule = new 
ReadwriteSplittingDataSourceRule(readwriteSplittingDataSourceRuleConfig, 
TransactionalReadQueryStrategy.DYNAMIC, new RoundRobinLoadBalanceAlgorithm());
         assertThat(new 
QualifiedReadwriteSplittingTransactionalDataSourceRouter(new 
ConnectionContext()).route(rule), is("read_ds_0"));
     }
 }
diff --git 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/standard/StandardReadwriteSplittingDataSourceRouterTest.java
 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/standard/StandardReadwriteSplittingDataSourceRouterTest.java
index 51c9756bcd1..2f1ed26af96 100644
--- 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/standard/StandardReadwriteSplittingDataSourceRouterTest.java
+++ 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/standard/StandardReadwriteSplittingDataSourceRouterTest.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.readwritesplitting.route.standard;
 
-import 
org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.RoundRobinReadQueryLoadBalanceAlgorithm;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.round.robin.RoundRobinLoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
 import 
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceRule;
@@ -37,7 +37,7 @@ class StandardReadwriteSplittingDataSourceRouterTest {
     void setUp() {
         rule = new ReadwriteSplittingDataSourceRule(
                 new 
ReadwriteSplittingDataSourceRuleConfiguration("test_config", "write_ds", 
Arrays.asList("read_ds_0", "read_ds_1"), null),
-                TransactionalReadQueryStrategy.DYNAMIC, new 
RoundRobinReadQueryLoadBalanceAlgorithm());
+                TransactionalReadQueryStrategy.DYNAMIC, new 
RoundRobinLoadBalanceAlgorithm());
     }
     
     @Test
diff --git 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/standard/filter/DisabledReadDataSourcesFilterTest.java
 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/standard/filter/DisabledReadDataSourcesFilterTest.java
index 96e487d8e75..4acf5b3df5e 100644
--- 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/standard/filter/DisabledReadDataSourcesFilterTest.java
+++ 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/standard/filter/DisabledReadDataSourcesFilterTest.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.readwritesplitting.route.standard.filter;
 
-import 
org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.RandomReadQueryLoadBalanceAlgorithm;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.random.RandomLoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
 import 
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceRule;
@@ -38,7 +38,7 @@ class DisabledReadDataSourcesFilterTest {
     void setUp() {
         rule = new ReadwriteSplittingDataSourceRule(
                 new ReadwriteSplittingDataSourceRuleConfiguration("test_pr", 
"write_ds", Arrays.asList("read_ds_0", "read_ds_1"), null),
-                TransactionalReadQueryStrategy.DYNAMIC, new 
RandomReadQueryLoadBalanceAlgorithm());
+                TransactionalReadQueryStrategy.DYNAMIC, new 
RandomLoadBalanceAlgorithm());
     }
     
     @Test
diff --git 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRuleTest.java
 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRuleTest.java
index b3fc9704656..526c342ae38 100644
--- 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRuleTest.java
+++ 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceRuleTest.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.readwritesplitting.rule;
 
-import 
org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance.RandomReadQueryLoadBalanceAlgorithm;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.random.RandomLoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
 import org.junit.jupiter.api.Test;
@@ -34,7 +34,7 @@ class ReadwriteSplittingDataSourceRuleTest {
         ReadwriteSplittingDataSourceRule readwriteSplittingDataSourceRule = 
new ReadwriteSplittingDataSourceRule(
                 new ReadwriteSplittingDataSourceRuleConfiguration("test_pr", 
"write_ds", Arrays.asList("read_ds_0", "read_ds_1"),
                         TransactionalReadQueryStrategy.DYNAMIC, null),
-                TransactionalReadQueryStrategy.DYNAMIC, new 
RandomReadQueryLoadBalanceAlgorithm());
+                TransactionalReadQueryStrategy.DYNAMIC, new 
RandomLoadBalanceAlgorithm());
         String writeDataSourceName = 
readwriteSplittingDataSourceRule.getWriteDataSource();
         assertThat(writeDataSourceName, is("write_ds"));
     }
diff --git 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
index 0eb3b17fc0f..fbf37d51b3e 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
@@ -24,16 +24,16 @@ import 
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleExc
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
 import 
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
 import 
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.core.LoadBalanceAlgorithm;
+import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
 import 
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
-import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.segment.ReadwriteSplittingRuleSegment;
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -209,6 +209,6 @@ public final class ReadwriteSplittingRuleStatementChecker {
     
     private static void checkLoadBalancers(final 
Collection<ReadwriteSplittingRuleSegment> segments) {
         
segments.stream().map(ReadwriteSplittingRuleSegment::getLoadBalancer).filter(Objects::nonNull)
-                .forEach(each -> 
TypedSPILoader.checkService(ReadQueryLoadBalanceAlgorithm.class, 
each.getName(), each.getProps()));
+                .forEach(each -> 
TypedSPILoader.checkService(LoadBalanceAlgorithm.class, each.getName(), 
each.getProps()));
     }
 }
diff --git 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadQueryLoadBalanceAlgorithmTypeAndClassMapper.java
 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadQueryLoadBalanceAlgorithmTypeAndClassMapper.java
index 227de047a02..44a1389ec7b 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadQueryLoadBalanceAlgorithmTypeAndClassMapper.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadQueryLoadBalanceAlgorithmTypeAndClassMapper.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
 
 import 
org.apache.shardingsphere.distsql.handler.executor.ral.plugin.PluginTypeAndClassMapper;
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.core.LoadBalanceAlgorithm;
 
 /**
  * Read query load balance algorithm type and class mapper.
@@ -26,8 +26,8 @@ import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgo
 public final class ReadQueryLoadBalanceAlgorithmTypeAndClassMapper implements 
PluginTypeAndClassMapper {
     
     @Override
-    public Class<ReadQueryLoadBalanceAlgorithm> getPluginClass() {
-        return ReadQueryLoadBalanceAlgorithm.class;
+    public Class<LoadBalanceAlgorithm> getPluginClass() {
+        return LoadBalanceAlgorithm.class;
     }
     
     @Override
diff --git 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/fixture/DistSQLReadQueryLoadBalanceAlgorithmFixture.java
 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/fixture/DistSQLReadQueryLoadBalanceAlgorithmFixture.java
index 5d18ba65026..a02cecffe0d 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/fixture/DistSQLReadQueryLoadBalanceAlgorithmFixture.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/fixture/DistSQLReadQueryLoadBalanceAlgorithmFixture.java
@@ -17,15 +17,15 @@
 
 package org.apache.shardingsphere.readwritesplitting.distsql.handler.fixture;
 
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.core.LoadBalanceAlgorithm;
 
 import java.util.List;
 
-public final class DistSQLReadQueryLoadBalanceAlgorithmFixture implements 
ReadQueryLoadBalanceAlgorithm {
+public final class DistSQLReadQueryLoadBalanceAlgorithmFixture implements 
LoadBalanceAlgorithm {
     
     @Override
-    public String getDataSource(final String name, final String 
writeDataSourceName, final List<String> readDataSourceNames) {
-        return readDataSourceNames.get(0);
+    public String getAvailableTargetName(final String groupName, final 
List<String> availableTargetNames) {
+        return availableTargetNames.get(0);
     }
     
     @Override
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java
index 2bf21760966..4a876638384 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ReadwriteSplittingRuleConfigurationImportChecker.java
@@ -18,12 +18,12 @@
 package 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.checker;
 
 import 
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.infra.algorithm.load.balancer.core.LoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
+import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
-import 
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
 
 import java.util.Collection;
 import java.util.LinkedHashSet;
@@ -63,6 +63,6 @@ public final class 
ReadwriteSplittingRuleConfigurationImportChecker {
     }
     
     private void checkLoadBalancers(final ReadwriteSplittingRuleConfiguration 
currentRuleConfig) {
-        currentRuleConfig.getLoadBalancers().values().forEach(each -> 
TypedSPILoader.checkService(ReadQueryLoadBalanceAlgorithm.class, 
each.getType(), each.getProps()));
+        currentRuleConfig.getLoadBalancers().values().forEach(each -> 
TypedSPILoader.checkService(LoadBalanceAlgorithm.class, each.getType(), 
each.getProps()));
     }
 }

Reply via email to