@@ -1437,17 +1437,15 @@ private <X> Object callCOSClientWithRetry(X request) throws CosServiceException,
1437
1437
String errorCode = cse .getErrorCode ();
1438
1438
LOG .debug ("fail to retry statusCode {}, errorCode {}" , statusCode , errorCode );
1439
1439
// 对5xx错误进行重试
1440
- if (request instanceof CopyObjectRequest && statusCode / 100 == 2
1441
- && errorCode != null && !errorCode .isEmpty ()) {
1440
+ if (request instanceof CopyObjectRequest && hasErrorCode (statusCode , errorCode )) {
1442
1441
if (retryIndex <= this .maxRetryTimes ) {
1443
1442
LOG .info (errMsg , cse );
1444
1443
++retryIndex ;
1445
1444
} else {
1446
1445
LOG .error (errMsg , cse );
1447
1446
throw new IOException (errMsg );
1448
1447
}
1449
- } else if (request instanceof CompleteMultipartUploadRequest && statusCode / 100 ==2
1450
- && errorCode != null && !errorCode .isEmpty ()) {
1448
+ } else if (request instanceof CompleteMultipartUploadRequest && hasErrorCode (statusCode , errorCode )) {
1451
1449
// complete mpu error code might be in body when status code is 200
1452
1450
// double check to head object only works in big data job case which key is not same.
1453
1451
String key = ((CompleteMultipartUploadRequest ) request ).getKey ();
@@ -1507,6 +1505,21 @@ private <X> Object callCOSClientWithRetry(X request) throws CosServiceException,
1507
1505
throw cse ;
1508
1506
}
1509
1507
}
1508
+
1509
+ // mpu might occur 503 access time out but already completed,
1510
+ // if direct retry may occur 403 not found the upload id.
1511
+ if (request instanceof CompleteMultipartUploadRequest && statusCode == 503 ) {
1512
+ String key = ((CompleteMultipartUploadRequest ) request ).getKey ();
1513
+ FileMetadata fileMetadata = this .queryObjectMetadata (key );
1514
+ if (null != fileMetadata ) {
1515
+ // if file exist direct return.
1516
+ LOG .info ("complete mpu error might access time out, " +
1517
+ "but key {} already exist, length {}" ,
1518
+ key , fileMetadata .getLength ());
1519
+ return new CompleteMultipartUploadResult ();
1520
+ }
1521
+ }
1522
+
1510
1523
Thread .sleep (
1511
1524
ThreadLocalRandom .current ().nextLong (sleepLeast , sleepBound ));
1512
1525
++retryIndex ;
@@ -1529,6 +1542,15 @@ private <X> Object callCOSClientWithRetry(X request) throws CosServiceException,
1529
1542
private static String ensureValidAttributeName (String attributeName ) {
1530
1543
return attributeName .replace ('.' , '-' ).toLowerCase ();
1531
1544
}
1545
+
1546
+ private boolean hasErrorCode (int statusCode , String errCode ) {
1547
+ return statusCode / 100 == 2 && errCode != null && !errCode .isEmpty ();
1548
+ }
1549
+
1550
+ public COSClient getCOSClient (){
1551
+ return this .cosClient ;
1552
+ }
1553
+
1532
1554
private String getPluginVersionInfo () {
1533
1555
Properties versionProperties = new Properties ();
1534
1556
InputStream inputStream = null ;
0 commit comments