This repository was archived by the owner on Apr 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
chore: handle unary gRPC call ordering in KeyAwareChannel #4336
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b9e5d4e
chore: handle unary gRPC call ordering in KeyAwareChannel
rahul2393 a4fb7f8
incorporate suggestions
rahul2393 4bab789
test: add tests for location API
olavloite d719633
fix test
rahul2393 33175a5
add more tests
rahul2393 7e2d482
add test for executesSql update cache
rahul2393 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,6 +245,12 @@ static final class KeyAwareClientCall<RequestT, ResponseT> | |
| @Nullable private ChannelEndpoint selectedEndpoint; | ||
| @Nullable private ByteString transactionIdToClear; | ||
| private boolean allowDefaultAffinity; | ||
| private long pendingRequests; | ||
| private boolean pendingHalfClose; | ||
| @Nullable private Boolean pendingMessageCompression; | ||
| private boolean cancelled; | ||
| @Nullable private String cancelMessage; | ||
| @Nullable private Throwable cancelCause; | ||
|
|
||
| KeyAwareClientCall( | ||
| KeyAwareChannel parentChannel, | ||
|
|
@@ -268,11 +274,22 @@ protected ClientCall<RequestT, ResponseT> delegate() { | |
| public void start(Listener<ResponseT> responseListener, Metadata headers) { | ||
| this.responseListener = new KeyAwareClientCallListener<>(responseListener, this); | ||
| this.headers = headers; | ||
| if (cancelled) { | ||
| this.responseListener.onClose( | ||
| io.grpc.Status.CANCELLED.withDescription(cancelMessage).withCause(cancelCause), | ||
| new Metadata()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("unchecked") | ||
| public void sendMessage(RequestT message) { | ||
| if (cancelled) { | ||
| return; | ||
| } | ||
| if (responseListener == null || headers == null) { | ||
| throw new IllegalStateException("start must be called before sendMessage"); | ||
| } | ||
| ChannelEndpoint endpoint = null; | ||
| ChannelFinder finder = null; | ||
|
|
||
|
|
@@ -326,16 +343,23 @@ public void sendMessage(RequestT message) { | |
| this.channelFinder = finder; | ||
|
|
||
| delegate = endpoint.getChannel().newCall(methodDescriptor, callOptions); | ||
| if (pendingMessageCompression != null) { | ||
| delegate.setMessageCompression(pendingMessageCompression); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to set it to null |
||
| delegate.start(responseListener, headers); | ||
| drainPendingRequests(); | ||
| delegate.sendMessage(message); | ||
| if (pendingHalfClose) { | ||
| delegate.halfClose(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void halfClose() { | ||
| if (delegate != null) { | ||
| delegate.halfClose(); | ||
| } else { | ||
| throw new IllegalStateException("halfClose called before sendMessage"); | ||
| pendingHalfClose = true; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -346,6 +370,56 @@ public void cancel(@Nullable String message, @Nullable Throwable cause) { | |
| } else if (responseListener != null) { | ||
| responseListener.onClose( | ||
| io.grpc.Status.CANCELLED.withDescription(message).withCause(cause), new Metadata()); | ||
| cancelled = true; | ||
| cancelMessage = message; | ||
| cancelCause = cause; | ||
| } else { | ||
| cancelled = true; | ||
| cancelMessage = message; | ||
| cancelCause = cause; | ||
| } | ||
|
rahul2393 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| @Override | ||
| public void request(int numMessages) { | ||
| if (delegate != null) { | ||
|
rahul2393 marked this conversation as resolved.
Outdated
|
||
| delegate.request(numMessages); | ||
| return; | ||
| } | ||
| if (numMessages <= 0) { | ||
| return; | ||
| } | ||
| long updated = pendingRequests + numMessages; | ||
| if (updated < 0L) { | ||
| updated = Long.MAX_VALUE; | ||
| } | ||
| pendingRequests = updated; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isReady() { | ||
| if (delegate == null) { | ||
| return false; | ||
| } | ||
| return delegate.isReady(); | ||
| } | ||
|
|
||
| @Override | ||
| public void setMessageCompression(boolean enabled) { | ||
| if (delegate != null) { | ||
| delegate.setMessageCompression(enabled); | ||
| } else { | ||
| pendingMessageCompression = enabled; | ||
| } | ||
| } | ||
|
|
||
| private void drainPendingRequests() { | ||
| long requests = pendingRequests; | ||
| pendingRequests = 0L; | ||
| while (requests > 0) { | ||
| int batch = requests > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) requests; | ||
| delegate.request(batch); | ||
| requests -= batch; | ||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.