From d96777ca700a1ad08500e0212e9fcf5d30c99e1e Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Thu, 17 Jan 2013 16:26:02 -0800 Subject: [PATCH] Work around failed metadata lookups with Rackspace 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. This commit is similar to commit 3c7b965 to hpcloud-objectstorage. --- .../functions/PublicUriForObjectInfo.java | 22 ++++++++++++++----- .../functions/PublicUriForObjectInfo.java | 7 ++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/PublicUriForObjectInfo.java b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/PublicUriForObjectInfo.java index d3121b25a2..7cfd44e8a5 100644 --- a/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/PublicUriForObjectInfo.java +++ b/apis/cloudfiles/src/main/java/org/jclouds/cloudfiles/blobstore/functions/PublicUriForObjectInfo.java @@ -44,16 +44,28 @@ public class PublicUriForObjectInfo implements Function { this.cdnContainer = cdnContainer; } + 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 uriBuilder(cdnContainer.getUnchecked(from.getContainer())) - .clearQuery().appendPath(from.getName()).build(); - } catch (NullPointerException e) { - // nulls not permitted from cache loader + String containerName = from.getContainer(); + if (containerName == null) return null; + try { + URI uri = cdnContainer.getUnchecked(containerName); + 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 uriBuilder(uri).clearQuery().appendPath(from.getName()).build(); } catch (CacheLoader.InvalidCacheLoadException e) { + // nulls not permitted from cache loader + cdnContainer.put(containerName, NEGATIVE_ENTRY); + return null; + } catch (NullPointerException e) { // nulls not permitted from cache loader return null; } 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 05f9d92f4e..f089dbe048 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 @@ -48,8 +48,11 @@ public class PublicUriForObjectInfo implements Function { public URI apply(ObjectInfo from) { if (from == null) return null; + String containerName = from.getContainer(); + if (containerName == null) + return null; try { - URI uri = cdnContainer.getUnchecked(from.getContainer()); + URI uri = cdnContainer.getUnchecked(containerName); 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. @@ -59,7 +62,7 @@ public class PublicUriForObjectInfo implements Function { return uriBuilder(uri).clearQuery().appendPath(from.getName()).build(); } catch (CacheLoader.InvalidCacheLoadException e) { // nulls not permitted from cache loader - cdnContainer.put(from.getContainer(), NEGATIVE_ENTRY); + cdnContainer.put(containerName, NEGATIVE_ENTRY); return null; } catch (NullPointerException e) { // nulls not permitted from cache loader