Skip to content

Commit f97befb

Browse files
committed
chore: add temporary WriteCtx constructor that allows specifying the initial crc32c value
The desired default will be `Crc32cValue.zero()`, but not all tests or uploads are ready to handle this. Stick with the existing null as default, and provide the overload to selectively opt into things incrementally.
1 parent ff94013 commit f97befb

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,22 @@ final class WriteCtx<RequestFactoryT extends WriteObjectRequestBuilderFactory> {
3131

3232
private final AtomicLong totalSentBytes;
3333
private final AtomicLong confirmedBytes;
34-
private final AtomicReference<Crc32cLengthKnown> cumulativeCrc32c;
34+
private final AtomicReference<@Nullable Crc32cLengthKnown> cumulativeCrc32c;
3535

3636
WriteCtx(RequestFactoryT requestFactory) {
37+
this(requestFactory, null);
38+
}
39+
40+
/**
41+
* TODO: Remove initialValue and replace with Crc32cValue.zero() once all uploads have been
42+
* updated to do e2e checksumming by default.
43+
*/
44+
@Deprecated
45+
WriteCtx(RequestFactoryT requestFactory, @Nullable Crc32cLengthKnown initialValue) {
3746
this.requestFactory = requestFactory;
3847
this.totalSentBytes = new AtomicLong(0);
3948
this.confirmedBytes = new AtomicLong(0);
40-
this.cumulativeCrc32c = new AtomicReference<>(null);
49+
this.cumulativeCrc32c = new AtomicReference<>(initialValue);
4150
}
4251

4352
public RequestFactoryT getRequestFactory() {
@@ -56,7 +65,7 @@ public AtomicLong getConfirmedBytes() {
5665
return confirmedBytes;
5766
}
5867

59-
public AtomicReference<Crc32cLengthKnown> getCumulativeCrc32c() {
68+
public AtomicReference<@Nullable Crc32cLengthKnown> getCumulativeCrc32c() {
6069
return cumulativeCrc32c;
6170
}
6271

google-cloud-storage/src/test/java/com/google/cloud/storage/ITGapicUnbufferedWritableByteChannelTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ public void directUpload() throws IOException, InterruptedException, ExecutionEx
159159
SettableApiFuture<WriteObjectResponse> result = SettableApiFuture.create();
160160
try (GapicUnbufferedDirectWritableByteChannel c =
161161
new GapicUnbufferedDirectWritableByteChannel(
162-
result, segmenter, sc.writeObjectCallable(), new WriteCtx<>(reqFactory))) {
162+
result,
163+
segmenter,
164+
sc.writeObjectCallable(),
165+
new WriteCtx<>(reqFactory, Crc32cValue.zero()))) {
163166
c.write(ByteBuffer.wrap(bytes));
164167
}
165168
assertThat(result.get()).isEqualTo(resp);
@@ -185,7 +188,7 @@ public void resumableUpload() throws IOException, InterruptedException, Executio
185188
result,
186189
segmenter,
187190
sc.writeObjectCallable(),
188-
new WriteCtx<>(reqFactory),
191+
new WriteCtx<>(reqFactory, Crc32cValue.zero()),
189192
RetrierWithAlg.attemptOnce(),
190193
Retrying::newCallContext);
191194
ArrayList<String> debugMessages = new ArrayList<>();
@@ -267,7 +270,7 @@ public void resumableUpload_chunkAutomaticRetry()
267270
result,
268271
segmenter,
269272
sc.writeObjectCallable(),
270-
new WriteCtx<>(reqFactory),
273+
new WriteCtx<>(reqFactory, Crc32cValue.zero()),
271274
TestUtils.retrierFromStorageOptions(fake.getGrpcStorageOptions())
272275
.withAlg(Retrying.alwaysRetry()),
273276
Retrying::newCallContext)) {
@@ -319,7 +322,7 @@ public void resumableUpload_finalizeWhenWriteAndCloseCalledEvenWhenQuantumAligne
319322
result,
320323
segmenter,
321324
sc.writeObjectCallable(),
322-
new WriteCtx<>(reqFactory),
325+
new WriteCtx<>(reqFactory, Crc32cValue.zero()),
323326
RetrierWithAlg.attemptOnce(),
324327
Retrying::newCallContext);
325328
try {

0 commit comments

Comments
 (0)