Skip to content

Commit

Permalink
Support prioritizing retries on other nodes before retrying the faile…
Browse files Browse the repository at this point in the history
…d node
  • Loading branch information
hexiaofeng committed May 28, 2024
1 parent 418e173 commit 072a4bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
@Extensible(value = "RouteFilter")
public interface RouteFilter {

int ORDER_RETRY = 100;

int ORDER_STICKY = ORDER_RETRY + 100;
int ORDER_STICKY = 100;

int ORDER_LOCALHOST = ORDER_STICKY + 100;

Expand All @@ -53,6 +51,8 @@ public interface RouteFilter {

int ORDER_LIVE_CELL = ORDER_LANE + 100;

int ORDER_RETRY = ORDER_LIVE_CELL + 100;

int ORDER_LOADBALANCE = ORDER_LIVE_CELL + 100;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
import com.jd.live.agent.core.extension.annotation.ConditionalOnProperty;
import com.jd.live.agent.core.extension.annotation.Extension;
import com.jd.live.agent.governance.config.GovernanceConfig;
import com.jd.live.agent.governance.instance.Endpoint;
import com.jd.live.agent.governance.invoke.OutboundInvocation;
import com.jd.live.agent.governance.invoke.RouteTarget;
import com.jd.live.agent.governance.invoke.filter.RouteFilter;
import com.jd.live.agent.governance.invoke.filter.RouteFilterChain;
import com.jd.live.agent.governance.policy.service.loadbalance.StickyType;
import com.jd.live.agent.governance.request.ServiceRequest.OutboundRequest;

import java.util.List;
import java.util.Set;

/**
Expand All @@ -39,14 +40,15 @@ public class RetryFilter implements RouteFilter {

@Override
public <T extends OutboundRequest> void filter(OutboundInvocation<T> invocation, RouteFilterChain chain) {
StickyType stickyType = invocation.getServiceMetadata().getStickyType();
if (stickyType != StickyType.FIXED) {
RouteTarget target = invocation.getRouteTarget();
// Get the set of attempted endpoint IDs from the request
Set<String> attempts = invocation.getRequest().getAttempts();
// If there have been previous attempts, filter out the endpoints that have already failed
if (attempts != null && !attempts.isEmpty()) {
target.filter(endpoint -> !attempts.contains(endpoint.getId()));
RouteTarget target = invocation.getRouteTarget();
// Get the set of attempted endpoint IDs from the request
Set<String> attempts = invocation.getRequest().getAttempts();
// If there have been previous attempts, filter out the endpoints that have already failed
if (attempts != null && !attempts.isEmpty()) {
List<? extends Endpoint> endpoints = RouteTarget.filter(target.getEndpoints(), endpoint -> !attempts.contains(endpoint.getId()), -1);
if (endpoints != null && !endpoints.isEmpty()) {
// Can retry on failed instances
target.setEndpoints(endpoints);
}
}
chain.filter(invocation);
Expand Down

0 comments on commit 072a4bc

Please sign in to comment.