Skip to content

Commit 3c70be7

Browse files
committed
fix: Fix retry strategy for read IOException.
Signed-off-by: Yang Yu <yuyang_733@163.com>
1 parent d7dffc4 commit 3c70be7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.io.IOException;
99
import java.io.InputStream;
10+
import java.net.SocketException;
1011
import java.util.concurrent.ThreadLocalRandom;
1112
import java.util.concurrent.TimeUnit;
1213
import java.util.concurrent.atomic.AtomicBoolean;
@@ -76,14 +77,14 @@ public void run() {
7677
try {
7778
this.retrieveBlock();
7879
needRetry = false;
79-
} catch (IOException ioException) {
80+
} catch (SocketException socketException) {
8081
// if we get stream success, but exceptions occurs when read cos input stream
8182
String errMsg = String.format("retrieve block sdk socket failed, " +
8283
"retryIndex: [%d / %d], key: %s, range: [%d , %d], exception: %s",
8384
retryIndex, this.socketErrMaxRetryTimes, this.key,
84-
this.readBuffer.getStart(), this.readBuffer.getEnd(), ioException.toString());
85+
this.readBuffer.getStart(), this.readBuffer.getEnd(), socketException.toString());
8586
if (retryIndex <= this.socketErrMaxRetryTimes) {
86-
LOG.info(errMsg, ioException);
87+
LOG.info(errMsg, socketException);
8788
long sleepLeast = retryIndex * 300L;
8889
long sleepBound = retryIndex * 500L;
8990
try {
@@ -96,11 +97,19 @@ public void run() {
9697
break;
9798
}
9899
} else {
99-
this.setFailResult(errMsg, ioException);
100+
this.setFailResult(errMsg, socketException);
100101
break;
101102
}
103+
} catch (IOException ioException) {
104+
String errMsg = String.format("retrieve block failed, " +
105+
"retryIndex: [%d / %d], key: %s, range: [%d , %d], io exception: %s",
106+
retryIndex, this.socketErrMaxRetryTimes, this.key,
107+
this.readBuffer.getStart(), this.readBuffer.getEnd(), ioException);
108+
this.setFailResult(errMsg, ioException);
109+
break;
102110
} catch (Throwable throwable) {
103111
this.setFailResult("retrieve block failed", new IOException(throwable));
112+
break;
104113
}
105114

106115
if (!needRetry) {

0 commit comments

Comments
 (0)