-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-17475. ABFS: Implementing ListStatusRemoteIterator #2548
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f00cd4e
Implementing ListStatusRemoteIterator
bilaharith baeceb0
Added test cases. Improved ListIteraor logic.
bilaharith 13ddf52
Making the server calls as a background activity
bilaharith fc40333
Making the async call exit if the queue is full. Adding more test cases.
bilaharith 9c54033
Merge branch 'trunk' into lsitr
bilaharith 83ec324
Addressing review comments
bilaharith a6e5407
Putting empty iterator in finally block. This is to prevent the take …
bilaharith b9ff82c
Throwing FileNotFoundException when the directory does not exist
bilaharith f2b3ad4
Making the put on finally non blocking
bilaharith d3cac77
Adding empty iterator from the catch block
bilaharith 7c4f64a
Addressing review comments
bilaharith f578bbd
Addressing review comments
bilaharith 89222d1
Addressing review comments
bilaharith 5970d6e
Adressing review comments. Checkstyle fixes.
bilaharith 9b8053c
Addressing review comments
bilaharith 919245d
To ignore the findbug warning related to continuation
bilaharith 51bd08a
Fixing javadoc issues
bilaharith b01659a
findbugs fix
bilaharith 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
151 changes: 151 additions & 0 deletions
151
...re/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsListStatusRemoteIterator.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,151 @@ | ||
| /** | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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 java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.NoSuchElementException; | ||
| import java.util.concurrent.ArrayBlockingQueue; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import org.apache.hadoop.fs.FileStatus; | ||
| import org.apache.hadoop.fs.RemoteIterator; | ||
|
|
||
| public class AbfsListStatusRemoteIterator implements RemoteIterator<FileStatus> { | ||
|
|
||
| private static final Logger LOG = LoggerFactory | ||
| .getLogger(AbfsListStatusRemoteIterator.class); | ||
|
|
||
| private static final boolean FETCH_ALL_FALSE = false; | ||
| private static final int MAX_QUEUE_SIZE = 10; | ||
|
|
||
| private final FileStatus fileStatus; | ||
| private final ListingSupport listingSupport; | ||
| private final ArrayBlockingQueue<Iterator<FileStatus>> iteratorsQueue; | ||
| private final Object asyncOpLock = new Object(); | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private volatile boolean isAsyncInProgress = false; | ||
| private boolean firstBatch = true; | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private String continuation; | ||
| private Iterator<FileStatus> currIterator; | ||
| private IOException ioException; | ||
|
|
||
| public AbfsListStatusRemoteIterator(final FileStatus fileStatus, | ||
| final ListingSupport listingSupport) { | ||
| this.fileStatus = fileStatus; | ||
| this.listingSupport = listingSupport; | ||
| iteratorsQueue = new ArrayBlockingQueue<>(MAX_QUEUE_SIZE); | ||
| currIterator = Collections.emptyIterator(); | ||
| fetchBatchesAsync(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean hasNext() throws IOException { | ||
| if (currIterator.hasNext()) { | ||
| return true; | ||
| } | ||
| updateCurrentIterator(); | ||
| return currIterator.hasNext(); | ||
| } | ||
|
|
||
| @Override | ||
| public FileStatus next() throws IOException { | ||
| if (!this.hasNext()) { | ||
| throw new NoSuchElementException(); | ||
| } | ||
| return currIterator.next(); | ||
| } | ||
|
|
||
| private void updateCurrentIterator() throws IOException { | ||
| fetchBatchesAsync(); | ||
| synchronized (this) { | ||
| if (iteratorsQueue.isEmpty()) { | ||
| if (ioException != null) { | ||
| throw ioException; | ||
| } | ||
| if (isListingComplete()) { | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| try { | ||
| currIterator = iteratorsQueue.take(); | ||
| if (!currIterator.hasNext() && !isListingComplete()) { | ||
| updateCurrentIterator(); | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| LOG.error("Thread got interrupted: {}", e); | ||
| } | ||
| } | ||
|
|
||
| private synchronized boolean isListingComplete() { | ||
| return !firstBatch && (continuation == null || continuation.isEmpty()); | ||
| } | ||
|
|
||
| private void fetchBatchesAsync() { | ||
| if (isAsyncInProgress) { | ||
bilaharith marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
| synchronized (asyncOpLock) { | ||
| if (isAsyncInProgress) { | ||
| return; | ||
| } | ||
| isAsyncInProgress = true; | ||
| } | ||
| CompletableFuture.runAsync(() -> asyncOp()); | ||
| } | ||
|
|
||
| private void asyncOp() { | ||
| try { | ||
| while (!isListingComplete() && iteratorsQueue.size() <= MAX_QUEUE_SIZE) { | ||
| addNextBatchIteratorToQueue(); | ||
| } | ||
| } catch (IOException e) { | ||
| ioException = e; | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| iteratorsQueue.offer(Collections.emptyIterator()); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| LOG.error("Thread got interrupted: {}", e); | ||
| } finally { | ||
| synchronized (asyncOpLock) { | ||
| isAsyncInProgress = false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private synchronized void addNextBatchIteratorToQueue() | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| throws IOException, InterruptedException { | ||
| List<FileStatus> fileStatuses = new ArrayList<>(); | ||
| continuation = listingSupport | ||
| .listStatus(fileStatus.getPath(), null, fileStatuses, FETCH_ALL_FALSE, | ||
| continuation); | ||
| iteratorsQueue.put(fileStatuses.iterator()); | ||
| if (firstBatch) { | ||
| firstBatch = false; | ||
| } | ||
| } | ||
|
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.