Skip to content

Commit

Permalink
fix: Fix retry strategy for read IOException.
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Yu <[email protected]>
  • Loading branch information
yuyang733 committed May 8, 2024
1 parent d7dffc4 commit 3c70be7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/org/apache/hadoop/fs/CosNFileReadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -76,14 +77,14 @@ public void run() {
try {
this.retrieveBlock();
needRetry = false;
} catch (IOException ioException) {
} catch (SocketException socketException) {
// if we get stream success, but exceptions occurs when read cos input stream
String errMsg = String.format("retrieve block sdk socket failed, " +
"retryIndex: [%d / %d], key: %s, range: [%d , %d], exception: %s",
retryIndex, this.socketErrMaxRetryTimes, this.key,
this.readBuffer.getStart(), this.readBuffer.getEnd(), ioException.toString());
this.readBuffer.getStart(), this.readBuffer.getEnd(), socketException.toString());
if (retryIndex <= this.socketErrMaxRetryTimes) {
LOG.info(errMsg, ioException);
LOG.info(errMsg, socketException);
long sleepLeast = retryIndex * 300L;
long sleepBound = retryIndex * 500L;
try {
Expand All @@ -96,11 +97,19 @@ public void run() {
break;
}
} else {
this.setFailResult(errMsg, ioException);
this.setFailResult(errMsg, socketException);
break;
}
} catch (IOException ioException) {
String errMsg = String.format("retrieve block failed, " +
"retryIndex: [%d / %d], key: %s, range: [%d , %d], io exception: %s",
retryIndex, this.socketErrMaxRetryTimes, this.key,
this.readBuffer.getStart(), this.readBuffer.getEnd(), ioException);
this.setFailResult(errMsg, ioException);
break;
} catch (Throwable throwable) {
this.setFailResult("retrieve block failed", new IOException(throwable));
break;
}

if (!needRetry) {
Expand Down

0 comments on commit 3c70be7

Please sign in to comment.