Skip to content

HADOOP-16202 Enhance S3A openFile() #2046

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

Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
*/
B opt(@Nonnull String key, float value);

/**
* Set optional long parameter for the Builder.
*
* @see #opt(String, String)
*/
B opt(@Nonnull String key, long value);

/**
* Set optional double parameter for the Builder.
*
Expand Down Expand Up @@ -104,6 +111,13 @@ public interface FSBuilder<S, B extends FSBuilder<S, B>> {
*/
B must(@Nonnull String key, float value);

/**
* Set mandatory long option.
*
* @see #must(String, String)
*/
B must(@Nonnull String key, long value);

/**
* Set mandatory double option.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2926,6 +2926,7 @@ public CompletableFuture<FSDataInputStream> build() throws IOException {
final Path absF = fixRelativePart(getPath());
OpenFileParameters parameters = new OpenFileParameters()
.withMandatoryKeys(getMandatoryKeys())
.withOptionalKeys(getOptionalKeys())
.withOptions(getOptions())
.withBufferSize(getBufferSize())
.withStatus(getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4536,7 +4536,7 @@ protected CompletableFuture<FSDataInputStream> openFileWithOptions(
final OpenFileParameters parameters) throws IOException {
AbstractFSBuilderImpl.rejectUnknownMandatoryKeys(
parameters.getMandatoryKeys(),
Collections.emptySet(), "");
OpenFileParameters.STANDARD_OPTIONS, "");
CompletableFuture<FSDataInputStream> result = new CompletableFuture<>();
try {
result.complete(open(pathHandle, parameters.getBufferSize()));
Expand Down Expand Up @@ -4643,6 +4643,7 @@ public CompletableFuture<FSDataInputStream> build() throws IOException {
Optional<Path> optionalPath = getOptionalPath();
OpenFileParameters parameters = new OpenFileParameters()
.withMandatoryKeys(getMandatoryKeys())
.withOptionalKeys(getOptionalKeys())
.withOptions(getOptions())
.withBufferSize(getBufferSize())
.withStatus(super.getStatus()); // explicit to avoid IDE warnings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@
/**
* Builder for filesystem/filecontext operations of various kinds,
* with option support.
*
* <code>
* <p></p>
* <pre>
* .opt("foofs:option.a", true)
* .opt("foofs:option.b", "value")
* .opt("barfs:cache", true)
* .opt("fs.s3a.open.option.etag", "9fe4c37c25b")
* .must("foofs:cache", true)
* .must("barfs:cache-size", 256 * 1024 * 1024)
* .build();
* </code>
* </pre>
* <p></p>
*
* Configuration keys declared in an {@code opt()} may be ignored by
* a builder which does not recognise them.
* <p></p>
*
* Configuration keys declared in a {@code must()} function set must
* be understood by the implementation or a
Expand Down Expand Up @@ -88,6 +90,9 @@
/** Keep track of the keys for mandatory options. */
private final Set<String> mandatoryKeys = new HashSet<>();

/** Keep track of the optional keys. */
private final Set<String> optionalKeys = new HashSet<>();

