You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2015/06/08 07:34:38 UTC

[2/6] jclouds git commit: JCLOUDS-894: Add portable multipart upload for S3

JCLOUDS-894: Add portable multipart upload for S3


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/ae157991
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/ae157991
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/ae157991

Branch: refs/heads/master
Commit: ae157991baea78f385acdbae4a956c0bf3c01e8d
Parents: 794b385
Author: Andrew Gaul <ga...@apache.org>
Authored: Mon Jun 1 18:16:08 2015 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Sat Jun 6 16:32:16 2015 -0700

----------------------------------------------------------------------
 .../org/jclouds/s3/blobstore/S3BlobStore.java   |  14 +-
 .../config/S3BlobStoreContextModule.java        |   6 -
 .../strategy/AsyncMultipartUploadStrategy.java  |  31 --
 .../strategy/MultipartUploadStrategy.java       |  28 --
 .../ParallelMultipartUploadStrategy.java        | 292 -------------------
 .../SequentialMultipartUploadStrategy.java      | 123 --------
 ...quentialMultipartUploadStrategyMockTest.java | 147 ----------
 .../aws/s3/blobstore/AWSS3BlobStore.java        |  16 +-
 8 files changed, 11 insertions(+), 646 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/ae157991/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java
----------------------------------------------------------------------
diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java
index 2509655..e17e272 100644
--- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java
+++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobStore.java
@@ -51,6 +51,7 @@ import org.jclouds.domain.Location;
 import org.jclouds.http.options.GetOptions;
 import org.jclouds.io.ContentMetadata;
 import org.jclouds.io.Payload;
+import org.jclouds.io.PayloadSlicer;
 import org.jclouds.s3.S3Client;
 import org.jclouds.s3.blobstore.functions.BlobToObject;
 import org.jclouds.s3.blobstore.functions.BlobToObjectMetadata;
@@ -58,7 +59,6 @@ import org.jclouds.s3.blobstore.functions.BucketToResourceList;
 import org.jclouds.s3.blobstore.functions.ContainerToBucketListOptions;
 import org.jclouds.s3.blobstore.functions.ObjectToBlob;
 import org.jclouds.s3.blobstore.functions.ObjectToBlobMetadata;
-import org.jclouds.s3.blobstore.strategy.MultipartUploadStrategy;
 import org.jclouds.s3.domain.AccessControlList;
 import org.jclouds.s3.domain.AccessControlList.GroupGranteeURI;
 import org.jclouds.s3.domain.AccessControlList.Permission;
