Skip to content

Commit 32cfd9a

Browse files
author
Dhriti Chopra
committed
feat(storage): reject fast open configs that are not a single read
Third step of fast open BiDi reads (go/fast-open-bidi-read, b/552263062). A fast open read is sent as one range in the open request, so only configs that make a single read on the stream (asFutureBytes, asFutureByteString, asChannel) can be one. asSeekableChannel issues reads as the caller seeks, so it cannot. readSession now rejects it with an IllegalArgumentException before anything is sent, instead of failing with an UnsupportedOperationException while creating the read.
1 parent e9de87e commit 32cfd9a

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageDataClient.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ ApiFuture<ObjectReadSession> readSession(
8484
req.getReadRangesList().isEmpty(),
8585
"ranges included in the initial request are not supported");
8686
checkArgument(fastOpenConfigs.size() <= 1, "at most one fast open read is supported");
87+
checkArgument(
88+
fastOpenConfigs.stream().allMatch(c -> c.getType() == ProjectionType.STREAM_READ),
89+
"a fast open read must be asFutureBytes(), asFutureByteString() or asChannel(), but was %s",
90+
fastOpenConfigs);
8791
ObjectReadSessionState state = new ObjectReadSessionState(ctx, req);
8892

8993
ZeroCopyBidiStreamingCallable<BidiReadObjectRequest, BidiReadObjectResponse> callable =

‎java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/ITFastOpenFakeTest.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,24 @@ public void readSession_withMoreThanOneFastOpenConfig_isRejected() throws Except
268268
assertThat(requestsReceived).isEmpty();
269269
}
270270

271+
@Test
272+
public void readSession_withASeekableChannelConfig_isRejected() throws Exception {
273+
FakeStorage server = fakeServer(ImmutableMap.of());
274+
275+
try (FakeServer fakeServer = FakeServer.of(server);
276+
Storage storage = fakeServer.getGrpcStorageOptions().getService()) {
277+
StorageDataClient dataClient = maybeGetStorageDataClient(storage);
278+
279+
assertThrows(
280+
IllegalArgumentException.class,
281+
() ->
282+
dataClient.readSession(
283+
OPEN, CTX, ImmutableList.of(ReadProjectionConfigs.asSeekableChannel())));
284+
}
285+
286+
assertThat(requestsReceived).isEmpty();
287+
}
288+
271289
/**
272290
* A fake server that answers each request in {@code responses} and adds it to {@link
273291
* #requestsReceived}. Any other request is answered with an error.

0 commit comments

Comments
 (0)