-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Revert gcsio 3 upgrades #38583
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
Revert gcsio 3 upgrades #38583
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "comment": "Modify this file in a trivial way to cause this test suite to run.", | ||
| "modification": 2 | ||
| "modification": 1 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "comment": "Modify this file in a trivial way to cause this test suite to run.", | ||
| "modification": 2 | ||
| "modification": 1 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "comment": "Modify this file in a trivial way to cause this test suite to run ", | ||
| "modification": 3 | ||
| "modification": 2 | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |||||||||||||||||||
| import com.google.api.client.http.HttpHeaders; | ||||||||||||||||||||
| import com.google.api.client.http.HttpRequestInitializer; | ||||||||||||||||||||
| import com.google.api.client.http.HttpStatusCodes; | ||||||||||||||||||||
| import com.google.api.client.http.HttpTransport; | ||||||||||||||||||||
| import com.google.api.client.util.BackOff; | ||||||||||||||||||||
| import com.google.api.client.util.Sleeper; | ||||||||||||||||||||
| import com.google.api.services.storage.Storage; | ||||||||||||||||||||
|
|
@@ -52,6 +53,7 @@ | |||||||||||||||||||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||||||||||||||||||||
| import java.io.FileNotFoundException; | ||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||
| import java.lang.reflect.Method; | ||||||||||||||||||||
| import java.nio.channels.SeekableByteChannel; | ||||||||||||||||||||
| import java.nio.channels.WritableByteChannel; | ||||||||||||||||||||
| import java.nio.file.AccessDeniedException; | ||||||||||||||||||||
|
|
@@ -265,12 +267,8 @@ public boolean shouldRetry(IOException e) { | |||||||||||||||||||
| .setReadChannelOptions(gcsReadOptions) | ||||||||||||||||||||
| .setGrpcEnabled(shouldUseGrpc) | ||||||||||||||||||||
| .build(); | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| googleCloudStorage = | ||||||||||||||||||||
| createGoogleCloudStorage(googleCloudStorageOptions, storageClient, credentials); | ||||||||||||||||||||
| } catch (IOException e) { | ||||||||||||||||||||
| throw new RuntimeException(e); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| googleCloudStorage = | ||||||||||||||||||||
| createGoogleCloudStorage(googleCloudStorageOptions, storageClient, credentials); | ||||||||||||||||||||
| this.batchRequestSupplier = | ||||||||||||||||||||
| () -> { | ||||||||||||||||||||
| // Capture reference to this so that the most recent storageClient and initializer | ||||||||||||||||||||
|
|
@@ -727,16 +725,48 @@ public WritableByteChannel create(GcsPath path, CreateOptions options) throws IO | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| GoogleCloudStorage createGoogleCloudStorage( | ||||||||||||||||||||
| GoogleCloudStorageOptions options, Storage storage, Credentials credentials) | ||||||||||||||||||||
| throws IOException { | ||||||||||||||||||||
| return GoogleCloudStorageImpl.builder() | ||||||||||||||||||||
| .setOptions(options) | ||||||||||||||||||||
| .setHttpTransport(storage.getRequestFactory().getTransport()) | ||||||||||||||||||||
| .setCredentials(credentials) | ||||||||||||||||||||
| // gcsio 3 expects httpRequestInitializer to be either absent or | ||||||||||||||||||||
| // com.google.cloud.hadoop.util.RetryHttpInitializer when credentials not provided | ||||||||||||||||||||
| .setHttpRequestInitializer(credentials != null ? httpRequestInitializer : null) | ||||||||||||||||||||
| .build(); | ||||||||||||||||||||
| GoogleCloudStorageOptions options, Storage storage, Credentials credentials) { | ||||||||||||||||||||
|
Comment on lines
727
to
+728
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The GoogleCloudStorage createGoogleCloudStorage(
GoogleCloudStorageOptions options, Storage storage, Credentials credentials)
throws IOException { |
||||||||||||||||||||
| try { | ||||||||||||||||||||
| return new GoogleCloudStorageImpl(options, storage, credentials); | ||||||||||||||||||||
| } catch (NoSuchMethodError e) { | ||||||||||||||||||||
| // gcs-connector 3.x drops the direct constructor and exclusively uses Builder | ||||||||||||||||||||
| // TODO eliminate reflection once Beam drops Java 8 support and upgrades to gcsio 3.x | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| final Method builderMethod = GoogleCloudStorageImpl.class.getMethod("builder"); | ||||||||||||||||||||
| Object builder = builderMethod.invoke(null); | ||||||||||||||||||||
| final Class<?> builderClass = | ||||||||||||||||||||
| Class.forName( | ||||||||||||||||||||
| "com.google.cloud.hadoop.gcsio.AutoBuilder_GoogleCloudStorageImpl_Builder"); | ||||||||||||||||||||
|
Comment on lines
+737
to
+739
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding the internal
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| final Method setOptionsMethod = | ||||||||||||||||||||
| builderClass.getMethod("setOptions", GoogleCloudStorageOptions.class); | ||||||||||||||||||||
| setOptionsMethod.setAccessible(true); | ||||||||||||||||||||
| builder = setOptionsMethod.invoke(builder, options); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| final Method setHttpTransportMethod = | ||||||||||||||||||||
| builderClass.getMethod("setHttpTransport", HttpTransport.class); | ||||||||||||||||||||
| setHttpTransportMethod.setAccessible(true); | ||||||||||||||||||||
| builder = | ||||||||||||||||||||
| setHttpTransportMethod.invoke(builder, storage.getRequestFactory().getTransport()); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| final Method setCredentialsMethod = | ||||||||||||||||||||
| builderClass.getMethod("setCredentials", Credentials.class); | ||||||||||||||||||||
| setCredentialsMethod.setAccessible(true); | ||||||||||||||||||||
| builder = setCredentialsMethod.invoke(builder, credentials); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| final Method setHttpRequestInitializerMethod = | ||||||||||||||||||||
| builderClass.getMethod("setHttpRequestInitializer", HttpRequestInitializer.class); | ||||||||||||||||||||
| setHttpRequestInitializerMethod.setAccessible(true); | ||||||||||||||||||||
| builder = setHttpRequestInitializerMethod.invoke(builder, httpRequestInitializer); | ||||||||||||||||||||
|
Comment on lines
+757
to
+760
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reflection logic for
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| final Method buildMethod = builderClass.getMethod("build"); | ||||||||||||||||||||
| buildMethod.setAccessible(true); | ||||||||||||||||||||
| return (GoogleCloudStorage) buildMethod.invoke(builder); | ||||||||||||||||||||
| } catch (Exception reflectionError) { | ||||||||||||||||||||
| throw new RuntimeException( | ||||||||||||||||||||
| "Failed to construct GoogleCloudStorageImpl from gcsio 3.x Builder", reflectionError); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |||||
|
|
||||||
| import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument; | ||||||
| import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkNotNull; | ||||||
| import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Sets.newHashSet; | ||||||
| import static org.apache.hadoop.util.Sets.newHashSet; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beam prefers using its vendored Guava dependencies (
Suggested change
|
||||||
|
|
||||||
| import com.google.auto.value.AutoValue; | ||||||
| import java.io.Serializable; | ||||||
|
|
||||||
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.
The
createGoogleCloudStoragemethod still needs to handle or declareIOExceptionbecause theGoogleCloudStorageImplconstructor ingcsio2.x throws it. The try-catch block should be restored here to maintain proper error handling and ensure the code compiles.