Skip to content
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

AVRO-3594: FsInput to use openFile() API #1807

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lang/java/mapred/src/main/java/org/apache/avro/mapred/FsInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FSDataInputStream;

import org.apache.avro.file.SeekableInput;

import static org.apache.hadoop.fs.Options.OpenFileOptions.FS_OPTION_OPENFILE_READ_POLICY;
import static org.apache.hadoop.fs.Options.OpenFileOptions.FS_OPTION_OPENFILE_READ_POLICY_ADAPTIVE;
import static org.apache.hadoop.util.functional.FutureIO.awaitFuture;

/** Adapt an {@link FSDataInputStream} to {@link SeekableInput}. */
public class FsInput implements Closeable, SeekableInput {
private final FSDataInputStream stream;
Expand All @@ -40,8 +45,19 @@ public FsInput(Path path, Configuration conf) throws IOException {

/** Construct given a path and a {@code FileSystem}. */
public FsInput(Path path, FileSystem fileSystem) throws IOException {
this.len = fileSystem.getFileStatus(path).getLen();
this.stream = fileSystem.open(path);
final FileStatus st = fileSystem.getFileStatus(path);
this.len = st.getLen();
// use the hadoop 3.3.0 openFile API, pass in status
// and read policy. object stores can use these to
// optimize read performance.
// the read policy "adaptive" means "start sequential but
// go to random IO when considered better"
// Filesystems which don't recognize the options will ignore them
// Importantly deployments which have switched the default read policy to
// "random"
// will not suffer when reading large avro files.
this.stream = awaitFuture(fileSystem.openFile(path)
.opt(FS_OPTION_OPENFILE_READ_POLICY, FS_OPTION_OPENFILE_READ_POLICY_ADAPTIVE).withFileStatus(st).build());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add the same fallback code as in parquet; s3a connector in 3.3.0-3.3.4 validates the whole path, and overreacts to hive's wrapping of the fs by its own VFS; 3.3.5+ only look at the filename.

}

@Override
Expand Down