Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#4427]able to disable both consumer and provider zone-aware #4430

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
public class ZoneAwareDiscoveryFilter implements ServerListFilterExt {
public static final String CONFIG_RATIO = "servicecomb.loadbalance.filter.zoneaware.ratio";

public static final String CONFIG_RATIO_CEILING = "servicecomb.loadbalance.filter.zoneaware.ratioCeiling";

@Override
public int getOrder() {
return ORDER_ZONE_AWARE;
Expand All @@ -48,6 +50,11 @@ private int getRatio() {
.getIntProperty(CONFIG_RATIO, 30).get();
}

private int getRatioCeiling() {
return DynamicPropertyFactory.getInstance()
.getIntProperty(CONFIG_RATIO_CEILING, 70).get();
}

@Override
public List<ServiceCombServer> getFilteredListOfServers(List<ServiceCombServer> servers,
Invocation invocation) {
Expand All @@ -67,26 +74,28 @@ public List<ServiceCombServer> getFilteredListOfServers(List<ServiceCombServer>
});

int ratio = getRatio();
int ratioCeiling = getRatioCeiling();

if (hasEnoughMembers(servers.size(), instancesRegionAndAZMatch.size(), ratio)) {
if (hasEnoughMembers(servers.size(), instancesRegionAndAZMatch.size(), ratio, ratioCeiling)) {
return instancesRegionAndAZMatch;
} else {
instancesAZMatch.addAll(instancesRegionAndAZMatch);
}

if (hasEnoughMembers(servers.size(), instancesAZMatch.size(), ratio)) {
if (hasEnoughMembers(servers.size(), instancesAZMatch.size(), ratio, ratioCeiling)) {
return instancesAZMatch;
} else {
instancesNoMatch.addAll(instancesAZMatch);
}
return instancesNoMatch;
}

private boolean hasEnoughMembers(int totalSize, int groupSize, int ratio) {
private boolean hasEnoughMembers(int totalSize, int groupSize, int ratio, int ratioCeiling) {
if (totalSize == 0 || groupSize == 0) {
return false;
}
return Math.floorDiv(groupSize * 100, totalSize) >= ratio;
int actual = Math.floorDiv(groupSize * 100, totalSize);
return actual >= ratio && actual <= ratioCeiling;
}

private boolean regionAndAZMatch(MicroserviceInstance myself, MicroserviceInstance target) {
Expand Down
Loading