-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-19767: [ABFS] Introduce Abfs Input Policy for detecting read patterns #8153
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
Open
anujmodi2021
wants to merge
9
commits into
apache:trunk
Choose a base branch
from
ABFSDriver:abfsInputRefact
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bb27ec4
input stream refraction
anujmodi2021 16253aa
RandomIS
anujmodi2021 68f905c
Configuration
anujmodi2021 bb42e3c
Added Tests
anujmodi2021 94d2336
PR Checks
anujmodi2021 46b3e18
Checkstyle
anujmodi2021 3560cc5
RBM Improvements
anujmodi2021 f3b6b57
javadoc erorr
anujmodi2021 c53a82f
Addressed Comments
anujmodi2021 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
117 changes: 117 additions & 0 deletions
117
...p-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsAdaptiveInputStream.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.fs.azurebfs.services; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.azurebfs.constants.ReadType; | ||
| import org.apache.hadoop.fs.azurebfs.utils.TracingContext; | ||
|
|
||
| /** | ||
| * Input stream implementation optimized for adaptive read patterns. | ||
| * This is the default implementation used for cases where user does not specify any input policy. | ||
| * It switches between sequential and random read optimizations based on the detected read pattern. | ||
| * It also keeps footer read and small file optimizations enabled. | ||
| */ | ||
| public class AbfsAdaptiveInputStream extends AbfsInputStream { | ||
|
|
||
| /** | ||
| * Constructs AbfsAdaptiveInputStream instance. | ||
| * @param client to be used for read operations | ||
| * @param statistics to record input stream statistics | ||
| * @param path file path | ||
| * @param contentLength file content length | ||
| * @param abfsInputStreamContext input stream context | ||
| * @param eTag file eTag | ||
| * @param tracingContext tracing context to trace the read operations | ||
| */ | ||
| public AbfsAdaptiveInputStream( | ||
| final AbfsClient client, | ||
| final FileSystem.Statistics statistics, | ||
| final String path, | ||
| final long contentLength, | ||
| final AbfsInputStreamContext abfsInputStreamContext, | ||
| final String eTag, | ||
| TracingContext tracingContext) { | ||
| super(client, statistics, path, contentLength, | ||
| abfsInputStreamContext, eTag, tracingContext); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| protected int readOneBlock(final byte[] b, final int off, final int len) throws IOException { | ||
| if (len == 0) { | ||
| return 0; | ||
| } | ||
| if (!validate(b, off, len)) { | ||
| return -1; | ||
| } | ||
| // If buffer is empty, then fill the buffer. | ||
| if (getBCursor() == getLimit()) { | ||
| // If EOF, then return -1 | ||
| if (getFCursor() >= getContentLength()) { | ||
| return -1; | ||
| } | ||
|
|
||
| long bytesRead = 0; | ||
| // reset buffer to initial state - i.e., throw away existing data | ||
| setBCursor(0); | ||
| setLimit(0); | ||
| if (getBuffer() == null) { | ||
| LOG.debug("created new buffer size {}", getBufferSize()); | ||
| setBuffer(new byte[getBufferSize()]); | ||
| } | ||
|
|
||
| // Reset Read Type back to normal and set again based on code flow. | ||
| getTracingContext().setReadType(ReadType.NORMAL_READ); | ||
| if (shouldAlwaysReadBufferSize()) { | ||
| bytesRead = readInternal(getFCursor(), getBuffer(), 0, getBufferSize(), false); | ||
| } else { | ||
| // Enable readAhead when reading sequentially | ||
| if (-1 == getFCursorAfterLastRead() || getFCursorAfterLastRead() == getFCursor() || b.length >= getBufferSize()) { | ||
| LOG.debug("Sequential read with read ahead size of {}", getBufferSize()); | ||
| bytesRead = readInternal(getFCursor(), getBuffer(), 0, getBufferSize(), false); | ||
| } else { | ||
| /* | ||
| * Disable queuing prefetches when random read pattern detected. | ||
| * Instead, read ahead only for readAheadRange above what is asked by caller. | ||
| */ | ||
| getTracingContext().setReadType(ReadType.RANDOM_READ); | ||
| int lengthWithReadAhead = Math.min(b.length + getReadAheadRange(), getBufferSize()); | ||
| LOG.debug("Random read with read ahead size of {}", lengthWithReadAhead); | ||
| bytesRead = readInternal(getFCursor(), getBuffer(), 0, lengthWithReadAhead, true); | ||
| } | ||
| } | ||
| if (isFirstRead()) { | ||
| setFirstRead(false); | ||
| } | ||
| if (bytesRead == -1) { | ||
| return -1; | ||
| } | ||
|
|
||
| setLimit(getLimit() + (int) bytesRead); | ||
| setFCursor(getFCursor() + bytesRead); | ||
| setFCursorAfterLastRead(getFCursor()); | ||
| } | ||
| return copyToUserBuffer(b, off, len); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: needs javadoc comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added