2424import com .google .api .core .BetaApi ;
2525import com .google .api .core .InternalApi ;
2626import 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 ;
3027import com .google .cloud .storage .BidiUploadState .AppendableUploadState ;
3128import com .google .cloud .storage .BidiUploadState .TakeoverAppendableUploadState ;
3229import com .google .cloud .storage .BlobAppendableUpload .AppendableUploadWriteableByteChannel ;
3633import com .google .cloud .storage .UnifiedOpts .ObjectTargetOpt ;
3734import com .google .cloud .storage .UnifiedOpts .Opts ;
3835import com .google .common .base .MoreObjects ;
39- import com .google .storage .v2 .BidiWriteObjectRequest ;
4036import com .google .storage .v2 .BidiWriteObjectResponse ;
41- import com .google .storage .v2 .Object ;
4237import com .google .storage .v2 .ServiceConstants .Values ;
4338import java .util .function .BiFunction ;
4439import 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
0 commit comments