Skip to content

Commit

Permalink
[#4427]able to disable both consumer and provider zone-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 committed Jul 27, 2024
1 parent 86eedb1 commit 0b77183
Showing 1 changed file with 13 additions and 4 deletions.
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

0 comments on commit 0b77183

Please sign in to comment.