/**
* Constructor with both optional path and path handle.
* Either or both argument may be empty, but it is an error for
Expand Down Expand Up @@ -163,6 +168,7 @@ public PathHandle getPathHandle() {
@Override
public B opt(@Nonnull final String key, @Nonnull final String value) {
mandatoryKeys.remove(key);
optionalKeys.add(key);
options.set(key, value);
return getThisBuilder();
}
Expand All @@ -175,6 +181,7 @@ public B opt(@Nonnull final String key, @Nonnull final String value) {
@Override
public B opt(@Nonnull final String key, boolean value) {
mandatoryKeys.remove(key);
optionalKeys.add(key);
options.setBoolean(key, value);
return getThisBuilder();
}
Expand All @@ -187,10 +194,19 @@ public B opt(@Nonnull final String key, boolean value) {
@Override
public B opt(@Nonnull final String key, int value) {
mandatoryKeys.remove(key);
optionalKeys.add(key);
options.setInt(key, value);
return getThisBuilder();
}

@Override
public B opt(@Nonnull final String key, final long value) {
mandatoryKeys.remove(key);
optionalKeys.add(key);
options.setLong(key, value);
return getThisBuilder();
}

/**
* Set optional float parameter for the Builder.
*
Expand All @@ -199,6 +215,7 @@ public B opt(@Nonnull final String key, int value) {
@Override
public B opt(@Nonnull final String key, float value) {
mandatoryKeys.remove(key);
optionalKeys.add(key);
options.setFloat(key, value);
return getThisBuilder();
}
Expand All @@ -211,6 +228,7 @@ public B opt(@Nonnull final String key, float value) {
@Override
public B opt(@Nonnull final String key, double value) {
mandatoryKeys.remove(key);
optionalKeys.add(key);
options.setDouble(key, value);
return getThisBuilder();
}
Expand All @@ -223,6 +241,7 @@ public B opt(@Nonnull final String key, double value) {
@Override
public B opt(@Nonnull final String key, @Nonnull final String... values) {
mandatoryKeys.remove(key);
optionalKeys.add(key);
options.setStrings(key, values);
return getThisBuilder();
}
Expand All @@ -248,6 +267,7 @@ public B must(@Nonnull final String key, @Nonnull final String value) {
@Override
public B must(@Nonnull final String key, boolean value) {
mandatoryKeys.add(key);
optionalKeys.remove(key);
options.setBoolean(key, value);
return getThisBuilder();
}
Expand All @@ -260,10 +280,19 @@ public B must(@Nonnull final String key, boolean value) {
@Override
public B must(@Nonnull final String key, int value) {
mandatoryKeys.add(key);
optionalKeys.remove(key);
options.setInt(key, value);
return getThisBuilder();
}

@Override
public B must(@Nonnull final String key, final long value) {
mandatoryKeys.add(key);
optionalKeys.remove(key);
options.setLong(key, value);
return getThisBuilder();
}

/**
* Set mandatory float option.
*
Expand All @@ -272,6 +301,7 @@ public B must(@Nonnull final String key, int value) {
@Override
public B must(@Nonnull final String key, float value) {
mandatoryKeys.add(key);
optionalKeys.remove(key);
options.setFloat(key, value);
return getThisBuilder();
}
Expand All @@ -284,6 +314,7 @@ public B must(@Nonnull final String key, float value) {
@Override
public B must(@Nonnull final String key, double value) {
mandatoryKeys.add(key);
optionalKeys.remove(key);
options.setDouble(key, value);
return getThisBuilder();
}
Expand All @@ -296,6 +327,7 @@ public B must(@Nonnull final String key, double value) {
@Override
public B must(@Nonnull final String key, @Nonnull final String... values) {
mandatoryKeys.add(key);
optionalKeys.remove(key);
options.setStrings(key, values);
return getThisBuilder();
}
Expand All @@ -314,6 +346,12 @@ public Configuration getOptions() {
public Set<String> getMandatoryKeys() {
return Collections.unmodifiableSet(mandatoryKeys);
}
/**
* Get all the keys that are set as optional keys.
*/
public Set<String> getOptionalKeys() {
return Collections.unmodifiableSet(optionalKeys);
}

/**
* Reject a configuration if one or more mandatory keys are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public FutureDataInputStreamBuilder getThisBuilder() {

@Override
public FutureDataInputStreamBuilder withFileStatus(FileStatus st) {
this.status = requireNonNull(st, "status");
this.status = st;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.apache.hadoop.fs.impl;

import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
Expand All @@ -38,6 +40,9 @@ public class OpenFileParameters {
*/
private Set<String> mandatoryKeys;

/** The optional keys. */
private Set<String> optionalKeys;

/**
* Options set during the build sequence.
*/
Expand All @@ -61,6 +66,11 @@ public OpenFileParameters withMandatoryKeys(final Set<String> keys) {
return this;
}

public OpenFileParameters withOptionalKeys(final Set<String> keys) {
this.optionalKeys = requireNonNull(keys);
return this;
}

public OpenFileParameters withOptions(final Configuration opts) {
this.options = requireNonNull(opts);
return this;
Expand All @@ -80,6 +90,10 @@ public Set<String> getMandatoryKeys() {
return mandatoryKeys;
}

public Set<String> getOptionalKeys() {
return optionalKeys;
}

public Configuration getOptions() {
return options;
}
Expand All @@ -91,4 +105,48 @@ public int getBufferSize() {
public FileStatus getStatus() {
return status;
}


/**
* OpenFile option for seek policies: {@value}.
*/
public static final String FS_OPT_OPENFILE_FADVISE =
"fs.opt.openfile.fadvise";

/**
* fadvise policy: {@value}.
*/
public static final String FS_OPT_OPENFILE_FADVISE_NORMAL = "normal";

/**
* fadvise policy: {@value}.
*/
public static final String FS_OPT_OPENFILE_FADVISE_SEQUENTIAL = "sequential";

/**
* fadvise policy: {@value}.
*/
public static final String FS_OPT_OPENFILE_FADVISE_RANDOM = "random";

/**
* fadvise policy: {@value}.
*/
public static final String FS_OPT_OPENFILE_FADVISE_ADAPTIVE = "adaptive";

/**
* OpenFile option for seek policies: {@value}.
*/
public static final String FS_OPT_OPENFILE_LENGTH =
"fs.opt.openfile.length";

/**
* Set of standard options.
*/
public static final Set<String> STANDARD_OPTIONS =
Stream.of(
FS_OPT_OPENFILE_FADVISE,
FS_OPT_OPENFILE_LENGTH)
.collect(Collectors.toSet());


}
Loading