Skip to content

Commit 174cd8f

Browse files
committed
chore: remove old appendble upload implementation
1 parent c0febee commit 174cd8f

8 files changed

Lines changed: 31 additions & 1082 deletions

google-cloud-storage/src/main/java/com/google/cloud/storage/BidiAppendableUnbufferedWritableByteChannel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package com.google.cloud.storage;
1818

1919
import com.google.cloud.BaseServiceException;
20-
import com.google.cloud.storage.BlobAppendableUploadImpl.AppendableUnbufferedWritableByteChannel;
2120
import com.google.cloud.storage.ChunkSegmenter.ChunkSegment;
21+
import com.google.cloud.storage.UnbufferedWritableByteChannelSession.UnbufferedWritableByteChannel;
2222
import java.io.IOException;
2323
import java.io.InterruptedIOException;
2424
import java.nio.ByteBuffer;
@@ -27,8 +27,7 @@
2727
import java.util.concurrent.TimeUnit;
2828
import java.util.concurrent.TimeoutException;
2929

30-
final class BidiAppendableUnbufferedWritableByteChannel
31-
implements AppendableUnbufferedWritableByteChannel {
30+
final class BidiAppendableUnbufferedWritableByteChannel implements UnbufferedWritableByteChannel {
3231

3332
private final BidiUploadStreamingStream stream;
3433
private final ChunkSegmenter chunkSegmenter;

google-cloud-storage/src/main/java/com/google/cloud/storage/BidiBlobWriteSessionConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ public WritableByteChannelSession<?, BlobInfo> writeSession(
111111
GrpcStorageImpl grpc = (GrpcStorageImpl) s;
112112
GrpcCallContext grpcCallContext =
113113
opts.grpcMetadataMapper().apply(GrpcCallContext.createDefault());
114-
BidiWriteObjectRequest req = grpc.getBidiWriteObjectRequest(info, opts);
114+
BidiWriteObjectRequest req =
115+
grpc.getBidiWriteObjectRequest(info, opts, false);
115116

116117
ApiFuture<BidiResumableWrite> startResumableWrite =
117118
grpc.startResumableWrite(grpcCallContext, req, opts);

google-cloud-storage/src/main/java/com/google/cloud/storage/BidiResumableWrite.java

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -94,73 +94,3 @@ static BidiResumableWrite identity(BidiResumableWrite w) {
9494
return w;
9595
}
9696
}
97-
98-
final class BidiAppendableWrite implements BidiWriteObjectRequestBuilderFactory {
99-
100-
private final BidiWriteObjectRequest req;
101-
102-
public BidiAppendableWrite(BidiWriteObjectRequest req) {
103-
this(req, false);
104-
}
105-
106-
public BidiAppendableWrite(BidiWriteObjectRequest req, boolean takeOver) {
107-
if (takeOver) {
108-
this.req = req;
109-
} else {
110-
req =
111-
req.toBuilder()
112-
.setWriteObjectSpec(req.getWriteObjectSpec().toBuilder().setAppendable(true).build())
113-
.build();
114-
this.req = req;
115-
}
116-
}
117-
118-
public BidiWriteObjectRequest getReq() {
119-
return req;
120-
}
121-
122-
@Override
123-
public BidiWriteObjectRequest.Builder newBuilder() {
124-
return req.toBuilder();
125-
}
126-
127-
@Override
128-
public @Nullable String bucketName() {
129-
if (req.hasWriteObjectSpec() && req.getWriteObjectSpec().hasResource()) {
130-
return req.getWriteObjectSpec().getResource().getBucket();
131-
} else if (req.hasAppendObjectSpec()) {
132-
return req.getAppendObjectSpec().getBucket();
133-
}
134-
return null;
135-
}
136-
137-
@Override
138-
public String toString() {
139-
return "BidiAppendableWrite{" + "req=" + fmtProto(req) + '}';
140-
}
141-
142-
@Override
143-
public boolean equals(Object o) {
144-
if (this == o) {
145-
return true;
146-
}
147-
if (!(o instanceof BidiAppendableWrite)) {
148-
return false;
149-
}
150-
BidiAppendableWrite BidiAppendableWrite = (BidiAppendableWrite) o;
151-
return Objects.equals(req, BidiAppendableWrite.getReq());
152-
}
153-
154-
@Override
155-
public int hashCode() {
156-
return Objects.hash(req);
157-
}
158-
159-
/**
160-
* Helper function which is more specific than {@link Function#identity()}. Constraining the input
161-
* and output to be exactly {@link BidiAppendableWrite}.
162-
*/
163-
static BidiAppendableWrite identity(BidiAppendableWrite w) {
164-
return w;
165-
}
166-
}

google-cloud-storage/src/main/java/com/google/cloud/storage/BlobAppendableUploadConfig.java

Lines changed: 11 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
import com.google.api.core.BetaApi;
2525
import com.google.api.core.InternalApi;
2626
import com.google.api.core.SettableApiFuture;
27-
import com.google.api.gax.retrying.BasicResultRetryAlgorithm;
28-
import com.google.api.gax.rpc.AbortedException;
29-
import com.google.api.gax.rpc.ApiException;
3027
import com.google.cloud.storage.BidiUploadState.AppendableUploadState;
3128
import com.google.cloud.storage.BidiUploadState.TakeoverAppendableUploadState;
3229
import com.google.cloud.storage.BlobAppendableUpload.AppendableUploadWriteableByteChannel;
@@ -36,9 +33,7 @@
3633
import com.google.cloud.storage.UnifiedOpts.ObjectTargetOpt;
3734
import com.google.cloud.storage.UnifiedOpts.Opts;
3835
import com.google.common.base.MoreObjects;
39-
import com.google.storage.v2.BidiWriteObjectRequest;
4036
import com.google.storage.v2.BidiWriteObjectResponse;
41-
import com.google.storage.v2.Object;
4237
import com.google.storage.v2.ServiceConstants.Values;
4338
import java.util.function.BiFunction;
4439
import javax.annotation.concurrent.Immutable;
@@ -60,20 +55,17 @@ public final class BlobAppendableUploadConfig {
6055
new BlobAppendableUploadConfig(
6156
FlushPolicy.minFlushSize(_256KiB),
6257
Hasher.enabled(),
63-
CloseAction.CLOSE_WITHOUT_FINALIZING,
64-
false);
58+
CloseAction.CLOSE_WITHOUT_FINALIZING);
6559

6660
private final FlushPolicy flushPolicy;
6761
private final Hasher hasher;
6862
private final CloseAction closeAction;
69-
private final boolean newImpl;
7063

7164
private BlobAppendableUploadConfig(
72-
FlushPolicy flushPolicy, Hasher hasher, CloseAction closeAction, boolean newImpl) {
65+
FlushPolicy flushPolicy, Hasher hasher, CloseAction closeAction) {
7366
this.flushPolicy = flushPolicy;
7467
this.hasher = hasher;
7568
this.closeAction = closeAction;
76-
this.newImpl = newImpl;
7769
}
7870

7971
/**
@@ -104,7 +96,7 @@ public BlobAppendableUploadConfig withFlushPolicy(FlushPolicy flushPolicy) {
10496
if (this.flushPolicy.equals(flushPolicy)) {
10597
return this;
10698
}
107-
return new BlobAppendableUploadConfig(flushPolicy, hasher, closeAction, newImpl);
99+
return new BlobAppendableUploadConfig(flushPolicy, hasher, closeAction);
108100
}
109101

110102
/**
@@ -134,7 +126,7 @@ public BlobAppendableUploadConfig withCloseAction(CloseAction closeAction) {
134126
if (this.closeAction == closeAction) {
135127
return this;
136128
}
137-
return new BlobAppendableUploadConfig(flushPolicy, hasher, closeAction, newImpl);
129+
return new BlobAppendableUploadConfig(flushPolicy, hasher, closeAction);
138130
}
139131

140132
/**
@@ -166,7 +158,7 @@ BlobAppendableUploadConfig withCrc32cValidationEnabled(boolean enabled) {
166158
return this;
167159
}
168160
return new BlobAppendableUploadConfig(
169-
flushPolicy, enabled ? Hasher.enabled() : Hasher.noop(), closeAction, newImpl);
161+
flushPolicy, enabled ? Hasher.enabled() : Hasher.noop(), closeAction);
170162
}
171163

172164
/** Never to be made public until {@link Hasher} is public */
@@ -175,10 +167,6 @@ Hasher getHasher() {
175167
return hasher;
176168
}
177169

178-
BlobAppendableUploadConfig useNewImpl() {
179-
return new BlobAppendableUploadConfig(flushPolicy, hasher, closeAction, true);
180-
}
181-
182170
@Override
183171
public String toString() {
184172
return MoreObjects.toStringHelper(this)
@@ -239,9 +227,8 @@ public enum CloseAction {
239227
}
240228

241229
BlobAppendableUpload create(GrpcStorageImpl storage, BlobInfo info, Opts<ObjectTargetOpt> opts) {
242-
if (newImpl) {
243-
// TODO: make configurable
244-
int maxRedirectsAllowed = 3;
230+
// TODO: make configurable
231+
int maxRedirectsAllowed = 3;
245232

246233
long maxPendingBytes = this.getFlushPolicy().getMaxPendingBytes();
247234
AppendableUploadState state = storage.getAppendableState(info, opts, maxPendingBytes);
@@ -277,67 +264,13 @@ BlobAppendableUpload create(GrpcStorageImpl storage, BlobInfo info, Opts<ObjectT
277264
return new AppendableObjectBufferedWritableByteChannel(
278265
flushPolicy.createBufferedChannel(c),
279266
c,
280-
this.closeAction == CloseAction.FINALIZE_WHEN_CLOSING,
281-
newImpl);
267+
this.closeAction == CloseAction.FINALIZE_WHEN_CLOSING);
282268
},
283269
state.getResultFuture());
284270

285-
return new BlobAppendableUploadImpl(
286-
new DefaultBlobWriteSessionConfig.DecoratedWritableByteChannelSession<>(
287-
build, BidiBlobWriteSessionConfig.Factory.WRITE_OBJECT_RESPONSE_BLOB_INFO_DECODER));
288-
} else {
289-
boolean takeOver = info.getGeneration() != null;
290-
BidiWriteObjectRequest req =
291-
takeOver
292-
? storage.getBidiWriteObjectRequestForTakeover(info, opts)
293-
: storage.getBidiWriteObjectRequest(info, opts);
294-
295-
BidiAppendableWrite baw = new BidiAppendableWrite(req, takeOver);
296-
297-
WritableByteChannelSession<
298-
AppendableObjectBufferedWritableByteChannel, BidiWriteObjectResponse>
299-
build =
300-
ResumableMedia.gapic()
301-
.write()
302-
.bidiByteChannel(storage.storageClient.bidiWriteObjectCallable())
303-
.setHasher(this.getHasher())
304-
.setByteStringStrategy(ByteStringStrategy.copy())
305-
.appendable()
306-
.withRetryConfig(
307-
storage.retrier.withAlg(
308-
new BasicResultRetryAlgorithm<Object>() {
309-
@Override
310-
public boolean shouldRetry(
311-
Throwable previousThrowable, Object previousResponse) {
312-
// TODO: remove this later once the redirects are not handled by the
313-
// retry loop
314-
ApiException apiEx = null;
315-
if (previousThrowable instanceof StorageException) {
316-
StorageException se = (StorageException) previousThrowable;
317-
Throwable cause = se.getCause();
318-
if (cause instanceof ApiException) {
319-
apiEx = (ApiException) cause;
320-
}
321-
}
322-
if (apiEx instanceof AbortedException) {
323-
return true;
324-
}
325-
return storage
326-
.retryAlgorithmManager
327-
.idempotent()
328-
.shouldRetry(previousThrowable, null);
329-
}
330-
}))
331-
.buffered(this.getFlushPolicy())
332-
.setStartAsync(ApiFutures.immediateFuture(baw))
333-
.setGetCallable(storage.storageClient.getObjectCallable())
334-
.setFinalizeOnClose(this.closeAction == CloseAction.FINALIZE_WHEN_CLOSING)
335-
.build();
336-
337-
return new BlobAppendableUploadImpl(
338-
new DefaultBlobWriteSessionConfig.DecoratedWritableByteChannelSession<>(
339-
build, BidiBlobWriteSessionConfig.Factory.WRITE_OBJECT_RESPONSE_BLOB_INFO_DECODER));
340-
}
271+
return new BlobAppendableUploadImpl(
272+
new DefaultBlobWriteSessionConfig.DecoratedWritableByteChannelSession<>(
273+
build, BidiBlobWriteSessionConfig.Factory.WRITE_OBJECT_RESPONSE_BLOB_INFO_DECODER));
341274
}
342275

343276
private static final class AppendableSession

google-cloud-storage/src/main/java/com/google/cloud/storage/BlobAppendableUploadImpl.java

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.api.core.ApiFuture;
2020
import com.google.api.core.BetaApi;
2121
import com.google.cloud.storage.BufferedWritableByteChannelSession.BufferedWritableByteChannel;
22-
import com.google.cloud.storage.UnbufferedWritableByteChannelSession.UnbufferedWritableByteChannel;
2322
import com.google.common.base.Preconditions;
2423
import java.io.IOException;
2524
import java.nio.ByteBuffer;
@@ -64,21 +63,18 @@ static final class AppendableObjectBufferedWritableByteChannel
6463
implements BufferedWritableByteChannel,
6564
BlobAppendableUpload.AppendableUploadWriteableByteChannel {
6665
private final BufferedWritableByteChannel buffered;
67-
private final AppendableUnbufferedWritableByteChannel unbuffered;
66+
private final BidiAppendableUnbufferedWritableByteChannel unbuffered;
6867
private final boolean finalizeOnClose;
6968
private final ReentrantLock lock;
70-
private final boolean newImpl;
7169

7270
AppendableObjectBufferedWritableByteChannel(
7371
BufferedWritableByteChannel buffered,
74-
AppendableUnbufferedWritableByteChannel unbuffered,
75-
boolean finalizeOnClose,
76-
boolean newImpl) {
72+
BidiAppendableUnbufferedWritableByteChannel unbuffered,
73+
boolean finalizeOnClose) {
7774
this.buffered = buffered;
7875
this.unbuffered = unbuffered;
7976
this.finalizeOnClose = finalizeOnClose;
80-
this.newImpl = newImpl;
81-
lock = new ReentrantLock();
77+
this.lock = new ReentrantLock();
8278
}
8379

8480
@Override
@@ -115,17 +111,9 @@ public boolean isOpen() {
115111
public void finalizeAndClose() throws IOException {
116112
lock.lock();
117113
try {
118-
if (newImpl) {
119-
if (buffered.isOpen()) {
120-
unbuffered.nextWriteShouldFinalize();
121-
buffered.close();
122-
}
123-
} else {
124-
if (buffered.isOpen()) {
125-
buffered.flush();
126-
unbuffered.finalizeWrite();
127-
buffered.close();
128-
}
114+
if (buffered.isOpen()) {
115+
unbuffered.nextWriteShouldFinalize();
116+
buffered.close();
129117
}
130118
} finally {
131119
lock.unlock();
@@ -153,11 +141,4 @@ public void close() throws IOException {
153141
}
154142
}
155143
}
156-
157-
/** Temporary shim to allow selective implementation */
158-
interface AppendableUnbufferedWritableByteChannel extends UnbufferedWritableByteChannel {
159-
default void nextWriteShouldFinalize() {}
160-
161-
default void finalizeWrite() throws IOException {}
162-
}
163144
}

0 commit comments

Comments
 (0)