Skip to content

Commit 8528a3e

Browse files
authored
mpu 409 retry with head (#58)
Co-authored-by: alantong <[email protected]>
1 parent 3aa7f33 commit 8528a3e

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.qcloud.cos</groupId>
88
<artifactId>hadoop-cos</artifactId>
9-
<version>8.0.7</version>
9+
<version>8.0.8</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Apache Hadoop Tencent Cloud COS Support</name>

src/main/java/org/apache/hadoop/fs/CosNConfigKeys.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@InterfaceStability.Unstable
1313
public class CosNConfigKeys extends CommonConfigurationKeys {
1414
public static final String USER_AGENT = "fs.cosn.user.agent";
15-
public static final String DEFAULT_USER_AGENT = "cos-hadoop-plugin-v8.0.7";
15+
public static final String DEFAULT_USER_AGENT = "cos-hadoop-plugin-v8.0.8";
1616

1717
public static final String TENCENT_EMR_VERSION_KEY = "fs.emr.version";
1818

src/main/java/org/apache/hadoop/fs/CosNativeFileSystemStore.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,27 @@ public int compare(PartETag o1, PartETag o2) {
512512
partETagList);
513513
completeMultipartUploadRequest.setObjectMetadata(objectMetadata);
514514
return (CompleteMultipartUploadResult) this.callCOSClientWithRetry(completeMultipartUploadRequest);
515+
} catch (CosServiceException cse) {
516+
// 避免并发上传的问题
517+
int statusCode = cse.getStatusCode();
518+
if (statusCode == 409) {
519+
// Check一下这个文件是否已经存在
520+
FileMetadata fileMetadata = this.queryObjectMetadata(key);
521+
if (null == fileMetadata) {
522+
// 如果文件不存在,则需要抛出异常
523+
handleException(cse, key);
524+
}
525+
LOG.warn("Upload the cos key [{}] complete mpu concurrently", key);
526+
} else {
527+
// 其他错误都要抛出来
528+
String errMsg = String.format("Complete the multipart upload failed. " +
529+
"cos service exception, cos key: %s, upload id: %s, " +
530+
"exception: %s", key, uploadId, cse.toString());
531+
handleException(new Exception(errMsg), key);
532+
}
515533
} catch (Exception e) {
516-
String errMsg = String.format("Complete the multipart upload failed. cos key: %s, upload id: %s, " +
534+
String errMsg = String.format("Complete the multipart upload failed. " +
535+
"cos key: %s, upload id: %s, " +
517536
"exception: %s", key, uploadId, e.toString());
518537
handleException(new Exception(errMsg), key);
519538
}

0 commit comments

Comments
 (0)