@@ -93,19 +93,17 @@ public class S3BlobStore extends BaseBlobStore {
    private final BlobToHttpGetOptions blob2ObjectGetOptions;
    private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider;
    private final LoadingCache<String, AccessControlList> bucketAcls;
-   protected final Provider<MultipartUploadStrategy> multipartUploadStrategy;
 
    @Inject
    protected S3BlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
-            @Memoized Supplier<Set<? extends Location>> locations, S3Client sync,
+            @Memoized Supplier<Set<? extends Location>> locations, PayloadSlicer slicer, S3Client sync,
             Function<Set<BucketMetadata>, PageSet<? extends StorageMetadata>> convertBucketsToStorageMetadata,
             ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList,
             ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
             BlobToObjectMetadata blob2ObjectMetadata,
             ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
-            LoadingCache<String, AccessControlList> bucketAcls,
-            Provider<MultipartUploadStrategy> multipartUploadStrategy) {
-      super(context, blobUtils, defaultLocation, locations);
+            LoadingCache<String, AccessControlList> bucketAcls) {
+      super(context, blobUtils, defaultLocation, locations, slicer);
       this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
       this.sync = checkNotNull(sync, "sync");
       this.convertBucketsToStorageMetadata = checkNotNull(convertBucketsToStorageMetadata, "convertBucketsToStorageMetadata");
@@ -117,7 +115,6 @@ public class S3BlobStore extends BaseBlobStore {
       this.blob2ObjectMetadata = checkNotNull(blob2ObjectMetadata, "blob2ObjectMetadata");
       this.fetchBlobMetadataProvider = checkNotNull(fetchBlobMetadataProvider, "fetchBlobMetadataProvider");
       this.bucketAcls = checkNotNull(bucketAcls, "bucketAcls");
-      this.multipartUploadStrategy = checkNotNull(multipartUploadStrategy, "multipartUploadStrategy");
    }
 
    /**
@@ -271,8 +268,7 @@ public class S3BlobStore extends BaseBlobStore {
    @Override
    public String putBlob(String container, Blob blob, PutOptions overrides) {
       if (overrides.isMultipart()) {
-         // need to use a provider if the strategy object is stateful
-         return multipartUploadStrategy.get().execute(container, blob);
+         return putMultipartBlob(container, blob, overrides);
       }
 
       // TODO: Make use of options overrides

http://git-wip-us.apache.org/repos/asf/jclouds/blob/ae157991/apis/s3/src/main/java/org/jclouds/s3/blobstore/config/S3BlobStoreContextModule.java
----------------------------------------------------------------------
diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/config/S3BlobStoreContextModule.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/config/S3BlobStoreContextModule.java
index 99a220b..f820308 100644
--- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/config/S3BlobStoreContextModule.java
+++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/config/S3BlobStoreContextModule.java
@@ -31,10 +31,6 @@ import org.jclouds.s3.blobstore.S3BlobRequestSigner;
 import org.jclouds.s3.blobstore.S3BlobStore;
 import org.jclouds.s3.blobstore.functions.LocationFromBucketName;
 import org.jclouds.s3.blobstore.internal.BackoffOnNotFoundWhenGetBucketACL;
-import org.jclouds.s3.blobstore.strategy.AsyncMultipartUploadStrategy;
-import org.jclouds.s3.blobstore.strategy.MultipartUploadStrategy;
-import org.jclouds.s3.blobstore.strategy.internal.ParallelMultipartUploadStrategy;
-import org.jclouds.s3.blobstore.strategy.internal.SequentialMultipartUploadStrategy;
 import org.jclouds.s3.domain.AccessControlList;
 
 import com.google.common.base.Function;
@@ -53,8 +49,6 @@ public class S3BlobStoreContextModule extends AbstractModule {
       bind(new TypeLiteral<Function<String, Location>>() {
       }).to(LocationFromBucketName.class);
       bindRequestSigner();
-      bind(MultipartUploadStrategy.class).to(SequentialMultipartUploadStrategy.class);
-      bind(AsyncMultipartUploadStrategy.class).to(ParallelMultipartUploadStrategy.class);
    }
 
    protected void bindRequestSigner() {

http://git-wip-us.apache.org/repos/asf/jclouds/blob/ae157991/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/AsyncMultipartUploadStrategy.java
----------------------------------------------------------------------
diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/AsyncMultipartUploadStrategy.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/AsyncMultipartUploadStrategy.java
deleted file mode 100644
index adbc842..0000000
--- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/AsyncMultipartUploadStrategy.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.s3.blobstore.strategy;
-
-import org.jclouds.blobstore.domain.Blob;
-import org.jclouds.blobstore.options.PutOptions;
-import org.jclouds.s3.blobstore.strategy.internal.ParallelMultipartUploadStrategy;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.inject.ImplementedBy;
-
-@ImplementedBy(ParallelMultipartUploadStrategy.class)
-public interface AsyncMultipartUploadStrategy {
-   
-   ListenableFuture<String> execute(String container, Blob blob, PutOptions options);
-
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/ae157991/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/MultipartUploadStrategy.java
----------------------------------------------------------------------
diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/MultipartUploadStrategy.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/MultipartUploadStrategy.java
deleted file mode 100644
index a6800ad..0000000
--- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/MultipartUploadStrategy.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.s3.blobstore.strategy;
-
-import org.jclouds.blobstore.domain.Blob;
-import org.jclouds.s3.blobstore.strategy.internal.SequentialMultipartUploadStrategy;
-
-import com.google.inject.ImplementedBy;
-
-@ImplementedBy(SequentialMultipartUploadStrategy.class)
-public interface MultipartUploadStrategy {
-   
-   String execute(String container, Blob blob);
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/ae157991/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/internal/ParallelMultipartUploadStrategy.java
----------------------------------------------------------------------
diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/internal/ParallelMultipartUploadStrategy.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/internal/ParallelMultipartUploadStrategy.java
deleted file mode 100644
index 789fb19..0000000
--- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/internal/ParallelMultipartUploadStrategy.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.s3.blobstore.strategy.internal;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Map;
-import java.util.Queue;
-import java.util.SortedMap;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ConcurrentSkipListMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.annotation.Resource;
-import javax.inject.Named;
-
-import org.jclouds.Constants;
-import org.jclouds.s3.blobstore.strategy.AsyncMultipartUploadStrategy;
-import org.jclouds.blobstore.domain.Blob;
-import org.jclouds.blobstore.internal.BlobRuntimeException;
-import org.jclouds.blobstore.options.PutOptions;
-import org.jclouds.blobstore.reference.BlobStoreConstants;
-import org.jclouds.io.Payload;
-import org.jclouds.io.PayloadSlicer;
-import org.jclouds.logging.Logger;
-import org.jclouds.s3.S3Client;
-import org.jclouds.s3.blobstore.S3BlobStore;
-import org.jclouds.s3.domain.ObjectMetadataBuilder;
-import org.jclouds.util.Throwables2;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.Maps;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.inject.Inject;
-
-public class ParallelMultipartUploadStrategy implements AsyncMultipartUploadStrategy {
-   @Resource
-   @Named(BlobStoreConstants.BLOBSTORE_LOGGER)
-   protected Logger logger = Logger.NULL;
-
-   @VisibleForTesting
-   static final int DEFAULT_PARALLEL_DEGREE = 4;
-   @VisibleForTesting
-   static final int DEFAULT_MIN_RETRIES = 5;
-   @VisibleForTesting
-   static final int DEFAULT_MAX_PERCENT_RETRIES = 10;
-
-   private final ListeningExecutorService executor;
-
-   @Inject(optional = true)
-   @Named("jclouds.mpu.parallel.degree")
-   @VisibleForTesting
-   int parallelDegree = DEFAULT_PARALLEL_DEGREE;
-
-   @Inject(optional = true)
-   @Named("jclouds.mpu.parallel.retries.min")
-   @VisibleForTesting
-   int minRetries = DEFAULT_MIN_RETRIES;
-
-   @Inject(optional = true)
-   @Named("jclouds.mpu.parallel.retries.maxpercent")
-   @VisibleForTesting
-   int maxPercentRetries = DEFAULT_MAX_PERCENT_RETRIES;
-
-   /**
-    * maximum duration of an blob Request
-    */
-   @Inject(optional = true)
-   @Named(Constants.PROPERTY_REQUEST_TIMEOUT)
-   protected Long maxTime;
-
-   protected final S3BlobStore blobstore;
-   protected final PayloadSlicer slicer;
-
-   @Inject
-   public ParallelMultipartUploadStrategy(S3BlobStore blobstore, PayloadSlicer slicer,
-         @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService executor) {
-      this.blobstore = checkNotNull(blobstore, "blobstore");
-      this.slicer = checkNotNull(slicer, "slicer");
-      this.executor = checkNotNull(executor, "executor");
-   }
-
-   protected void prepareUploadPart(final String container, final String key,
-         final String uploadId, final Integer part, final Payload payload,
-         final long offset, final long size, final SortedMap<Integer, String> etags,
-         final BlockingQueue<Integer> activeParts,
-         final Map<Integer, ListenableFuture<String>> futureParts,
-         final AtomicInteger errors, final int maxRetries, final Map<Integer, Exception> errorMap,
-         final Queue<Part> toRetry, final CountDownLatch latch) {
-      if (errors.get() > maxRetries) {
-         activeParts.remove(part); // remove part from the bounded-queue without blocking
-         latch.countDown();
-         return;
-      }
-      final S3Client client = blobstore.getContext().unwrapApi(S3Client.class);
-      final Payload chunkedPart = slicer.slice(payload, offset, size);
-      logger.debug(String.format("async uploading part %s of %s to container %s with uploadId %s", part, key, container, uploadId));
-      final long start = System.currentTimeMillis();
-      final ListenableFuture<String> futureETag = executor.submit(new Callable<String>() {
-         @Override public String call() throws Exception {
-            return client.uploadPart(container, key, part, uploadId, chunkedPart);
-         }
-      });
-      futureETag.addListener(new Runnable() {
-         @Override
-         public void run() {
-            try {
-               etags.put(part, futureETag.get());
-               logger.debug(String.format("async uploaded part %s of %s to container %s in %sms with uploadId %s",
-                     part, key, container, System.currentTimeMillis() - start, uploadId));
-            } catch (CancellationException e) {
-               errorMap.put(part, e);
-               String message = String.format("%s while uploading part %s - [%s,%s] to container %s with uploadId: %s running since %dms",
-                     e.getMessage(), part, offset, size, container, uploadId, System.currentTimeMillis() - start);
-               logger.debug(message);
-            } catch (Exception e) {
-               errorMap.put(part, e);
-               String message = String.format("%s while uploading part %s - [%s,%s] to container %s with uploadId: %s running since %dms",
-                     e.getMessage(), part, offset, size, container, uploadId, System.currentTimeMillis() - start);
-               logger.error(message, e);
-               if (errors.incrementAndGet() <= maxRetries)
-                  toRetry.add(new Part(part, offset, size));
-            } finally {
-               activeParts.remove(part); // remove part from the bounded-queue without blocking
-               futureParts.remove(part);
-               latch.countDown();
-            }
-         }
-      }, executor);
-      futureParts.put(part, futureETag);
-   }
-
-   @Override
-   public ListenableFuture<String> execute(final String container, final Blob blob, final PutOptions options) {
-      return executor.submit(new Callable<String>() {
-               @Override
-               public String call() throws Exception {
-                  String key = blob.getMetadata().getName();
-                  Payload payload = blob.getPayload();
-                  MultipartUploadSlicingAlgorithm algorithm = new MultipartUploadSlicingAlgorithm();
-                  algorithm.calculateChunkSize(payload.getContentMetadata()
-                        .getContentLength());
-                  int parts = algorithm.getParts();
-                  long chunkSize = algorithm.getChunkSize();
-                  long remaining = algorithm.getRemaining();
-                  if (parts > 0) {
-                     final S3Client client = blobstore.getContext().unwrapApi(S3Client.class);
-                     String uploadId = null;
-                     final Map<Integer, ListenableFuture<String>> futureParts =
-                        new ConcurrentHashMap<Integer, ListenableFuture<String>>();
-                     final Map<Integer, Exception> errorMap = Maps.newHashMap();
-                     AtomicInteger errors = new AtomicInteger(0);
-                     int maxRetries = Math.max(minRetries, parts * maxPercentRetries / 100);
-                     int effectiveParts = remaining > 0 ? parts + 1 : parts;
-                     try {
-                        uploadId = client.initiateMultipartUpload(container,
-                                 ObjectMetadataBuilder.create().key(key).build()); // TODO md5
-                        logger.debug(String.format("initiated multipart upload of %s to container %s" +
-                              " with uploadId %s consisting from %s part (possible max. retries: %d)",
-                              key, container, uploadId, effectiveParts, maxRetries));
-                        // we need a bounded-blocking queue to control the amount of parallel jobs
-                        ArrayBlockingQueue<Integer> activeParts = new ArrayBlockingQueue<Integer>(parallelDegree);
-                        Queue<Part> toRetry = new ConcurrentLinkedQueue<Part>();
-                        SortedMap<Integer, String> etags = new ConcurrentSkipListMap<Integer, String>();
-                        CountDownLatch latch = new CountDownLatch(effectiveParts);
-                        int part;
-                        while ((part = algorithm.getNextPart()) <= parts) {
-                           Integer partKey = Integer.valueOf(part);
-                           activeParts.put(partKey);
-                           prepareUploadPart(container, key, uploadId, partKey, payload,
-                                 algorithm.getNextChunkOffset(), chunkSize, etags,
-                                 activeParts, futureParts, errors, maxRetries, errorMap, toRetry, latch);
-                        }
-                        if (remaining > 0) {
-                           Integer partKey = Integer.valueOf(part);
-                           activeParts.put(partKey);
-                           prepareUploadPart(container, key, uploadId, partKey, payload,
-                                 algorithm.getNextChunkOffset(), remaining, etags,
-                                 activeParts, futureParts, errors, maxRetries, errorMap, toRetry, latch);
-                        }
-                        latch.await();
-                        // handling retries
-                        while (errors.get() <= maxRetries && !toRetry.isEmpty()) {
-                           int atOnce = Math.min(Math.min(toRetry.size(), errors.get()), parallelDegree);
-                           CountDownLatch retryLatch = new CountDownLatch(atOnce);
-                           for (int i = 0; i < atOnce; i++) {
-                              Part failedPart = toRetry.poll();
-                              Integer partKey = Integer.valueOf(failedPart.getPart());
-                              activeParts.put(partKey);
-                              prepareUploadPart(container, key, uploadId, partKey, payload,
-                                    failedPart.getOffset(), failedPart.getSize(), etags,
-                                    activeParts, futureParts, errors, maxRetries, errorMap, toRetry, retryLatch);
-                           }
-                           retryLatch.await();
-                        }
-                        if (errors.get() > maxRetries) {
-                           throw new BlobRuntimeException(String.format(
-                                 "Too many failed parts: %s while multipart upload of %s to container %s with uploadId %s",
-                                 errors.get(), key, container, uploadId));
-                        }
-                        String eTag = client.completeMultipartUpload(container, key, uploadId, etags);
-                        logger.debug(String.format("multipart upload of %s to container %s with uploadId %s" +
-                            " successfully finished with %s retries", key, container, uploadId, errors.get()));
-                        return eTag;
-                     } catch (Exception ex) {
-                        RuntimeException rtex = Throwables2.getFirstThrowableOfType(ex, RuntimeException.class);
-                        if (rtex == null) {
-                           rtex = new RuntimeException(ex);
-                        }
-                        for (Map.Entry<Integer, ListenableFuture<String>> entry : futureParts.entrySet()) {
-                           entry.getValue().cancel(false);
-                        }
-                        if (uploadId != null) {
-                           client.abortMultipartUpload(container, key, uploadId);
-                        }
-                        throw rtex;
-                     }
-                  } else {
-                     // Issue 936: don't just call putBlob, as that will see options=multiPart and
-                     // recursively call this execute method again; instead mark as not multipart
-                     // because it can all fit in one go.
-                     final PutOptions nonMultipartOptions = PutOptions.Builder.multipart(false);
-                     ListenableFuture<String> futureETag = executor.submit(new Callable<String>() {
-                        @Override public String call() throws Exception {
-                           return blobstore.putBlob(container, blob, nonMultipartOptions);
-                        }
-                     });
-                     return maxTime != null ?
-                           futureETag.get(maxTime, TimeUnit.SECONDS) : futureETag.get();
-                  }
-               }
-            });
-   }
-
-   static class Part {
-      private int part;
-      private long offset;
-      private long size;
-
-      Part(int part, long offset, long size) {
-         this.part = part;
-         this.offset = offset;
-         this.size = size;
-      }
-
-      public int getPart() {
-         return part;
-      }
-
-      public void setPart(int part) {
-         this.part = part;
-      }
-
-      public long getOffset() {
-         return offset;
-      }
-
-      public void setOffset(long offset) {
-         this.offset = offset;
-      }
-
-      public long getSize() {
-         return size;
-      }
-
-      public void setSize(long size) {
-         this.size = size;
-      }
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/ae157991/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategy.java
----------------------------------------------------------------------
diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategy.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategy.java
deleted file mode 100644
index 0400341..0000000
--- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategy.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.s3.blobstore.strategy.internal;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.SortedMap;
-
-import javax.annotation.Resource;
-import javax.inject.Named;
-
-import org.jclouds.s3.blobstore.strategy.MultipartUploadStrategy;
-import org.jclouds.blobstore.KeyNotFoundException;
-import org.jclouds.blobstore.domain.Blob;
-import org.jclouds.blobstore.reference.BlobStoreConstants;
-import org.jclouds.io.ContentMetadata;
-import org.jclouds.io.Payload;
-import org.jclouds.io.PayloadSlicer;
-import org.jclouds.logging.Logger;
-import org.jclouds.s3.S3Client;
-import org.jclouds.s3.blobstore.functions.BlobToObject;
-import org.jclouds.s3.domain.ObjectMetadataBuilder;
-
-import com.google.common.collect.Maps;
-import com.google.inject.Inject;
-
-/**
- * Provides a sequential multipart upload strategy.
- * 
- * The file partitioning algorithm:
- * 
- * The default partition size we choose is 32mb. A multiple of this default
- * partition size is used. The number of partCount first grows to a chosen magnitude
- * (for example 100 partCount), then it grows the partition size instead of number
- * of partitions. When we reached the maximum part size, then again it starts to
- * grow the number of partitions.
- */
-public class SequentialMultipartUploadStrategy implements MultipartUploadStrategy {
-   @Resource
-   @Named(BlobStoreConstants.BLOBSTORE_LOGGER)
-   private Logger logger = Logger.NULL;
-
-   private final S3Client client;
-   private final BlobToObject blobToObject;
-   private final MultipartUploadSlicingAlgorithm algorithm;
-   private final PayloadSlicer slicer;
-
-   @Inject
-   public SequentialMultipartUploadStrategy(S3Client client, BlobToObject blobToObject,
-         MultipartUploadSlicingAlgorithm algorithm, PayloadSlicer slicer) {
-      this.client = checkNotNull(client, "client");
-      this.blobToObject = checkNotNull(blobToObject, "blobToObject");
-      this.algorithm = checkNotNull(algorithm, "algorithm");
-      this.slicer = checkNotNull(slicer, "slicer");
-   }
-
-   @Override
-   public String execute(String container, Blob blob) {
-      String key = blob.getMetadata().getName();
-      ContentMetadata metadata = blob.getMetadata().getContentMetadata();
-      Payload payload = blob.getPayload();
-      Long length = payload.getContentMetadata().getContentLength();
-      checkNotNull(length,
-            "please invoke payload.getContentMetadata().setContentLength(length) prior to multipart upload");
-      long chunkSize = algorithm.calculateChunkSize(length);
-      int partCount = algorithm.getParts();
-      if (partCount > 0) {
-         ObjectMetadataBuilder builder = ObjectMetadataBuilder.create().key(key)
-            .contentType(metadata.getContentType())
-            .contentDisposition(metadata.getContentDisposition())
-            .contentEncoding(metadata.getContentEncoding())
-            .contentLanguage(metadata.getContentLanguage())
-            .userMetadata(blob.getMetadata().getUserMetadata());
-         String uploadId = client.initiateMultipartUpload(container, builder.build());
-         try {
-            SortedMap<Integer, String> etags = Maps.newTreeMap();
-            for (Payload part : slicer.slice(payload, chunkSize)) {
-               int partNum = algorithm.getNextPart();
-               prepareUploadPart(container, key, uploadId, partNum, part, algorithm.getNextChunkOffset(), etags);
-            }
-            return client.completeMultipartUpload(container, key, uploadId, etags);
-         } catch (RuntimeException ex) {
-            client.abortMultipartUpload(container, key, uploadId);
-            throw ex;
-         }
-      } else {
-         // TODO: find a way to disable multipart. if we pass the original
-         // options, it goes into a stack overflow
-         return client.putObject(container, blobToObject.apply(blob));
-      }
-   }
-
-   private void prepareUploadPart(String container, String key, String uploadId, int part, Payload chunkedPart,
-         long offset, SortedMap<Integer, String> etags) {
-      String eTag = null;
-      try {
-         eTag = client.uploadPart(container, key, part, uploadId, chunkedPart);
-         etags.put(Integer.valueOf(part), eTag);
-      } catch (KeyNotFoundException e) {
-         // note that because of eventual consistency, the upload id may not be
-         // present yet we may wish to add this condition to the retry handler
-
-         // we may also choose to implement ListParts and wait for the uploadId
-         // to become available there.
-         eTag = client.uploadPart(container, key, part, uploadId, chunkedPart);
-         etags.put(Integer.valueOf(part), eTag);
-      }
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/ae157991/apis/s3/src/test/java/org/jclouds/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategyMockTest.java
----------------------------------------------------------------------
diff --git a/apis/s3/src/test/java/org/jclouds/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategyMockTest.java b/apis/s3/src/test/java/org/jclouds/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategyMockTest.java
deleted file mode 100644
index cdff2cc..0000000
--- a/apis/s3/src/test/java/org/jclouds/s3/blobstore/strategy/internal/SequentialMultipartUploadStrategyMockTest.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.s3.blobstore.strategy.internal;
-
-import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
-import static org.jclouds.Constants.PROPERTY_MAX_RETRIES;
-import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT;
-import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS;
-import static org.testng.Assert.assertEquals;
-
-import java.io.IOException;
-import java.util.Properties;
-import java.util.Set;
-
-import org.jclouds.ContextBuilder;
-import org.jclouds.blobstore.domain.internal.BlobBuilderImpl;
-import org.jclouds.concurrent.config.ExecutorServiceModule;
-import org.jclouds.http.HttpResponseException;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.net.HttpHeaders;
-import com.google.common.net.MediaType;
-import com.google.inject.Module;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-import com.squareup.okhttp.mockwebserver.RecordedRequest;
-
-@Test(singleThreaded = true)
-public class SequentialMultipartUploadStrategyMockTest {
-
-   @Test
-   public void testMPUDoesMultipart() throws IOException, InterruptedException {
-      MockWebServer server = new MockWebServer();
-      server.enqueue(new MockResponse().setResponseCode(200).setBody("<UploadId>upload-id</UploadId>"));
-      server.enqueue(new MockResponse().setResponseCode(200).addHeader("ETag", "a00"));
-      server.enqueue(new MockResponse().setResponseCode(200).addHeader("ETag", "b00"));
-      server.enqueue(new MockResponse().setResponseCode(200).setBody("<ETag>fff</ETag>"));
-      server.play();
-
-      byte[] bytes = "0123456789abcdef".getBytes(Charsets.US_ASCII);
-      int partSize = bytes.length / 2;
-
-      SequentialMultipartUploadStrategy api = mockSequentialMultipartUploadStrategy(server.getUrl("/").toString(),
-            partSize);
-
-      try {
-         assertEquals(api.execute("container", new BlobBuilderImpl().name("foo").payload(bytes)
-            .contentDisposition("inline; filename=foo.mp4")
-            .contentType(MediaType.MP4_VIDEO.toString())
-            .build()), "fff");
-      } finally {
-
-         RecordedRequest initiate = server.takeRequest();
-         assertEquals(initiate.getRequestLine(), "POST /container/foo?uploads HTTP/1.1");
-         assertEquals(initiate.getHeader("Content-Length"), "0");
-         assertEquals(initiate.getHeader(HttpHeaders.CONTENT_TYPE), MediaType.MP4_VIDEO.toString());
-         assertEquals(initiate.getHeader(HttpHeaders.CONTENT_DISPOSITION), "inline; filename=foo.mp4");
-
-         RecordedRequest part1 = server.takeRequest();
-         assertEquals(part1.getRequestLine(), "PUT /container/foo?partNumber=1&uploadId=upload-id HTTP/1.1");
-         assertEquals(part1.getHeader("Content-Length"), String.valueOf(partSize));
-         assertEquals(new String(part1.getBody()), "01234567");
-
-         RecordedRequest part2 = server.takeRequest();
-         assertEquals(part2.getRequestLine(), "PUT /container/foo?partNumber=2&uploadId=upload-id HTTP/1.1");
-         assertEquals(part2.getHeader("Content-Length"), String.valueOf(partSize));
-         assertEquals(new String(part2.getBody()), "89abcdef");
-
-         RecordedRequest manifest = server.takeRequest();
-         assertEquals(manifest.getRequestLine(), "POST /container/foo?uploadId=upload-id HTTP/1.1");
-         assertEquals(manifest.getHeader("Content-Length"), "161");
-         assertEquals(
-               new String(manifest.getBody()),
-               "<CompleteMultipartUpload><Part><PartNumber>1</PartNumber><ETag>a00</ETag></Part><Part><PartNumber>2</PartNumber><ETag>b00</ETag></Part></CompleteMultipartUpload>");
-
-         server.shutdown();
-      }
-   }
-
-   @Test(expectedExceptions = HttpResponseException.class)
-   public void testMPUAbortsOnProblem() throws IOException, InterruptedException {
-      MockWebServer server = new MockWebServer();
-      server.enqueue(new MockResponse().setResponseCode(200).setBody("<UploadId>upload-id</UploadId>"));
-      server.enqueue(new MockResponse().setResponseCode(400));
-      server.enqueue(new MockResponse().setResponseCode(200));
-      server.play();
-
-      byte[] bytes = "0123456789abcdef".getBytes(Charsets.US_ASCII);
-      int partSize = bytes.length / 2;
-
-      SequentialMultipartUploadStrategy api = mockSequentialMultipartUploadStrategy(server.getUrl("/").toString(),
-            partSize);
-
-      try {
-         assertEquals(api.execute("container", new BlobBuilderImpl().name("foo").payload(bytes).build()), "fff");
-      } finally {
-
-         RecordedRequest initiate = server.takeRequest();
-         assertEquals(initiate.getRequestLine(), "POST /container/foo?uploads HTTP/1.1");
-         assertEquals(initiate.getHeader("Content-Length"), "0");
-
-         RecordedRequest part1 = server.takeRequest();
-         assertEquals(part1.getRequestLine(), "PUT /container/foo?partNumber=1&uploadId=upload-id HTTP/1.1");
-         assertEquals(part1.getHeader("Content-Length"), String.valueOf(partSize));
-         assertEquals(new String(part1.getBody()), "01234567");
-
-         RecordedRequest abort = server.takeRequest();
-         assertEquals(abort.getRequestLine(), "DELETE /container/foo?uploadId=upload-id HTTP/1.1");
-
-         server.shutdown();
-      }
-   }
-
-   private static final Set<Module> modules = ImmutableSet.<Module>of(
-         new ExecutorServiceModule(sameThreadExecutor()));
-
-   static SequentialMultipartUploadStrategy mockSequentialMultipartUploadStrategy(String uri, int partSize) {
-      Properties overrides = new Properties();
-      overrides.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false");
-      // prevent expect-100 bug http://code.google.com/p/mockwebserver/issues/detail?id=6
-      overrides.setProperty(PROPERTY_SO_TIMEOUT, "0");
-      overrides.setProperty(PROPERTY_MAX_RETRIES, "1");
-      overrides.setProperty("jclouds.mpu.parts.size", String.valueOf(partSize));
-      return ContextBuilder.newBuilder("s3")
-                           .credentials("accessKey", "secretKey")
-                           .endpoint(uri)
-                           .overrides(overrides)
-                           .modules(modules)
-                           .buildInjector().getInstance(SequentialMultipartUploadStrategy.class);
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/ae157991/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java
----------------------------------------------------------------------
diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java
index 744056b..546bf34 100644
--- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java
+++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobStore.java
@@ -38,6 +38,7 @@ import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
 import org.jclouds.blobstore.util.BlobUtils;
 import org.jclouds.collect.Memoized;
 import org.jclouds.domain.Location;
+import org.jclouds.io.PayloadSlicer;
 import org.jclouds.s3.blobstore.S3BlobStore;
 import org.jclouds.s3.blobstore.functions.BlobToObject;
 import org.jclouds.s3.blobstore.functions.BlobToObjectMetadata;
@@ -45,7 +46,6 @@ import org.jclouds.s3.blobstore.functions.BucketToResourceList;
 import org.jclouds.s3.blobstore.functions.ContainerToBucketListOptions;
 import org.jclouds.s3.blobstore.functions.ObjectToBlob;
 import org.jclouds.s3.blobstore.functions.ObjectToBlobMetadata;
-import org.jclouds.s3.blobstore.strategy.MultipartUploadStrategy;
 import org.jclouds.s3.domain.AccessControlList;
 import org.jclouds.s3.domain.BucketMetadata;
 import org.jclouds.s3.domain.CannedAccessPolicy;
@@ -66,18 +66,16 @@ public class AWSS3BlobStore extends S3BlobStore {
 
    @Inject
    AWSS3BlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
-            @Memoized Supplier<Set<? extends Location>> locations, AWSS3Client sync,
+            @Memoized Supplier<Set<? extends Location>> locations, PayloadSlicer slicer, AWSS3Client sync,
             Function<Set<BucketMetadata>, PageSet<? extends StorageMetadata>> convertBucketsToStorageMetadata,
             ContainerToBucketListOptions container2BucketListOptions, BucketToResourceList bucket2ResourceList,
             ObjectToBlob object2Blob, BlobToHttpGetOptions blob2ObjectGetOptions, BlobToObject blob2Object,
             BlobToObjectMetadata blob2ObjectMetadata,
             ObjectToBlobMetadata object2BlobMd, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
-            LoadingCache<String, AccessControlList> bucketAcls,
-            Provider<MultipartUploadStrategy> multipartUploadStrategy) {
-      super(context, blobUtils, defaultLocation, locations, sync, convertBucketsToStorageMetadata,
+            LoadingCache<String, AccessControlList> bucketAcls) {
+      super(context, blobUtils, defaultLocation, locations, slicer, sync, convertBucketsToStorageMetadata,
                container2BucketListOptions, bucket2ResourceList, object2Blob, blob2ObjectGetOptions, blob2Object,
-               blob2ObjectMetadata, object2BlobMd, fetchBlobMetadataProvider, bucketAcls,
-               multipartUploadStrategy);
+               blob2ObjectMetadata, object2BlobMd, fetchBlobMetadataProvider, bucketAcls);
       this.bucketAcls = bucketAcls;
       this.blob2Object = blob2Object;
    }
@@ -85,9 +83,7 @@ public class AWSS3BlobStore extends S3BlobStore {
    @Override
    public String putBlob(String container, Blob blob, PutOptions options) {
       if (options.isMultipart()) {
-         // need to use a provider if the strategy object is stateful
-         return multipartUploadStrategy.get().execute(container, blob);
-
+         return putMultipartBlob(container, blob, options);
       } else if ((options instanceof AWSS3PutOptions) &&
          (((AWSS3PutOptions) options).getStorageClass() == REDUCED_REDUNDANCY)) {
          return putBlobWithReducedRedundancy(container, blob);