@@ -512,8 +512,27 @@ public int compare(PartETag o1, PartETag o2) {
512
512
partETagList );
513
513
completeMultipartUploadRequest .setObjectMetadata (objectMetadata );
514
514
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
+ }
515
533
} 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, " +
517
536
"exception: %s" , key , uploadId , e .toString ());
518
537
handleException (new Exception (errMsg ), key );
519
538
}
0 commit comments