You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by el...@apache.org on 2018/01/24 17:23:20 UTC
[incubator-trafficcontrol] 11/36: Clean up DDC code in TR a bit
This is an automated email from the ASF dual-hosted git repository.
elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git
commit 235f4c75500326854b7d5d76ec3b38b1647c66a9
Author: Rawlin Peters <ra...@comcast.com>
AuthorDate: Wed Oct 25 17:02:17 2017 -0600
Clean up DDC code in TR a bit
---
.../traffic_router/core/ds/DeliveryService.java | 5 +--
.../traffic_router/core/router/TrafficRouter.java | 45 ++++++++++------------
2 files changed, 21 insertions(+), 29 deletions(-)
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/ds/DeliveryService.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/ds/DeliveryService.java
index e124fb4..7adc191 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/ds/DeliveryService.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/ds/DeliveryService.java
@@ -93,7 +93,7 @@ public class DeliveryService {
private final boolean acceptHttp;
private final boolean acceptHttps;
private final boolean redirectToHttps;
- private int deepCache; // should this be final or should it be settable?
+ private final int deepCache;
// enums are hard in Java.
public static final int DC_NEVER = 0;
@@ -398,9 +398,6 @@ public class DeliveryService {
public int getDeepCache() {
return deepCache;
}
- public void setDeepCache(final int deepCache) {
- this.deepCache = deepCache;
- }
public boolean appendQueryString() {
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
index b1b2623..76c5627 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
@@ -249,33 +249,24 @@ public class TrafficRouter {
// DDC - Dynamic Deep Caching
// cacheLocation has a list of caches that we can hash this request to.
// Make this list different for content that should be cached deep.
- //boolean useDeepCZ = false;
- // first get the cachegroup, because the popularity is by cachegroup...
- // this is expensive, but i see no other option.
- final CacheLocation cacheGroup = getCoverageZoneCacheLocation(request.getClientIP(), ds, false);
- CacheLocation cacheLocation = null;
+ CacheLocation cacheLocation;
ResultType result = ResultType.CZ;
- if (cacheGroup != null) {
- // change true to a function that returns yes if the request.getPath is popular
- //boolean isPop = isPopular(request.getPath(), ds.getId(), cacheGroup.getId());
- if (ds.getDeepCache() == DeliveryService.DC_ALWAYS) {
- // Deep caching is enabled and wanted for the requested URL. See if there are deep caches available
- cacheLocation = getCoverageZoneCacheLocation(request.getClientIP(), ds, true);
- if (cacheLocation != null && cacheLocation.getCaches().size() != 0) {
- // Found deep caches for this client, and there are caches available there.
- // Use the cacheLocation, and set result to DEEP_CZ
- result = ResultType.DEEP_CZ;
- } else {
- // No deep caches for this client, would have used them if there were any...
- // set the cacheLocation to the cacheGroup found earlier.
- result = ResultType.DEEP_CZ_MISS;
- cacheLocation = cacheGroup;
- }
+
+ if (ds.getDeepCache() == DeliveryService.DC_ALWAYS) {
+ // Deep caching is enabled. See if there are deep caches available
+ cacheLocation = getDeepCoverageZoneCacheLocation(request.getClientIP(), ds);
+ if (cacheLocation != null && cacheLocation.getCaches().size() != 0) {
+ // Found deep caches for this client, and there are caches available there.
+ // Use the deep cacheLocation, and set result to DEEP_CZ
+ result = ResultType.DEEP_CZ;
} else {
- // Deep caching not enabled or not for this URL. Back to cachegroup.
- cacheLocation = cacheGroup;
+ // No deep caches for this client, would have used them if there were any...
+ result = ResultType.DEEP_CZ_MISS;
+ cacheLocation = getCoverageZoneCacheLocation(request.getClientIP(), ds);
}
-
+ } else {
+ // Deep caching not enabled for this Delivery Service; use the regular CZ
+ cacheLocation = getCoverageZoneCacheLocation(request.getClientIP(), ds);
}
List<Cache>caches = selectCachesByCZ(ds, cacheLocation, track, result);
@@ -467,7 +458,7 @@ public class TrafficRouter {
}
private List<Cache> selectCachesByCZ(final DeliveryService ds, final CacheLocation cacheLocation, final Track track) {
- return selectCachesByCZ(ds, cacheLocation, track, ResultType.CZ); // RestultType.CZ was the original default before DDC
+ return selectCachesByCZ(ds, cacheLocation, track, ResultType.CZ); // ResultType.CZ was the original default before DDC
}
private List<Cache> selectCachesByCZ(final DeliveryService ds, final CacheLocation cacheLocation, final Track track, final ResultType result) {
@@ -687,6 +678,10 @@ public class TrafficRouter {
return getClosestCacheLocation(cacheRegister.filterAvailableLocations(deliveryServiceId), networkNode.getGeolocation(), cacheRegister.getDeliveryService(deliveryServiceId));
}
+ public CacheLocation getDeepCoverageZoneCacheLocation(final String ip, final DeliveryService deliveryService) {
+ return getCoverageZoneCacheLocation(ip, deliveryService, true);
+ }
+
protected CacheLocation getCoverageZoneCacheLocation(final String ip, final DeliveryService deliveryService, final boolean useDeep) {
return getCoverageZoneCacheLocation(ip, deliveryService.getId(), useDeep);
}
--
To stop receiving notification emails like this one, please contact
elsloo@apache.org.