From 3c7b9652f44d35d7c6adfae3a53d2b18d4b1e54f Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sat, 20 Oct 2012 14:16:09 -0700 Subject: [PATCH] Work around failed CDN metadata lookups with HPCS Previously BlobStore.list and thus BlobStore.clearContainer serialized on synchronous and failed CDN lookups. This effectively prevents clearing any large container. We cache a negative entry to work around this. When HP improves their CDN support we should remove this workaround. --- .../functions/PublicUriForObjectInfo.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/PublicUriForObjectInfo.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/PublicUriForObjectInfo.java index 3f8978af90..903b281bff 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/PublicUriForObjectInfo.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/blobstore/functions/PublicUriForObjectInfo.java @@ -18,7 +18,10 @@ */ package org.jclouds.hpcloud.objectstorage.blobstore.functions; +import static com.google.common.base.Throwables.propagate; + import java.net.URI; +import java.net.URISyntaxException; import javax.inject.Inject; import javax.inject.Provider; @@ -45,14 +48,24 @@ public class PublicUriForObjectInfo implements Function { this.uriBuilders = uriBuilders; } + private static final URI NEGATIVE_ENTRY = URI.create("http://127.0.0.1"); + public URI apply(ObjectInfo from) { if (from == null) return null; try { - return uriBuilders.get().uri(cdnContainer.getUnchecked(from.getContainer())).path(from.getName()).replaceQuery("") + URI uri = cdnContainer.getUnchecked(from.getContainer()); + if (uri == NEGATIVE_ENTRY) { // intentionally use reference equality + // TODO: GetCDNMetadata.load returns null on failure cases. We use + // a negative entry to avoid repeatedly issuing failed CDN queries. + // The LoadingCache removes this value after its normal expiry. + return null; + } + return uriBuilders.get().uri(uri).path(from.getName()).replaceQuery("") .build(); } catch (CacheLoader.InvalidCacheLoadException e) { // nulls not permitted from cache loader + cdnContainer.put(from.getContainer(), NEGATIVE_ENTRY); return null; } catch (NullPointerException e) { // nulls not permitted from cache loader