Search in sources :

Example 1 with CopyPartResult

use of com.emc.object.s3.bean.CopyPartResult in project pravega by pravega.

the class S3FileSystemImpl method copyPart.

@Override
public CopyPartResult copyPart(CopyPartRequest request) {
    Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
    if (partMap == null) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }
    partMap.put(request.getPartNumber(), request);
    CopyPartResult result = new CopyPartResult();
    result.setPartNumber(request.getPartNumber());
    result.setETag(request.getUploadId());
    return result;
}
Also used : CopyPartRequest(com.emc.object.s3.request.CopyPartRequest) S3Exception(com.emc.object.s3.S3Exception) CopyPartResult(com.emc.object.s3.bean.CopyPartResult)

Example 2 with CopyPartResult

use of com.emc.object.s3.bean.CopyPartResult in project pravega by pravega.

the class S3Mock method copyPart.

public CopyPartResult copyPart(CopyPartRequest request) {
    String objectName = getObjectName(request.getBucketName(), request.getKey());
    synchronized (this.objects) {
        Map<Integer, CopyPartRequest> partMap = this.multipartUploads.get(objectName);
        if (partMap == null) {
            throw new S3Exception("NoSuchUpload", HttpStatus.SC_NOT_FOUND, "NoSuchUpload", "");
        }
        if (partMap.containsKey(request.getPartNumber())) {
            // we want to make sure we don't do it.
            throw new S3Exception("Part exists already.", HttpStatus.SC_BAD_REQUEST, "InvalidArgument", "");
        }
        partMap.put(request.getPartNumber(), request);
        CopyPartResult result = new CopyPartResult();
        result.setPartNumber(request.getPartNumber());
        result.setETag(request.getUploadId());
        return result;
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CopyPartRequest(com.emc.object.s3.request.CopyPartRequest) S3Exception(com.emc.object.s3.S3Exception) CopyPartResult(com.emc.object.s3.bean.CopyPartResult)

Example 3 with CopyPartResult

use of com.emc.object.s3.bean.CopyPartResult in project pravega by pravega.

the class ExtendedS3Storage method doConcat.

/**
 * The concat is implemented using extended S3 implementation of multipart copy API. Please see here for
 * more detail on multipart copy:
 * http://docs.aws.amazon.com/AmazonS3/latest/dev/CopyingObjctsUsingLLJavaMPUapi.html
 *
 * The multipart copy is an atomic operation. We schedule two parts and commit them atomically using
 * completeMultiPartUpload call. Specifically, to concatenate, we are copying the target segment T and the
 * source segment S to T, so essentially we are doing T <- T + S.
 */
private Void doConcat(SegmentHandle targetHandle, long offset, String sourceSegment) throws StreamSegmentNotExistsException {
    Preconditions.checkArgument(!targetHandle.isReadOnly(), "target handle must not be read-only.");
    long traceId = LoggerHelpers.traceEnter(log, "concat", targetHandle.getSegmentName(), offset, sourceSegment);
    SortedSet<MultipartPartETag> partEtags = new TreeSet<>();
    String targetPath = config.getRoot() + targetHandle.getSegmentName();
    String uploadId = client.initiateMultipartUpload(config.getBucket(), targetPath);
    // check whether the target exists
    if (!doExists(targetHandle.getSegmentName())) {
        throw new StreamSegmentNotExistsException(targetHandle.getSegmentName());
    }
    // check whether the source is sealed
    SegmentProperties si = doGetStreamSegmentInfo(sourceSegment);
    Preconditions.checkState(si.isSealed(), "Cannot concat segment '%s' into '%s' because it is not sealed.", sourceSegment, targetHandle.getSegmentName());
    // Copy the first part
    CopyPartRequest copyRequest = new CopyPartRequest(config.getBucket(), targetPath, config.getBucket(), targetPath, uploadId, 1).withSourceRange(Range.fromOffsetLength(0, offset));
    CopyPartResult copyResult = client.copyPart(copyRequest);
    partEtags.add(new MultipartPartETag(copyResult.getPartNumber(), copyResult.getETag()));
    // Copy the second part
    S3ObjectMetadata metadataResult = client.getObjectMetadata(config.getBucket(), config.getRoot() + sourceSegment);
    // in bytes
    long objectSize = metadataResult.getContentLength();
    copyRequest = new CopyPartRequest(config.getBucket(), config.getRoot() + sourceSegment, config.getBucket(), targetPath, uploadId, 2).withSourceRange(Range.fromOffsetLength(0, objectSize));
    copyResult = client.copyPart(copyRequest);
    partEtags.add(new MultipartPartETag(copyResult.getPartNumber(), copyResult.getETag()));
    // Close the upload
    client.completeMultipartUpload(new CompleteMultipartUploadRequest(config.getBucket(), targetPath, uploadId).withParts(partEtags));
    client.deleteObject(config.getBucket(), config.getRoot() + sourceSegment);
    LoggerHelpers.traceLeave(log, "concat", traceId);
    return null;
}
Also used : CopyPartRequest(com.emc.object.s3.request.CopyPartRequest) TreeSet(java.util.TreeSet) MultipartPartETag(com.emc.object.s3.bean.MultipartPartETag) S3ObjectMetadata(com.emc.object.s3.S3ObjectMetadata) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) CopyPartResult(com.emc.object.s3.bean.CopyPartResult) StreamSegmentNotExistsException(io.pravega.segmentstore.contracts.StreamSegmentNotExistsException) CompleteMultipartUploadRequest(com.emc.object.s3.request.CompleteMultipartUploadRequest)

Example 4 with CopyPartResult

use of com.emc.object.s3.bean.CopyPartResult in project pravega by pravega.

the class ExtendedS3ChunkStorage method doConcat.

@Override
public int doConcat(ConcatArgument[] chunks) throws ChunkStorageException {
    int totalBytesConcatenated = 0;
    String targetPath = getObjectPath(chunks[0].getName());
    String uploadId = null;
    boolean isCompleted = false;
    try {
        int partNumber = 1;
        SortedSet<MultipartPartETag> partEtags = new TreeSet<>();
        uploadId = client.initiateMultipartUpload(config.getBucket(), targetPath);
        // check whether the target exists
        if (!checkExists(chunks[0].getName())) {
            throw new ChunkNotFoundException(chunks[0].getName(), "doConcat - Target segment does not exist");
        }
        // Copy the parts
        for (int i = 0; i < chunks.length; i++) {
            if (0 != chunks[i].getLength()) {
                val sourceHandle = chunks[i];
                S3ObjectMetadata metadataResult = client.getObjectMetadata(config.getBucket(), getObjectPath(sourceHandle.getName()));
                // in bytes
                long objectSize = metadataResult.getContentLength();
                Preconditions.checkState(objectSize >= chunks[i].getLength());
                CopyPartRequest copyRequest = new CopyPartRequest(config.getBucket(), getObjectPath(sourceHandle.getName()), config.getBucket(), targetPath, uploadId, partNumber++).withSourceRange(Range.fromOffsetLength(0, chunks[i].getLength()));
                CopyPartResult copyResult = client.copyPart(copyRequest);
                partEtags.add(new MultipartPartETag(copyResult.getPartNumber(), copyResult.getETag()));
                totalBytesConcatenated += chunks[i].getLength();
            }
        }
        // Close the upload
        client.completeMultipartUpload(new CompleteMultipartUploadRequest(config.getBucket(), targetPath, uploadId).withParts(partEtags));
        isCompleted = true;
    } catch (RuntimeException e) {
        // Error message is REC_CATCH_EXCEPTION: Exception is caught when Exception is not thrown
        throw convertException(chunks[0].getName(), "doConcat", e);
    } catch (Exception e) {
        throw convertException(chunks[0].getName(), "doConcat", e);
    } finally {
        if (!isCompleted && null != uploadId) {
            client.abortMultipartUpload(new AbortMultipartUploadRequest(config.getBucket(), targetPath, uploadId));
        }
    }
    return totalBytesConcatenated;
}
Also used : ChunkNotFoundException(io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException) lombok.val(lombok.val) AbortMultipartUploadRequest(com.emc.object.s3.request.AbortMultipartUploadRequest) InvalidOffsetException(io.pravega.segmentstore.storage.chunklayer.InvalidOffsetException) S3Exception(com.emc.object.s3.S3Exception) ChunkStorageException(io.pravega.segmentstore.storage.chunklayer.ChunkStorageException) ChunkNotFoundException(io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException) ChunkAlreadyExistsException(io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException) CopyPartRequest(com.emc.object.s3.request.CopyPartRequest) TreeSet(java.util.TreeSet) MultipartPartETag(com.emc.object.s3.bean.MultipartPartETag) S3ObjectMetadata(com.emc.object.s3.S3ObjectMetadata) CopyPartResult(com.emc.object.s3.bean.CopyPartResult) CompleteMultipartUploadRequest(com.emc.object.s3.request.CompleteMultipartUploadRequest)

Example 5 with CopyPartResult

use of com.emc.object.s3.bean.CopyPartResult in project pravega by pravega.

the class ExtendedS3Storage method doConcatWithMultipartUpload.

private void doConcatWithMultipartUpload(String targetPath, String sourceSegment, long offset) {
    String uploadId = client.initiateMultipartUpload(config.getBucket(), targetPath);
    SortedSet<MultipartPartETag> partEtags = new TreeSet<>();
    // Copy the first part
    CopyPartRequest copyRequest = new CopyPartRequest(config.getBucket(), targetPath, config.getBucket(), targetPath, uploadId, 1).withSourceRange(Range.fromOffsetLength(0, offset));
    CopyPartResult copyResult = client.copyPart(copyRequest);
    partEtags.add(new MultipartPartETag(copyResult.getPartNumber(), copyResult.getETag()));
    // Copy the second part
    S3ObjectMetadata metadataResult = client.getObjectMetadata(config.getBucket(), config.getPrefix() + sourceSegment);
    // in bytes
    long objectSize = metadataResult.getContentLength();
    copyRequest = new CopyPartRequest(config.getBucket(), config.getPrefix() + sourceSegment, config.getBucket(), targetPath, uploadId, 2).withSourceRange(Range.fromOffsetLength(0, objectSize));
    copyResult = client.copyPart(copyRequest);
    partEtags.add(new MultipartPartETag(copyResult.getPartNumber(), copyResult.getETag()));
    // Close the upload
    client.completeMultipartUpload(new CompleteMultipartUploadRequest(config.getBucket(), targetPath, uploadId).withParts(partEtags));
}
Also used : CopyPartRequest(com.emc.object.s3.request.CopyPartRequest) TreeSet(java.util.TreeSet) MultipartPartETag(com.emc.object.s3.bean.MultipartPartETag) S3ObjectMetadata(com.emc.object.s3.S3ObjectMetadata) CopyPartResult(com.emc.object.s3.bean.CopyPartResult) CompleteMultipartUploadRequest(com.emc.object.s3.request.CompleteMultipartUploadRequest)

Aggregations

CopyPartResult (com.emc.object.s3.bean.CopyPartResult)5 CopyPartRequest (com.emc.object.s3.request.CopyPartRequest)5 S3Exception (com.emc.object.s3.S3Exception)3 S3ObjectMetadata (com.emc.object.s3.S3ObjectMetadata)3 MultipartPartETag (com.emc.object.s3.bean.MultipartPartETag)3 CompleteMultipartUploadRequest (com.emc.object.s3.request.CompleteMultipartUploadRequest)3 TreeSet (java.util.TreeSet)3 AbortMultipartUploadRequest (com.emc.object.s3.request.AbortMultipartUploadRequest)1 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)1 StreamSegmentNotExistsException (io.pravega.segmentstore.contracts.StreamSegmentNotExistsException)1 ChunkAlreadyExistsException (io.pravega.segmentstore.storage.chunklayer.ChunkAlreadyExistsException)1 ChunkNotFoundException (io.pravega.segmentstore.storage.chunklayer.ChunkNotFoundException)1 ChunkStorageException (io.pravega.segmentstore.storage.chunklayer.ChunkStorageException)1 InvalidOffsetException (io.pravega.segmentstore.storage.chunklayer.InvalidOffsetException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 lombok.val (lombok.val)1