-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HADOOP-19613. [ABFS][ReadAheadV2] Refactor ReadBufferManager to isolate new code with the current working code #7801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fa214ea
c1a6fd0
fc9324d
ccae40d
99fb6a9
643d30c
0bfbfb9
3dda35d
727bd51
9ce4f81
2019935
5b93b32
7000ead
14c5b2e
0c64849
108dc08
e9ad12a
92dfbda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ public class AbfsInputStream extends FSInputStream implements CanUnbuffer, | |
private final String eTag; // eTag of the path when InputStream are created | ||
private final boolean tolerateOobAppends; // whether tolerate Oob Appends | ||
private final boolean readAheadEnabled; // whether enable readAhead; | ||
private final boolean readAheadV2Enabled; // whether enable readAhead V2; | ||
private final String inputStreamId; | ||
private final boolean alwaysReadBufferSize; | ||
/* | ||
|
@@ -130,6 +131,7 @@ public class AbfsInputStream extends FSInputStream implements CanUnbuffer, | |
|
||
/** ABFS instance to be held by the input stream to avoid GC close. */ | ||
private final BackReference fsBackRef; | ||
private ReadBufferManager readBufferManager; | ||
|
||
public AbfsInputStream( | ||
final AbfsClient client, | ||
|
@@ -150,6 +152,7 @@ public AbfsInputStream( | |
this.eTag = eTag; | ||
this.readAheadRange = abfsInputStreamContext.getReadAheadRange(); | ||
this.readAheadEnabled = abfsInputStreamContext.isReadAheadEnabled(); | ||
this.readAheadV2Enabled = abfsInputStreamContext.isReadAheadV2Enabled(); | ||
this.alwaysReadBufferSize | ||
= abfsInputStreamContext.shouldReadBufferSizeAlways(); | ||
this.bufferedPreadDisabled = abfsInputStreamContext | ||
|
@@ -173,9 +176,19 @@ public AbfsInputStream( | |
this.fsBackRef = abfsInputStreamContext.getFsBackRef(); | ||
contextEncryptionAdapter = abfsInputStreamContext.getEncryptionAdapter(); | ||
|
||
// Propagate the config values to ReadBufferManager so that the first instance | ||
// to initialize can set the readAheadBlockSize | ||
ReadBufferManager.setReadBufferManagerConfigs(readAheadBlockSize); | ||
/* | ||
* Initialize the ReadBufferManager based on whether readAheadV2 is enabled or not. | ||
* Precedence is given to ReadBufferManagerV2. | ||
* If none of the V1 and V2 are enabled, then no read ahead will be done. | ||
*/ | ||
if (readAheadV2Enabled) { | ||
ReadBufferManagerV2.setReadBufferManagerConfigs( | ||
readAheadBlockSize, client.getAbfsConfiguration()); | ||
readBufferManager = ReadBufferManagerV2.getBufferManager(); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be under else if (readAheadEnabled) instead of else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We always had RBM initlialised today. |
||
ReadBufferManagerV1.setReadBufferManagerConfigs(readAheadBlockSize); | ||
readBufferManager = ReadBufferManagerV1.getBufferManager(); | ||
} | ||
if (streamStatistics != null) { | ||
ioStatistics = streamStatistics.getIOStatistics(); | ||
} | ||
|
@@ -491,7 +504,7 @@ private int copyToUserBuffer(byte[] b, int off, int len){ | |
|
||
private int readInternal(final long position, final byte[] b, final int offset, final int length, | ||
final boolean bypassReadAhead) throws IOException { | ||
if (readAheadEnabled && !bypassReadAhead) { | ||
if (isReadAheadEnabled() && !bypassReadAhead) { | ||
// try reading from read-ahead | ||
if (offset != 0) { | ||
throw new IllegalArgumentException("readahead buffers cannot have non-zero buffer offsets"); | ||
|
@@ -510,7 +523,7 @@ private int readInternal(final long position, final byte[] b, final int offset, | |
while (numReadAheads > 0 && nextOffset < contentLength) { | ||
LOG.debug("issuing read ahead requestedOffset = {} requested size {}", | ||
nextOffset, nextSize); | ||
ReadBufferManager.getBufferManager().queueReadAhead(this, nextOffset, (int) nextSize, | ||
readBufferManager.queueReadAhead(this, nextOffset, (int) nextSize, | ||
new TracingContext(readAheadTracingContext)); | ||
nextOffset = nextOffset + nextSize; | ||
numReadAheads--; | ||
|
@@ -519,7 +532,7 @@ private int readInternal(final long position, final byte[] b, final int offset, | |
} | ||
|
||
// try reading from buffers first | ||
receivedBytes = ReadBufferManager.getBufferManager().getBlock(this, position, length, b); | ||
receivedBytes = readBufferManager.getBlock(this, position, length, b); | ||
bytesFromReadAhead += receivedBytes; | ||
if (receivedBytes > 0) { | ||
incrementReadOps(); | ||
|
@@ -720,7 +733,9 @@ public boolean seekToNewSource(long l) throws IOException { | |
public synchronized void close() throws IOException { | ||
LOG.debug("Closing {}", this); | ||
closed = true; | ||
ReadBufferManager.getBufferManager().purgeBuffersForStream(this); | ||
if (readBufferManager != null) { | ||
readBufferManager.purgeBuffersForStream(this); | ||
} | ||
buffer = null; // de-reference the buffer so it can be GC'ed sooner | ||
if (contextEncryptionAdapter != null) { | ||
contextEncryptionAdapter.destroy(); | ||
|
@@ -773,9 +788,14 @@ byte[] getBuffer() { | |
return buffer; | ||
} | ||
|
||
/** | ||
* Checks if any version of read ahead is enabled. | ||
* If both are disabled, then skip read ahead logic. | ||
* @return true if read ahead is enabled, false otherwise. | ||
*/ | ||
@VisibleForTesting | ||
public boolean isReadAheadEnabled() { | ||
return readAheadEnabled; | ||
return (readAheadEnabled || readAheadV2Enabled) && readBufferManager != null; | ||
anujmodi2021 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@VisibleForTesting | ||
|
Uh oh!
There was an error while loading. Please reload this page.