Skip to content

Commit

Permalink
Update http-nio and wire its new settings (#8611)
Browse files Browse the repository at this point in the history
* Update http-nio and wire it so it's configured at startup along with GCS setttings.
  • Loading branch information
lbergelson authored Dec 9, 2023
1 parent e2c5fab commit 3b8b5bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ dependencies {
implementation 'org.broadinstitute:gatk-bwamem-jni:1.0.4'
implementation 'org.broadinstitute:gatk-fermilite-jni:1.2.0'

implementation 'org.broadinstitute:http-nio:0.1.0-rc1'
implementation 'org.broadinstitute:http-nio:1.0.0'

// Required for COSMIC Funcotator data source:
implementation 'org.xerial:sqlite-jdbc:3.44.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@
import org.broadinstitute.hellbender.utils.Utils;
import org.broadinstitute.hellbender.utils.io.IOUtils;
import org.broadinstitute.http.nio.HttpFileSystemProvider;
import org.broadinstitute.http.nio.HttpFileSystemProviderSettings;
import org.broadinstitute.http.nio.HttpsFileSystemProvider;
import com.google.api.gax.retrying.RetrySettings;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.http.HttpTransportOptions;
import org.broadinstitute.http.nio.RetryHandler;
import org.threeten.bp.Duration;

import java.io.*;
import java.net.URL;
import java.nio.channels.SeekableByteChannel;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.UUID;
Expand All @@ -55,6 +54,7 @@ public final class BucketUtils {

// slashes omitted since hdfs paths seem to only have 1 slash which would be weirder to include than no slashes
public static final String FILE_PREFIX = "file:";
public static final int MAX_TIMEOUT = 120000;

private BucketUtils(){} //private so that no one will instantiate this class

Expand Down Expand Up @@ -387,14 +387,33 @@ public static String getPathWithoutBucket(String path) {
* Sets max_reopens, requester_pays, and generous timeouts as the global default.
* These will apply even to library code that creates its own paths to access with NIO.
*
* @param maxReopens If the GCS bucket channel errors out, how many times it will attempt to
* @param maxReopens If the channel errors out, how many times it will attempt to
* re-initiate the connection.
* @param requesterProject Project to bill when accessing "requester pays" buckets. If unset,
* these buckets cannot be accessed.
*/
public static void setGlobalNIODefaultOptions(int maxReopens, String requesterProject) {
CloudStorageFileSystemProvider.setDefaultCloudStorageConfiguration(getCloudStorageConfiguration(maxReopens, requesterProject));
CloudStorageFileSystemProvider.setStorageOptions(setGenerousTimeouts(StorageOptions.newBuilder()).build());
setGlobalHttpNioDefaultOptions(maxReopens);
}

/**
* Set the options for http-nio to have generous timeouts and defaults
*/
public static void setGlobalHttpNioDefaultOptions(final int maxRetries) {
final HttpFileSystemProviderSettings.RetrySettings retrySettings = new HttpFileSystemProviderSettings.RetrySettings(
maxRetries,
RetryHandler.DEFAULT_RETRYABLE_HTTP_CODES,
RetryHandler.DEFAULT_RETRYABLE_EXCEPTIONS,
RetryHandler.DEFALT_RETRYABLE_MESSAGES,
e -> false);
final HttpFileSystemProviderSettings settings = new HttpFileSystemProviderSettings(
java.time.Duration.ofMillis(MAX_TIMEOUT),
HttpFileSystemProviderSettings.DEFAULT_SETTINGS.redirect(),
retrySettings);

HttpFileSystemProvider.setSettings(settings);
}

/**
Expand Down Expand Up @@ -437,8 +456,8 @@ public static CloudStorageConfiguration getCloudStorageConfiguration(int maxReop
private static StorageOptions.Builder setGenerousTimeouts(StorageOptions.Builder builder) {
return builder
.setTransportOptions(HttpTransportOptions.newBuilder()
.setConnectTimeout(120000)
.setReadTimeout(120000)
.setConnectTimeout(MAX_TIMEOUT)
.setReadTimeout(MAX_TIMEOUT)
.build())
.setRetrySettings(RetrySettings.newBuilder()
.setMaxAttempts(15)
Expand Down

0 comments on commit 3b8b5bf

Please sign in to comment.