Skip to content

Commit

Permalink
fix: update StorageOptions to carry forward fields that aren't part o…
Browse files Browse the repository at this point in the history
…f ServiceOptions (#2521)
  • Loading branch information
BenWhitehead committed May 6, 2024
1 parent 67a7c6b commit b84654e
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 8 deletions.
12 changes: 12 additions & 0 deletions google-cloud-storage/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,16 @@
<className>com/google/cloud/storage/WriteFlushStrategy$DefaultBidiFlusher</className>
</difference>

<!-- BlobWriteSessionConfig is package-private extendable only, allow hashCode/equals -->
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/storage/BlobWriteSessionConfig</className>
<method>int hashCode()</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/storage/BlobWriteSessionConfig</className>
<method>boolean equals(java.lang.Object)</method>
</difference>

</differences>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.storage.v2.BidiWriteObjectResponse;
import java.io.IOException;
import java.time.Clock;
import java.util.Objects;
import javax.annotation.concurrent.Immutable;

/**
Expand Down Expand Up @@ -64,6 +65,23 @@ public int getBufferSize() {
return bufferSize;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof BidiBlobWriteSessionConfig)) {
return false;
}
BidiBlobWriteSessionConfig that = (BidiBlobWriteSessionConfig) o;
return bufferSize == that.bufferSize;
}

@Override
public int hashCode() {
return Objects.hashCode(bufferSize);
}

@Override
WriterFactory createFactory(Clock clock) throws IOException {
return new Factory(bufferSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public abstract class BlobWriteSessionConfig implements Serializable {
@InternalApi
BlobWriteSessionConfig() {}

@Override
public abstract int hashCode();

@Override
public abstract boolean equals(Object obj);

@InternalApi
abstract WriterFactory createFactory(Clock clock) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import java.util.stream.Collector;
import javax.annotation.concurrent.Immutable;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
Expand Down Expand Up @@ -81,6 +82,25 @@ public final class BufferToDiskThenUpload extends BlobWriteSessionConfig
this.includeLoggingSink = includeLoggingSink;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof BufferToDiskThenUpload)) {
return false;
}
BufferToDiskThenUpload that = (BufferToDiskThenUpload) o;
return includeLoggingSink == that.includeLoggingSink
&& Objects.equals(paths, that.paths)
&& Objects.equals(absolutePaths, that.absolutePaths);
}

@Override
public int hashCode() {
return Objects.hash(paths, includeLoggingSink, absolutePaths);
}

@VisibleForTesting
@InternalApi
BufferToDiskThenUpload withIncludeLoggingSink() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.nio.channels.WritableByteChannel;
import java.time.Clock;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;
import javax.annotation.concurrent.Immutable;

Expand Down Expand Up @@ -105,6 +106,23 @@ public DefaultBlobWriteSessionConfig withChunkSize(int chunkSize) {
return new DefaultBlobWriteSessionConfig(chunkSize);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof DefaultBlobWriteSessionConfig)) {
return false;
}
DefaultBlobWriteSessionConfig that = (DefaultBlobWriteSessionConfig) o;
return chunkSize == that.chunkSize;
}

@Override
public int hashCode() {
return Objects.hashCode(chunkSize);
}

@Override
@InternalApi
WriterFactory createFactory(Clock clock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.storage;

import com.google.api.gax.retrying.ResultRetryAlgorithm;
import com.google.common.base.MoreObjects;
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.SetIamPolicyRequest;
import com.google.iam.v1.TestIamPermissionsRequest;
Expand Down Expand Up @@ -50,11 +51,12 @@
import com.google.storage.v2.UpdateObjectRequest;
import com.google.storage.v2.WriteObjectRequest;
import java.io.Serializable;
import java.util.Objects;

final class GrpcRetryAlgorithmManager implements Serializable {

private static final long serialVersionUID = 3084833873820431477L;
private final StorageRetryStrategy retryStrategy;
final StorageRetryStrategy retryStrategy;

GrpcRetryAlgorithmManager(StorageRetryStrategy retryStrategy) {
this.retryStrategy = retryStrategy;
Expand Down Expand Up @@ -217,4 +219,26 @@ public ResultRetryAlgorithm<?> getFor(BidiWriteObjectRequest req) {
? retryStrategy.getIdempotentHandler()
: retryStrategy.getNonidempotentHandler();
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof GrpcRetryAlgorithmManager)) {
return false;
}
GrpcRetryAlgorithmManager that = (GrpcRetryAlgorithmManager) o;
return Objects.equals(retryStrategy, that.retryStrategy);
}

@Override
public int hashCode() {
return Objects.hashCode(retryStrategy);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("retryStrategy", retryStrategy).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,30 @@ public GrpcStorageOptions.Builder toBuilder() {

@Override
public int hashCode() {
return baseHashCode();
return Objects.hash(
retryAlgorithmManager,
terminationAwaitDuration,
attemptDirectPath,
grpcInterceptorProvider,
blobWriteSessionConfig,
baseHashCode());
}

@Override
public boolean equals(Object obj) {
return obj instanceof GrpcStorageOptions && baseEquals((GrpcStorageOptions) obj);
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof GrpcStorageOptions)) {
return false;
}
GrpcStorageOptions that = (GrpcStorageOptions) o;
return attemptDirectPath == that.attemptDirectPath
&& Objects.equals(retryAlgorithmManager, that.retryAlgorithmManager)
&& Objects.equals(terminationAwaitDuration, that.terminationAwaitDuration)
&& Objects.equals(grpcInterceptorProvider, that.grpcInterceptorProvider)
&& Objects.equals(blobWriteSessionConfig, that.blobWriteSessionConfig)
&& this.baseEquals(that);
}

/** @since 2.14.0 This new api is in preview and is subject to breaking changes. */
Expand Down Expand Up @@ -399,6 +417,12 @@ public static final class Builder extends StorageOptions.Builder {

Builder(StorageOptions options) {
super(options);
GrpcStorageOptions gso = (GrpcStorageOptions) options;
this.storageRetryStrategy = gso.getRetryAlgorithmManager().retryStrategy;
this.terminationAwaitDuration = gso.getTerminationAwaitDuration();
this.attemptDirectPath = gso.attemptDirectPath;
this.grpcInterceptorProvider = gso.grpcInterceptorProvider;
this.blobWriteSessionConfig = gso.blobWriteSessionConfig;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
final class HttpRetryAlgorithmManager implements Serializable {

private static final long serialVersionUID = -3301856948991518651L;
private final StorageRetryStrategy retryStrategy;
final StorageRetryStrategy retryStrategy;

HttpRetryAlgorithmManager(StorageRetryStrategy retryStrategy) {
this.retryStrategy = retryStrategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.time.Clock;
import java.util.Objects;
import java.util.Set;
import org.checkerframework.checker.nullness.qual.NonNull;

Expand Down Expand Up @@ -93,12 +94,21 @@ public HttpStorageOptions.Builder toBuilder() {

@Override
public int hashCode() {
return baseHashCode();
return Objects.hash(retryAlgorithmManager, blobWriteSessionConfig, baseHashCode());
}

@Override
public boolean equals(Object obj) {
return obj instanceof HttpStorageOptions && baseEquals((HttpStorageOptions) obj);
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof HttpStorageOptions)) {
return false;
}
HttpStorageOptions that = (HttpStorageOptions) o;
return Objects.equals(retryAlgorithmManager, that.retryAlgorithmManager)
&& Objects.equals(blobWriteSessionConfig, that.blobWriteSessionConfig)
&& this.baseEquals(that);
}

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
Expand Down Expand Up @@ -133,6 +143,9 @@ public static class Builder extends StorageOptions.Builder {

Builder(StorageOptions options) {
super(options);
HttpStorageOptions hso = (HttpStorageOptions) options;
this.storageRetryStrategy = hso.retryAlgorithmManager.retryStrategy;
this.blobWriteSessionConfig = hso.blobWriteSessionConfig;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Objects;
import java.util.stream.Collector;
import javax.annotation.concurrent.Immutable;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
Expand Down Expand Up @@ -89,6 +90,25 @@ public final class JournalingBlobWriteSessionConfig extends BlobWriteSessionConf
this.includeLoggingSink = includeLoggingSink;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof JournalingBlobWriteSessionConfig)) {
return false;
}
JournalingBlobWriteSessionConfig that = (JournalingBlobWriteSessionConfig) o;
return includeLoggingSink == that.includeLoggingSink
&& Objects.equals(paths, that.paths)
&& Objects.equals(absolutePaths, that.absolutePaths);
}

@Override
public int hashCode() {
return Objects.hash(paths, includeLoggingSink, absolutePaths);
}

@VisibleForTesting
@InternalApi
JournalingBlobWriteSessionConfig withIncludeLoggingSink() {
Expand Down

0 comments on commit b84654e

Please sign in to comment.