2011-01-15 14 views
15

Amazon-SDK(Java)のサンプルコードS3TransferProgressSample.javaを使用して、大きなファイルをAmazon-S3ストレージ(also posted here on AWS docs)にアップロードしようとしました。大きなファイルをAmazon S3にアップロードする際の問題

しかし、私は11ギガバイトのファイルをアップロードしようとしていたとき、アップロードはエラーメッセージを表示して異なるポイントで立ち往生されています

Unable to upload file to Amazon S3: Unable to upload part: Unable toexecute HTTP request: Unbuffered entity enclosing request can not be repeated " (attached screenshot). 

にIOExceptionがSDKは、要求を再試行することができません発生した後、それはそのように見えます(下記参照)。

誰かがこれに遭遇しますか?これを解決するベストプラクティスは何ですか?任意のコードが評価されます。

INFO: Received successful response: 200, AWS Request ID: 
2B66E7669E24DA75<br> Jan 15, 2011 6:44:46 AM 
com.amazonaws.http.HttpClient execute<br> INFO: Sending Request: PUT 
s3.amazonaws.com /test_file_upload/autogenerated.txt Parameters: 
(uploadId: 
    m9MqxzD484Ys1nifnX._IzJBGbCFIoT_zBg0xdd6kkZ4TAtmcG0lXQOE.LeiSEuqn6NjcosIQLXJeKzSnKllmw--, partNumber: 1494,)<br> Jan 15, 2011 6:45:10 AM 
    org.apache.commons.httpclient.HttpMethodDirector executeWithRetry<br> 
    **INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error**<br> 
    Jan 15, 2011 6:45:10 AM 
    org.apache.commons.httpclient.HttpMethodDirector executeWithRetry<br> 
    INFO: Retrying request<br> Jan 15, 2011 6:45:12 AM 
    com.amazonaws.http.HttpClient execute<br> WARNING: Unable to execute 
    HTTP request: Unbuffered entity enclosing request can not be 
    repeated.<br> Jan 15, 2011 6:45:12 AM 
    org.apache.commons.httpclient.HttpMethodDirector executeWithRetry<br> 
    **INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error**<br> 
    Jan 15, 2011 6:45:12 AM 
    org.apache.commons.httpclient.HttpMethodDirector executeWithRetry<br> 
    INFO: Retrying request<br> Jan 15, 2011 6:45:13 AM 
    org.apache.commons.httpclient.HttpMethodDirector executeWithRetry<br> 
    **INFO: I/O exception (java.net.SocketException) caught when processing request: Connection reset by peer: socket write error**<br> 
    Jan 15, 2011 6:45:13 AM 
    org.apache.commons.httpclient.HttpMethodDirector executeWithRetry<br> 
    INFO: Retrying request<br> Jan 15, 2011 6:45:13 AM 
    com.amazonaws.http.HttpClient execute<br> 
    **WARNING: Unable to execute HTTP request: Unbuffered entity enclosing request can not be repeated.**<br> Jan 15, 2011 6:45:14 AM 
    com.amazonaws.http.HttpClient execute<br> WARNING: Unable to execute 
    HTTP request: Unbuffered entity enclosing request can not be 
    repeated.<br> Jan 15, 2011 6:45:14 AM com.amazonaws.http.HttpClient 
    execute<br> WARNING: Unable to execute HTTP request: Unbuffered entity 
    enclosing request can not be repeated.<br> Jan 15, 2011 6:45:14 AM 
    com.amazonaws.http.HttpClient execute<br> WARNING: Unable to execute 
    HTTP request: Unbuffered entity enclosing request can not be 
    repeated.<br> Jan 15, 2011 6:45:15 AM com.amazonaws.http.HttpClient 
    execute<br> WARNING: Unable to execute HTTP request: Unbuffered entity 
    enclosing request can not be repeated.<br> Jan 15, 2011 6:45:16 AM 
    com.amazonaws.http.HttpClient execute<br> WARNING: Unable to execute 
    HTTP request: Unbuffered entity enclosing request can not be 
    repeated.<br> Jan 15, 2011 6:45:16 AM 

