Created
April 18, 2013 18:31
-
-
Save stephenh/5415089 to your computer and use it in GitHub Desktop.
retries
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
public synchronized int read() throws IOException { | |
int result = in.read(); | |
if (result != -1) { | |
pos++; | |
} | |
return result; | |
} |
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
public synchronized int read() throws IOException | |
{ | |
int result = -1; | |
try { | |
result = this.pair.in.read(); | |
} catch (IOException e) { | |
NativeS3FileSystem.LOG.info("Received IOException while reading '" + this.pair.key + "', attempting to reopen."); | |
seek(this.pos); | |
result = this.pair.in.read(); | |
} | |
if (result == -1) { | |
int numRetries = 5; | |
if ((this.pair.contentLength != -1L) && (this.pos != this.pair.contentLength)) { | |
NativeS3FileSystem.LOG.info("Unexpected end of stream in read() while reading from stream pos=" + this.pos + ", contentLength=" + this.pair.contentLength); | |
NativeS3FileSystem.LOG.info("result=" + result + " and numRetries=" + numRetries); | |
while ((result <= 0) && (numRetries > 0)) { | |
NativeS3FileSystem.LOG.info("Retry reading from stream " + this.pos + ", contentLength=" + this.pair.contentLength); | |
seek(this.pos); | |
result = this.pair.in.read(); | |
--numRetries; | |
} | |
if (result <= 0) { | |
NativeS3FileSystem.LOG.error("Unable to recover reading from stream"); | |
throw new IOException("Unexpected end of stream pos=" + this.pos + " contentLength= " + this.pair.contentLength); | |
} | |
} | |
} | |
if (result > 0) { | |
advance(result); | |
} | |
return result; | |
} |
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
@Override | |
public synchronized int read(byte[] b, int off, int len) | |
throws IOException { | |
int result = -1; | |
try { | |
result = in.read(b, off, len); | |
} catch (IOException e) { | |
LOG.info("Received IOException while reading '" + key + "', attempting to reopen."); | |
seek(pos); | |
result = in.read(b, off, len); | |
} | |
if (result > 0) { | |
pos += result; | |
} | |
if (statistics != null && result > 0) { | |
statistics.incrementBytesRead(result); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment