majdyz commented on a change in pull request #3109:
URL: https://github.com/apache/hadoop/pull/3109#discussion_r655260406
##########
File path:
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AInputStream.java
##########
@@ -396,6 +396,41 @@ private void incrementBytesRead(long bytesRead) {
}
}
+ @FunctionalInterface
+ interface CheckedIntSupplier {
+ int get() throws IOException;
+ }
+
+ /**
+ * Helper function that allows to retry an IntSupplier in case of
`IOException`.
+ * This function is used by `read()` and `read(buf, off, len)` functions. It
tries to run
+ * `readFn` and in case of `IOException`:
+ * 1. If it gets an EOFException, return -1
+ * 2. Else, run `onReadFailure` and retry running `readFn`. If it fails
again,
+ * we run `onReadFailure` and re-throw the error.
+ * @param readFn the function to read, it must return an integer
+ * @param length length of data being attempted to read
+ * @return -1 if `readFn` throws EOFException, else returns int value from
the result of `readFn`
+ * @throws IOException if retry of `readFn` also fails with `IOException`
+ */
+ private int retryReadOnce(CheckedIntSupplier readFn, int length) throws
IOException {
+ try {
+ return readFn.get();
+ } catch (EOFException e) {
+ return -1;
+ } catch (IOException e) {
+ onReadFailure(e, length, e instanceof SocketTimeoutException);
Review comment:
This method is used on both `read()` and `read(b, off, len)` we use
length = 1 for `read()` and variable length for `read(b, off, len)`. It's
intended to keep the current behaviour
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]