fix weight lb bug (#704)

* fix weight lb bug

* add change log
pull/705/head
lepdou 3 years ago committed by GitHub
parent 03045c16c0
commit 57418849ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,3 +3,4 @@
- [fix router concurrent bug&fix spring-retry circuit breaker not work bug](https://github.com/Tencent/spring-cloud-tencent/pull/679) - [fix router concurrent bug&fix spring-retry circuit breaker not work bug](https://github.com/Tencent/spring-cloud-tencent/pull/679)
- [fix router unit test](https://github.com/Tencent/spring-cloud-tencent/pull/684) - [fix router unit test](https://github.com/Tencent/spring-cloud-tencent/pull/684)
- [fix weight load balancer bug](https://github.com/Tencent/spring-cloud-tencent/pull/704)

@ -122,7 +122,7 @@ public class PolarisLoadBalancerCompositeRule extends AbstractLoadBalancerRule {
} }
// set load balancer to delegate rule // set load balancer to delegate rule
if (!initializedLoadBalancerToDelegateRule.compareAndSet(false, true)) { if (initializedLoadBalancerToDelegateRule.compareAndSet(false, true)) {
delegateRule.setLoadBalancer(loadBalancer); delegateRule.setLoadBalancer(loadBalancer);
} }

@ -14,6 +14,12 @@ spring:
enabled: true enabled: true
loadbalancer: loadbalancer:
enabled: true enabled: true
loadbalancer:
retry:
retry-on-all-operations: true
max-retries-on-same-service-instance: 0
max-retries-on-next-service-instance: 3
# strategy: polarisWeighted
management: management:
endpoints: endpoints:
web: web:

@ -21,7 +21,10 @@ package com.tencent.cloud.polaris.loadbalancer;
import java.util.List; import java.util.List;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractLoadBalancerRule; import com.netflix.loadbalancer.AbstractServerPredicate;
import com.netflix.loadbalancer.AvailabilityPredicate;
import com.netflix.loadbalancer.CompositePredicate;
import com.netflix.loadbalancer.PredicateBasedRule;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
import com.tencent.cloud.common.pojo.PolarisServer; import com.tencent.cloud.common.pojo.PolarisServer;
import com.tencent.polaris.api.config.consumer.LoadBalanceConfig; import com.tencent.polaris.api.config.consumer.LoadBalanceConfig;
@ -38,9 +41,10 @@ import org.springframework.util.CollectionUtils;
* *
* @author lepdou 2022-05-17 * @author lepdou 2022-05-17
*/ */
public class PolarisWeightedRule extends AbstractLoadBalancerRule { public class PolarisWeightedRule extends PredicateBasedRule {
private final RouterAPI routerAPI; private final RouterAPI routerAPI;
private CompositePredicate compositePredicate;
public PolarisWeightedRule(RouterAPI routerAPI) { public PolarisWeightedRule(RouterAPI routerAPI) {
this.routerAPI = routerAPI; this.routerAPI = routerAPI;
@ -48,6 +52,13 @@ public class PolarisWeightedRule extends AbstractLoadBalancerRule {
@Override @Override
public void initWithNiwsConfig(IClientConfig clientConfig) { public void initWithNiwsConfig(IClientConfig clientConfig) {
AvailabilityPredicate availabilityPredicate = new AvailabilityPredicate(this, clientConfig);
compositePredicate = CompositePredicate.withPredicates(availabilityPredicate).build();
}
@Override
public AbstractServerPredicate getPredicate() {
return compositePredicate;
} }
@Override @Override
@ -57,6 +68,9 @@ public class PolarisWeightedRule extends AbstractLoadBalancerRule {
return null; return null;
} }
// filter circuit breaker servers by ribbon
servers = compositePredicate.getEligibleServers(servers);
ServiceInstances serviceInstances = LoadBalancerUtils.transferServersToServiceInstances(servers); ServiceInstances serviceInstances = LoadBalancerUtils.transferServersToServiceInstances(servers);
ProcessLoadBalanceRequest request = new ProcessLoadBalanceRequest(); ProcessLoadBalanceRequest request = new ProcessLoadBalanceRequest();

Loading…
Cancel
Save