2011-01-15 24 views
15

पर बड़ी फ़ाइलों को अपलोड करते समय समस्याएं मैंने अमेज़ॅन-एस 3 स्टोरेज (also posted here on AWS docs) पर बड़ी फ़ाइलों को अपलोड करने के लिए अमेज़ॅन-एसडीके (जावा) नमूना कोड S3TransferProgressSample.java का उपयोग करने का प्रयास किया।अमेज़ॅन एस 3

लेकिन जब मैं 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 होता एसडीके पुनः अनुरोध करने में सक्षम नहीं है (निचे देखो)।

क्या किसी को इसका सामना करना पड़ता है? इसे हल करने के लिए सबसे अच्छा अभ्यास क्या है? किसी भी कोड की सराहना की है।

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 का उपयोग करने का प्रयास करें।

चीजें गलत होने पर यह आपको अधिक नियंत्रण देगा, क्योंकि उन्हें 11 जीबी फ़ाइल के साथ करने की संभावना है।

समय-समय पर एस 3 से अनुरोध विफल रहता है। निम्न स्तर एपीआई के साथ, यदि अपलोड विफल हो जाता है तो आप अपलोड का एक हिस्सा पुनः प्रयास करने में सक्षम होंगे।

अमेज़न डॉक्स में उदाहरण Refactoring एक सा:

// 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); 

नोट: मैं एक जावा डेवलपर तो मैं चीजों वाक्य रचना में गड़बड़ हो सकता है नहीं हूँ, लेकिन उम्मीद है कि यह आप सही दिशा में जा रहा हो जाता है। साथ ही, यदि अपलोड बार-बार विफल हो जाता है तो आप अंतहीन पाश को रोकने के लिए 'पुनः प्रयास काउंटर' में जोड़ना चाहेंगे।

+0

ठीक है, क्या ypu कोड का एक टुकड़ा प्रदान कर सकता है कि विफलता पर अपलोड का एक हिस्सा कैसे पुनः प्रयास करें? – Alexey

+0

@Alexey - मैंने आपको सही ट्रैक पर रखने के लिए एक नमूना जोड़ा है। बुनियादी विचार यह है कि अगर वह पूरे अपलोड को रद्द करने की बजाए विफल रहता है तो एक भाग फिर से प्रयास करना है। –

+0

धन्यवाद, इसने मेरी समस्या का समाधान किया। एक अच्छा विचार है कि कई धागे का उपयोग तेजी से अपलोड करने के लिए – Alexey

2

क्या आप आकार 11 जीबी की एक फ़ाइल अपलोड करने की कोशिश कर रहे हैं? या आपकी सभी फाइलों का आकार 11 जीबी है? क्योंकि एस 3 पर अधिकतम फ़ाइल आकार सीमा 5 जीबी है।

+0

आकार 11 जीबी की एक फ़ाइल। अब 5 जीबी सीमा नहीं है, क्योंकि अगर आप इसे अमेज़ॅन वेब इंटरफ़ेस (बड़े फाइल विकल्प सक्षम करें) के माध्यम से अपलोड करते हैं तो यह आपको 5TB तक फ़ाइलों को अपलोड करने की अनुमति देता है। मैं सिर्फ जावा प्रोग्राम – Alexey

+0

से अपने दस्तावेज़ों से उद्धरण करना चाहता हूं (लिंक ऊपर दिए गए मेरे पोस्ट में है): "पार्ट्स में ऑब्जेक्ट अपलोड करें- मल्टीपार्ट अपलोड एपीआई का उपयोग करके आप 5 टीबी तक बड़ी ऑब्जेक्ट्स अपलोड कर सकते हैं।" – Alexey

+0

यह एस 3 की एक नई सुविधा है। –

1

जेफ एप्पलफोर्ड का उत्तर मेरे लिए काम करता है। हालांकि, मैं & & रीट्रीकाउंट < MAX_RETRIES को लूप कंट्रोल स्टेटमेंट में जोड़ता हूं और थोड़ी देर के अंदर पकड़े गए प्रत्येक अपवाद पर पुनः प्रयास की वृद्धि करता हूं।

Aviad

3

एक तरफ ध्यान दें के रूप में, 404 त्रुटियों फेंकी जा सकती है अगर आप एक कुंजी एक बहुखण्डीय अपलोड तहत पहले से ही है कि करने के लिए एक बहुखण्डीय अपलोड करने की कोशिश।

1

मैं ज्यॉफ़ एप्पलफोर्ड के जवाब के लिए एक टिप्पणी जोड़ना चाहते थे लेकिन मेरे लिए अनुमति नहीं होगी। आम तौर पर निम्न स्तर के एपीआई का उपयोग करने का उसका जवाब ठीक काम करता है, लेकिन अगर हमारे पास अब एक लूप को डिज़ाइन करने का तरीका है, तो इसमें अंतर्निहित रीट्री लॉजिक है। अपने कोड स्निपेट में फ़ाइल स्थिति केवल तब होती है जब सफलता होती है अन्यथा आप एक ही भाग को फिर से अपलोड कर रहे हैं।