Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements a fast-open read mechanism for Google Cloud Storage sessions, allowing reads to be sent alongside the initial session-opening request to save a round trip. The session caches these fast-open reads and returns them on the first matching readAs call, while ensuring any unclaimed reads are properly closed. The review feedback highlights a critical issue where duplicate configurations in the fast-open list would overwrite each other in the map, leading to resource leaks and redundant requests. To resolve this, the reviewer suggests refactoring the map to store a queue of reads per configuration, providing complete code suggestions across the session implementation and client code.
2e65e0a to
b59e5e4
Compare
Second step of fast open BiDi reads (go/fast-open-bidi-read, b/552263062). ObjectReadSessionImpl keeps the fast open reads sent with the open, keyed by the config each was created from. readAs removes the read for an equal config and returns it, so the bytes that came back with the open are used and no second request is sent; any other readAs sends a new read exactly as before. Closing the session first closes fast open reads that were never asked for. An unclaimed asChannel() read fills its small buffer and blocks the stream's thread, so it must be closed (and its buffer emptied) before the stream, or close() would wait forever. Only one fast open read is supported for now; readSession rejects more than one before anything is sent.
b59e5e4 to
e9de87e
Compare
nidhiii-27
left a comment
There was a problem hiding this comment.
Please resolve the gemini-code-assist[bot] comments as well.
| GrpcUtils.closeAll(fastOpenReads.values()); | ||
| fastOpenReads.clear(); |
There was a problem hiding this comment.
If close() races with a concurrent readAs(config) that just passed checkState(open), closing fastOpenReads.values() before removing them from the map could let readAs claim a read whose buffers were just closed. Can we remove each entry from fastOpenReads first before closing (similar to children.drainEntries below)?
List<ObjectReadSessionStreamRead<?>> unclaimed = new ArrayList<>(fastOpenReads.size());
fastOpenReads.keySet().forEach(k -> {
ObjectReadSessionStreamRead<?> read = fastOpenReads.remove(k);
if (read != null) {
unclaimed.add(read);
}
});
GrpcUtils.closeAll(unclaimed);There was a problem hiding this comment.
Switched to removing entries from fastOpenReads into a local list before calling GrpcUtils.closeAll.
| } | ||
|
|
||
| @Test | ||
| public void close_withAnUnclaimedFastOpenRead_closesTheSession() throws Exception { |
There was a problem hiding this comment.
[Optional suggestion]
READ_10_TO_20 uses asFutureBytes(), which already closes its ChildRefs inside eof(). Consider also testing an unclaimed asFutureByteString() read here, since ZeroCopyByteStringAccumulatingRead is the case that holds zero-copy buffers open after eof() removes the read from state.
| .readSession(OPEN, CTX, ImmutableList.of(ReadProjectionConfigs.asChannel())) | ||
| .get(5, SECONDS); | ||
| // let the chunks arrive and fill the unread channel read | ||
| Thread.sleep(500); |
There was a problem hiding this comment.
nit: Can we use a CountDownLatch(3) in the fake server loop instead of Thread.sleep(500) so the test deterministically waits for the 2-slot queue to fill?
There was a problem hiding this comment.
I tried CountDownLatch(3) in the fake server loop, but client.onNext returns as soon as the server buffers the frames without waiting for the client—in 10 runs readOffset on the client was still 0 (nine times) or 8 (once) when the latch opened, before the 2-slot queue filled. Keeping the sleep so the 3rd chunk actually blocks the gRPC thread, though happy to switch to polling readOffset >= 16 plus a brief pause if you prefer.
|
Replied to the bot, currently we are supporting at most one fast open config for now, marking them resolved for now. Will revisit when we support multiple fast open configs |
2/n of fast open BiDi reads.
ObjectReadSessionImpl keeps the fast open reads sent with the open, keyed by the config each was created from. readAs removes the read for an equal config and returns it, so the bytes that came back with the open are used and no second request is sent; any other readAs sends a new read exactly as before. Closing the session also closes fast open reads that were never asked for.