-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exception handling. Fix Multi-part uploads
- Loading branch information
Showing
5 changed files
with
72 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,14 @@ public boolean hasCapability(String capability) { | |
@Override | ||
public int read() throws IOException { | ||
throwIfClosed(); | ||
return inputStream.read(); | ||
int bytesRead; | ||
try { | ||
bytesRead = inputStream.read(); | ||
} catch (IOException ioe){ | ||
onReadFailure(ioe); | ||
throw ioe; | ||
} | ||
return bytesRead; | ||
} | ||
|
||
@Override | ||
|
@@ -89,18 +96,32 @@ public synchronized long getPos() { | |
* | ||
* @param buf buffer to read data into | ||
* @param off start position in buffer at which data is written | ||
* @param n the number of bytes to read; the n-th byte should be the last byte of the stream. | ||
* @param len the number of bytes to read; the n-th byte should be the last byte of the stream. | ||
* @return the total number of bytes read into the buffer | ||
*/ | ||
public void readTail(byte[] buf, int off, int n) throws IOException { | ||
public int readTail(byte[] buf, int off, int len) throws IOException { | ||
Check failure on line 102 in hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3ASeekableStream.java ASF Cloudbees Jenkins ci-hadoop / Apache Yetushadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3ASeekableStream.java#L102
Check failure on line 102 in hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3ASeekableStream.java ASF Cloudbees Jenkins ci-hadoop / Apache Yetushadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3ASeekableStream.java#L102
|
||
throwIfClosed(); | ||
inputStream.readTail(buf, off, n); | ||
int bytesRead; | ||
try { | ||
bytesRead = inputStream.readTail(buf, off, len); | ||
} catch (IOException ioe) { | ||
onReadFailure(ioe); | ||
throw ioe; | ||
} | ||
return bytesRead; | ||
} | ||
|
||
@Override | ||
public int read(byte[] buf, int off, int len) throws IOException { | ||
throwIfClosed(); | ||
return inputStream.read(buf, off, len); | ||
int bytesRead; | ||
try { | ||
bytesRead = inputStream.read(buf, off, len); | ||
} catch (IOException ioe) { | ||
onReadFailure(ioe); | ||
throw ioe; | ||
} | ||
return bytesRead; | ||
} | ||
|
||
|
||
|
@@ -118,12 +139,37 @@ public int available() throws IOException { | |
@Override | ||
public void close() throws IOException { | ||
if (inputStream != null) { | ||
inputStream.close(); | ||
inputStream = null; | ||
super.close(); | ||
try { | ||
inputStream.close(); | ||
inputStream = null; | ||
super.close(); | ||
} catch (IOException ioe) { | ||
LOG.debug("Failure closing stream {}: ", key); | ||
throw ioe; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Close the stream on read failure. | ||
* No attempt to recover from failure | ||
* @param ioe exception caught. | ||
*/ | ||
@Retries.OnceTranslated | ||
private void onReadFailure(IOException ioe) throws IOException { | ||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Got exception while trying to read from stream {}, " + | ||
"not trying to recover:", | ||
key, ioe); | ||
} else { | ||
LOG.info("Got exception while trying to read from stream {}, " + | ||
"not trying to recover:", | ||
key, ioe); | ||
} | ||
this.close(); | ||
} | ||
|
||
|
||
protected void throwIfClosed() throws IOException { | ||
if (isClosed()) { | ||
throw new IOException(key + ": " + FSExceptionMessages.STREAM_IS_CLOSED); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters