You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/08/10 15:10:07 UTC
(shardingsphere) branch master updated: Fix incomplete WEIGHT load balancer validation (#39378)
This is an automated email from the ASF dual-hosted git repository.
terrymanu 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 a3b3aee3bc6 Fix incomplete WEIGHT load balancer validation (#39378)
a3b3aee3bc6 is described below
commit a3b3aee3bc671cf85e0eb9501129aa664318d979
Author: Gimin Kim <13...@users.noreply.github.com>
AuthorDate: Tue Aug 11 00:10:00 2026 +0900
Fix incomplete WEIGHT load balancer validation (#39378)
* Fix incomplete weight load balancer validation
* Add release note for weight validation fix
---------
Co-authored-by: Gimin Kim <Gi...@users.noreply.github.com>
---
RELEASE-NOTES.md | 1 +
.../algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java | 2 ++
.../loadbalancer/weight/WeightLoadBalanceAlgorithmTest.java | 8 +++++++-
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index faf6230cb7e..e3d10f3adaa 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -14,6 +14,7 @@
1. Infra: Avoid retaining transient multi-object lookup keys in `OrderedSPILoader` - [#38980](https://github.com/apache/shardingsphere/pull/38980)
1. Infra: Fix invalid target selection after counter overflow in `RoundRobinLoadBalanceAlgorithm` - [#39340](https://github.com/apache/shardingsphere/pull/39340)
+1. Infra: Reject incomplete WEIGHT load balancer properties during rule configuration validation - [#39378](https://github.com/apache/shardingsphere/pull/39378)
1. SQL Parser: Preserve unary NOT as NotExpression for scalar-subquery table extraction in PostgreSQL - [#38187](https://github.com/apache/shardingsphere/pull/38187)
1. SQL Parser: Fix wrong parameter index parse in MySQL, Doris - [#38624](https://github.com/apache/shardingsphere/pull/38624)
1. SQL Parser: Fix No value specified for parameter exception when sql is 'INSERT INTO tableName ON CONFLICT DO UPDATE set WHERE ' - [#38668](https://github.com/apache/shardingsphere/pull/38668)
diff --git a/infra/algorithm/type/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java b/infra/algorithm/type/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java
index cd753629c9b..8cddb4d1c2b 100644
--- a/infra/algorithm/type/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java
+++ b/infra/algorithm/type/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java
@@ -62,6 +62,8 @@ public final class WeightLoadBalanceAlgorithm implements LoadBalanceAlgorithm {
public void check(final String databaseName, final Collection<String> configuredTargetNames) {
weightConfigMap.keySet().forEach(each -> ShardingSpherePreconditions.checkContains(configuredTargetNames, each,
() -> new AlgorithmInitializationException(this, "Target `%s` is required in database `%s`.", each, databaseName)));
+ configuredTargetNames.forEach(each -> ShardingSpherePreconditions.checkContains(weightConfigMap.keySet(), each,
+ () -> new AlgorithmInitializationException(this, "Weight of target `%s` is required in database `%s`.", each, databaseName)));
}
@HighFrequencyInvocation
diff --git a/infra/algorithm/type/load-balancer/type/weight/src/test/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithmTest.java b/infra/algorithm/type/load-balancer/type/weight/src/test/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithmTest.java
index 8bcb9caa5ae..94e6762196f 100644
--- a/infra/algorithm/type/load-balancer/type/weight/src/test/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithmTest.java
+++ b/infra/algorithm/type/load-balancer/type/weight/src/test/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithmTest.java
@@ -41,11 +41,17 @@ class WeightLoadBalanceAlgorithmTest {
}
@Test
- void assertCheck() {
+ void assertCheckWithUnconfiguredTarget() {
LoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(LoadBalanceAlgorithm.class, "WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5")));
assertThrows(AlgorithmInitializationException.class, () -> loadBalanceAlgorithm.check("foo_db", Collections.singletonList("test_read_ds_0")));
}
+ @Test
+ void assertCheckWithMissingWeight() {
+ LoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(LoadBalanceAlgorithm.class, "WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_0", "5")));
+ assertThrows(AlgorithmInitializationException.class, () -> loadBalanceAlgorithm.check("foo_db", Arrays.asList("test_read_ds_0", "test_read_ds_1")));
+ }
+
@Test
void assertGetSingleAvailableTarget() {
LoadBalanceAlgorithm loadBalanceAlgorithm = TypedSPILoader.getService(LoadBalanceAlgorithm.class, "WEIGHT", PropertiesBuilder.build(new Property("test_read_ds_1", "5")));