Skip to content

Commit

Permalink
fix:修复就近路由以及匀速限流排队问题 (#299)
Browse files Browse the repository at this point in the history
* refactor:not switch on fail when only one address

* refactor:not switch on fail when only one address

* fix:修复就近路由以及匀速限流排队问题

* fix:修复就近路由以及匀速限流排队问题
  • Loading branch information
chuntaojun authored Feb 28, 2023
1 parent 98dd621 commit ba1025e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.tencent.polaris.client.pb.RateLimitProto.Rule;
import com.tencent.polaris.logging.LoggerFactory;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;

/**
Expand All @@ -56,6 +58,9 @@ public RemoteAwareLeakyBucket(InitCriteria initCriteria, Configuration configura
boolean effective = false;
double effectiveRate = 0.0F;
leakyBucket.setMaxQueuingDuration(configuration.getProvider().getRateLimit().getMaxQueuingTime());
if (rule.getMaxQueueDelay().getValue() > 0) {
leakyBucket.setMaxQueuingDuration(TimeUnit.SECONDS.toMillis(rule.getMaxQueueDelay().getValue()));
}
long maxDuration = 0;
for (Amount amount : rule.getAmountsList()) {
int maxAmount = amount.getMaxAmount().getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
package com.tencent.polaris.plugins.router.nearby;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -68,6 +70,7 @@ public class NearbyRouter extends AbstractServiceRouter implements PluginConfigP
public static final String ROUTER_METADATA_KEY_ZONE = "zone";
public static final String ROUTER_METADATA_KEY_REGION = "region";
public static final String ROUTER_METADATA_KEY_CAMPUS = "campus";
private static final String NEARBY_METADATA_ENABLE = "internal-enable-nearby";


private static final Logger LOG = LoggerFactory.getLogger(NearbyRouter.class);
Expand Down Expand Up @@ -349,6 +352,10 @@ public boolean enable(RouteInfo routeInfo, ServiceMetadata dstSvcInfo) {
if (MapUtils.isEmpty(clientLocationInfo)) {
return false;
}
Map<String, String> destSvcMetadata = Optional.ofNullable(dstSvcInfo.getMetadata()).orElse(Collections.emptyMap());
if (Boolean.parseBoolean(destSvcMetadata.get(NEARBY_METADATA_ENABLE))) {
return true;
}
//默认关闭,需要显示打开
Map<String, String> routerMetadata = routeInfo.getRouterMetadata(ROUTER_TYPE_NEAR_BY);
if (MapUtils.isNotEmpty(routerMetadata)) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<properties>
<!-- Project revision -->
<revision>1.9.4</revision>
<revision>1.9.5</revision>

<timestamp>${maven.build.timestamp}</timestamp>
<skip.maven.deploy>false</skip.maven.deploy>
Expand Down

0 comments on commit ba1025e

Please sign in to comment.