Skip to content

Commit

Permalink
Optimize props check for weight load balancer (#34140)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaigorJiang authored Dec 24, 2024
1 parent fc69347 commit 91d84ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ private static void checkProperties(final ReadwriteSplittingRuleSegment each) {
}

private static void checkDataSource(final ReadwriteSplittingRuleSegment ruleSegment) {
for (Object each : ruleSegment.getLoadBalancer().getProps().keySet()) {
String dataSourceName = (String) each;
ShardingSpherePreconditions.checkState(ruleSegment.getReadDataSources().contains(dataSourceName) || ruleSegment.getWriteDataSource().equals(dataSourceName),
() -> new InvalidAlgorithmConfigurationException("Load balancer", ruleSegment.getLoadBalancer().getName()));
}
Collection<String> weightKeys = ruleSegment.getLoadBalancer().getProps().stringPropertyNames();
weightKeys.forEach(each -> ShardingSpherePreconditions.checkContains(ruleSegment.getReadDataSources(), each,
() -> new InvalidAlgorithmConfigurationException("Load balancer", ruleSegment.getLoadBalancer().getName(), String.format("Can not find read storge unit '%s'", each))));
ruleSegment.getReadDataSources().forEach(each -> ShardingSpherePreconditions.checkContains(weightKeys, each,
() -> new InvalidAlgorithmConfigurationException("Load balancer", ruleSegment.getLoadBalancer().getName(), String.format("Weight of '%s' is required", each))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ public InvalidAlgorithmConfigurationException(final String algorithmType, final
public InvalidAlgorithmConfigurationException(final String algorithmType) {
super(XOpenSQLState.CHECK_OPTION_VIOLATION, 4, "Invalid %s algorithm configuration.", algorithmType);
}

public InvalidAlgorithmConfigurationException(final String algorithmType, final String algorithm, final String message) {
super(XOpenSQLState.CHECK_OPTION_VIOLATION, 4, "Invalid %s algorithm configuration '%s'. %s.", algorithmType, algorithm, message);
}
}

0 comments on commit 91d84ad

Please sign in to comment.