From a3d421442a4de74a29e0b470a7f69789b0326815 Mon Sep 17 00:00:00 2001 From: Andrei Savu Date: Mon, 8 Oct 2012 16:26:40 +0300 Subject: [PATCH] Issue 973. Performance problems with Synaptic's Atmos service and writing new blobs --- .../java/org/jclouds/atmos/AtmosAsyncClient.java | 1 + .../handlers/AtmosClientErrorRetryHandler.java | 5 +++-- .../java/org/jclouds/atmos/util/AtmosUtils.java | 13 +++++++++++-- .../atmos/blobstore/integration/AtmosLiveTest.java | 2 ++ .../storage/SynapticStorageClientLiveTest.java | 3 +++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/AtmosAsyncClient.java b/apis/atmos/src/main/java/org/jclouds/atmos/AtmosAsyncClient.java index 06e64fc3ed..145b9f7fcf 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/AtmosAsyncClient.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/AtmosAsyncClient.java @@ -58,6 +58,7 @@ import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; + import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosClientErrorRetryHandler.java b/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosClientErrorRetryHandler.java index 6225524064..0eef327b1e 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosClientErrorRetryHandler.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/handlers/AtmosClientErrorRetryHandler.java @@ -37,6 +37,7 @@ import com.google.inject.Inject; /** * Handles Retryable responses with error codes in the 4xx range * + * @see Error codes section at * @author Adrian Cole */ public class AtmosClientErrorRetryHandler implements HttpRetryHandler { @@ -62,14 +63,14 @@ public class AtmosClientErrorRetryHandler implements HttpRetryHandler { if (response.getStatusCode() == 404 && command.getCurrentRequest().getMethod().equals("DELETE")) { command.incrementFailureCount(); return true; - } else if (response.getStatusCode() == 409 || response.getStatusCode() == 400) { + } else if (response.getStatusCode() == 409) { byte[] content = HttpUtils.closeClientButKeepContentStream(response); // Content can be null in the case of HEAD requests if (content != null) { try { AtmosError error = utils.parseAtmosErrorFromContent(command, response, new String(content)); - if (error.getCode() == 1016) { + if (error.getCode() == 1006) { return backoffHandler.shouldRetryRequest(command, response); } // don't increment count before here, since backoff handler does already diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/util/AtmosUtils.java b/apis/atmos/src/main/java/org/jclouds/atmos/util/AtmosUtils.java index af822753cf..91efe6bf44 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/util/AtmosUtils.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/util/AtmosUtils.java @@ -27,9 +27,11 @@ import javax.inject.Provider; import org.jclouds.atmos.AtmosClient; import org.jclouds.atmos.blobstore.functions.BlobToObject; import org.jclouds.atmos.domain.AtmosError; +import org.jclouds.atmos.domain.AtmosObject; import org.jclouds.atmos.filters.SignRequest; import org.jclouds.atmos.options.PutOptions; import org.jclouds.atmos.xml.ErrorHandler; +import org.jclouds.blobstore.KeyAlreadyExistsException; import org.jclouds.blobstore.domain.Blob; import org.jclouds.crypto.Crypto; import org.jclouds.http.HttpCommand; @@ -70,8 +72,15 @@ public class AtmosUtils { public static String putBlob(final AtmosClient sync, Crypto crypto, BlobToObject blob2Object, String container, Blob blob, PutOptions options) { final String path = container + "/" + blob.getMetadata().getName(); - deleteAndEnsureGone(sync, path); - sync.createFile(container, blob2Object.apply(blob), options); + final AtmosObject object = blob2Object.apply(blob); + + try { + sync.createFile(container, object, options); + + } catch(KeyAlreadyExistsException e) { + deleteAndEnsureGone(sync, path); + sync.createFile(container, object, options); + } return path; } diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosLiveTest.java index d826318341..8b862d7cb8 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosLiveTest.java @@ -32,6 +32,8 @@ public class AtmosLiveTest extends BaseBlobLiveTest { public AtmosLiveTest() { provider = "atmos"; } + + @Override protected void checkMD5(String container, String name, byte[] md5) { // atmos does not support content-md5 yet assertEquals(view.getBlobStore().blobMetadata(container, name).getContentMetadata().getContentMD5(), null); diff --git a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/SynapticStorageClientLiveTest.java b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/SynapticStorageClientLiveTest.java index dd9dfd7744..c8359f08de 100644 --- a/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/SynapticStorageClientLiveTest.java +++ b/providers/synaptic-storage/src/test/java/org/jclouds/synaptic/storage/SynapticStorageClientLiveTest.java @@ -29,4 +29,7 @@ import org.testng.annotations.Test; @Test(groups = "live", sequential = true, testName = "SynapticStorageClientLiveTest") public class SynapticStorageClientLiveTest extends AtmosClientLiveTest { + public SynapticStorageClientLiveTest() { + provider = "synaptic-storage"; + } }