Skip to content

Commit

Permalink
fix: update grpc bidi resumable uploads to validate ack'd object size (
Browse files Browse the repository at this point in the history
…#2570)

* fix: update grpc bidi resumable uploads to validate ack'd object size

Follow up to #2527

Part 1, add tests and simulation server

* fix: update grpc bidi resumable uploads to validate ack'd object size

Follow up to #2527

Cleanup unused inner-class

* fix: update grpc bidi resumable uploads to validate ack'd object size

Follow up to #2527

Move request trimming inline rather than at the end

* fix: update grpc bidi resumable uploads to validate ack'd object size

Follow up to #2527

Update GapicBidiUnbufferedWritableByteChannel to correctly handle failure scenarios {1, 2, 3, 4, 4_1, 4_2, 5, 7}

Refactor ResumableSessionFailureScenario to accept Message and List rather than WriteObjectResponse and List<WriteObjectRequest>.

The shape of BidiWriteObjectRequest/WriteObjectRequest and BidiWriteObjectResponse/WriteObjectResponse are largely the same (bidi has two extra fields) so rather than overloading toStorageException yet again, this time there is a single method for grpc messages that internally can branch when formatting the request. In this case, we're quite safe taking this relaxed typing because it is an internal API that is only called from a grpc context where protos will be used.

* fix: update grpc bidi resumable uploads to validate ack'd object size

Follow up to #2527

Update GapicBidiUnbufferedWritableByteChannel to correctly handle partial consumption of content

Tests passing now.

Separate tracking of client detected errors and stream errors.

When await is invoked, if a client detected error is present AND a stream error is present, the client detected error will take precedence. If a stream error happens and the client detected error has not yet been observed, the stream error will be added as a suppressed exception to the client detected error.

* chore: fix failing tests
  • Loading branch information
BenWhitehead authored Jun 13, 2024
1 parent 55a6d15 commit 5c9cecf
Show file tree
Hide file tree
Showing 8 changed files with 1,340 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public StartResumableWriteResponse getRes() {

@Override
public BidiWriteObjectRequest.Builder newBuilder() {
return writeRequest.toBuilder();
return writeRequest.toBuilder().clearWriteObjectSpec();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.google.cloud.storage;

import static com.google.cloud.storage.StorageV2ProtoUtils.fmtProto;

import com.google.cloud.storage.BidiWriteCtx.BidiWriteObjectRequestBuilderFactory;
import com.google.cloud.storage.Crc32cValue.Crc32cLengthKnown;
import com.google.storage.v2.BidiWriteObjectRequest;
Expand Down Expand Up @@ -84,36 +82,5 @@ interface BidiWriteObjectRequestBuilderFactory {

@Nullable
String bucketName();

static BidiSimpleWriteObjectRequestBuilderFactory simple(BidiWriteObjectRequest req) {
return new BidiSimpleWriteObjectRequestBuilderFactory(req);
}
}

static final class BidiSimpleWriteObjectRequestBuilderFactory
implements BidiWriteObjectRequestBuilderFactory {
private final BidiWriteObjectRequest req;

private BidiSimpleWriteObjectRequestBuilderFactory(BidiWriteObjectRequest req) {
this.req = req;
}

@Override
public BidiWriteObjectRequest.Builder newBuilder() {
return req.toBuilder();
}

@Override
public @Nullable String bucketName() {
if (req.hasWriteObjectSpec() && req.getWriteObjectSpec().hasResource()) {
return req.getWriteObjectSpec().getResource().getBucket();
}
return null;
}

@Override
public String toString() {
return "SimpleBidiWriteObjectRequestBuilderFactory{" + "req=" + fmtProto(req) + '}';
}
}
}
Loading

0 comments on commit 5c9cecf

Please sign in to comment.