use of com.linkedin.util.degrader.Degrader in project rest.li by linkedin.
the class DegraderLoadBalancerStrategyV3 method getTrackerClient.
@Override
public TrackerClient getTrackerClient(Request request, RequestContext requestContext, long clusterGenerationId, int partitionId, Map<URI, TrackerClient> trackerClients, boolean shouldForceUpdate) {
debug(_log, "getTrackerClient with generation id ", clusterGenerationId, " partition id: ", partitionId, " on tracker clients: ", trackerClients);
if (trackerClients == null || trackerClients.size() == 0) {
warn(_log, "getTrackerClient called with null/empty trackerClients, so returning null");
return null;
}
List<DegraderTrackerClient> degraderTrackerClients = castToDegraderTrackerClients(trackerClients);
// only one thread will be allowed to enter updatePartitionState for any partition
TimingContextUtil.markTiming(requestContext, TIMING_KEY);
checkUpdatePartitionState(clusterGenerationId, partitionId, degraderTrackerClients, shouldForceUpdate);
TimingContextUtil.markTiming(requestContext, TIMING_KEY);
Ring<URI> ring = _state.getRing(partitionId);
URI targetHostUri = KeyMapper.TargetHostHints.getRequestContextTargetHost(requestContext);
Set<URI> excludedUris = ExcludedHostHints.getRequestContextExcludedHosts(requestContext);
if (excludedUris == null) {
excludedUris = new HashSet<>();
}
// no valid target host header was found in the request
DegraderTrackerClient client;
if (targetHostUri == null) {
client = findValidClientFromRing(request, ring, degraderTrackerClients, excludedUris, requestContext);
} else {
debug(_log, "Degrader honoring target host header in request, skipping hashing. URI: ", targetHostUri);
client = searchClientFromUri(targetHostUri, degraderTrackerClients);
if (client == null) {
warn(_log, "No client found for ", targetHostUri, ". Target host specified is no longer part of cluster");
} else {
// if this flag is set to be true, that means affinity routing is preferred but backup requests are still acceptable
Boolean otherHostAcceptable = KeyMapper.TargetHostHints.getRequestContextOtherHostAcceptable(requestContext);
if (otherHostAcceptable != null && otherHostAcceptable) {
ExcludedHostHints.addRequestContextExcludedHost(requestContext, targetHostUri);
}
}
}
if (client == null) {
return null;
}
// Decides whether to drop the call
Degrader degrader = client.getDegrader(partitionId);
if (degrader.checkDrop()) {
warn(_log, "client's degrader is dropping call for: ", client);
return null;
}
debug(_log, "returning client: ", client);
// Decides whether to degrade call at the transport layer
if (degrader.checkPreemptiveTimeout()) {
DegraderControl degraderControl = client.getDegraderControl(partitionId);
requestContext.putLocalAttr(R2Constants.PREEMPTIVE_TIMEOUT_RATE, degraderControl.getPreemptiveRequestTimeoutRate());
}
return client;
}
Aggregations