com.amazonaws.http.HttpClient 
    execute<br> WARNING: Unable to execute HTTP request: Unbuffered entity 
    enclosing request can not be repeated.<br> Jan 15, 2011 6:45:17 AM 
    com.amazonaws.http.HttpClient execute<br> WARNING: Unable to execute 
    HTTP request: Unbuffered entity enclosing request can not be 
    repeated.<br> Jan 15, 2011 6:45:19 AM com.amazonaws.http.HttpClient 
    execute<br> WARNING: Unable to execute HTTP request: Unbuffered entity 
    enclosing request can not be repeated.<br> Jan 15, 2011 6:45:19 AM 
    com.amazonaws.http.HttpClient execute<br> ....<br> Jan 15, 2011 
    6:45:21 AM com.amazonaws.http.HttpClient handleResponse<br> 
    **INFO: Received successful response: 204, AWS Request ID: E794B8FCA4C3D007**<br> Jan 15, 2011 6:45:21 AM 
    com.amazonaws.http.HttpClient execute<br> ...<br> Jan 15, 2011 6:45:19 
    AM com.amazonaws.http.HttpClient execute<br> INFO: Sending Request: 
    DELETE s3.amazonaws.com /test_file_upload/autogenerated.txt 
    Parameters:<br> ...<br> Jan 15, 2011 6:47:01 AM 
    com.amazonaws.http.HttpClient handleErrorResponse<br> INFO: Received 
    error response: Status Code: 404, AWS Request ID: 0CE25DFE767CC595, 
    AWS Error Code: NoSuchUpload, AWS Error Message: The specified upload 
    does not exist. The upload ID may be invalid, or the upload may have 
    been aborted or completed.<br> 

答えて

17

low level APIをお試しください。

これは、11GBファイルと関係している可能性があるため、問題が発生したときには、これをはるかにコントロールします。

S3からのリクエストは時折失敗します。低レベルのAPIを使用すると、失敗した場合にアップロードの一部を再試行することができます。

アマゾンのドキュメントにビットを例にリファクタリング:

// Step 2: Upload parts. 
long filePosition = 0; 
for (int i = 1; filePosition < contentLength; i++) { 
    // Last part can be less than 5 MB. Adjust part size. 
    partSize = Math.min(partSize, (contentLength - filePosition)); 

    // Create request to upload a part. 
    UploadPartRequest uploadRequest = new UploadPartRequest() 
       .withBucketName(existingBucketName).withKey(keyName) 
       .withUploadId(initResponse.getUploadId()).withPartNumber(i) 
       .withFileOffset(filePosition) 
       .withFile(file) 
       .withPartSize(partSize); 

    // repeat the upload until it succeeds. 
    boolean anotherPass; 
     do { 
       anotherPass = false; // assume everythings ok 
       try { 
        // Upload part and add response to our list. 
        partETags.add(s3Client.uploadPart(uploadRequest).getPartETag()); 
       } catch (Exception e) { 
        anotherPass = true; // repeat 
       } 
     } while (anotherPass); 

    filePosition += partSize; 
} 

    // Step 3: complete. 
    CompleteMultipartUploadRequest compRequest = new 
        CompleteMultipartUploadRequest(
           existingBucketName, 
           keyName, 
           initResponse.getUploadId(), 
           partETags); 

    s3Client.completeMultipartUpload(compRequest); 

注:私はので、私は構文的に物事を台無しにしている可能性がJava開発者ではないですが、うまくいけば、これはあなたが正しい方向に向かっ取得します。また、アップロードが繰り返し失敗した場合は、無限ループを防ぐために「再試行カウンタ」を追加することをお勧めします。

+0

OK、エラー時にアップロードの一部を再試行する方法をコードで指定できますか? – Alexey

+0

@Alexey - うまくいけば正しい軌道に乗せるためにサンプルを追加しました。基本的な考え方は、アップロード全体をキャンセルするのではなく、失敗した場合にパーツを再試行することです。 –

+0

ありがとう、これは私の問題を解決しました。良いアイデアは、高速アップロードを可能にするために複数のスレッドを使用することです。 – Alexey

2

サイズ11GBのファイルを1つアップロードしようとしていますか?または、すべてのファイルの合計サイズは11GBですか? S3の最大ファイルサイズ制限は5GBです。

+0

サイズが11 GBのファイルが1つあります。 5 GBの制限はありません。これは、Amazon Webインターフェイス(大容量ファイルを有効にするオプション)を使用してアップロードすると、最大5TBのファイルをアップロードできるためです。私はただJavaプログラム – Alexey

+0

からドキュメントを引用したいと思います(リンクは上記記事のリンクです):「オブジェクトをアップロードする - MultipartアップロードAPIを使用すると、最大5 TBの大きなオブジェクトをアップロードできます。 – Alexey

+0

これはS3の新機能です。 –

1

Geoff Applefordの答えが私に役立ちます。 しかし、whileループ制御文にretryCount < MAX_RETRIESを追加し、whileループ内で捕捉されたすべての例外に対してretryCountを増やします。あなたはマルチパートアップロードの下にすでにあるキーにマルチパートアップロードを行うにしようとした場合

Aviad

3

側の注意点としては、404エラーがスローされることがあります。

1

を、私はジェフ・アップルフォードの答えにコメントを追加したかったが、SO、私がすることができません。一般的に、低レベルのAPIを使用する彼の答えはうまくいきますが、do-whileループがある場合でも、ループの方法が設計されていますが、再構築ロジックが組み込まれています。彼のコードスニペットでは、ファイルの位置は、成功した場合にのみ増加し、そうでなければ同じパートを再度アップロードします。

関連する問題