Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retries:Remove early commit for transparent retries with none remaining. (1.54.x backport) #10080

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 1 addition & 15 deletions core/src/main/java/io/grpc/internal/RetriableStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -932,29 +932,15 @@ public void run() {
return;
}
if (isHedging) {
boolean commit = false;
synchronized (lock) {
// Although this operation is not done atomically with
// noMoreTransparentRetry.compareAndSet(false, true), it does not change the size() of
// activeHedges, so neither does it affect the commitment decision of other threads,
// nor do the commitment decision making threads affect itself.
state = state.replaceActiveHedge(substream, newSubstream);

// optimization for early commit
if (!hasPotentialHedging(state)
&& state.activeHedges.size() == 1) {
commit = true;
}
}
if (commit) {
commitAndRun(newSubstream);
}
} else {
if (retryPolicy == null || retryPolicy.maxAttempts == 1) {
// optimization for early commit
commitAndRun(newSubstream);
}
}

callExecutor.execute(new Runnable() {
@Override
public void run() {
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/io/grpc/internal/RetriableStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@ public void normalRetry_thenNoTransparentRetry_andNoMoreRetry() {
}

@Test
public void noRetry_transparentRetry_earlyCommit() {
public void noRetry_transparentRetry_noEarlyCommit() {
ClientStream mockStream1 = mock(ClientStream.class);
ClientStream mockStream2 = mock(ClientStream.class);
InOrder inOrder = inOrder(retriableStreamRecorder, mockStream1, mockStream2);
Expand Down Expand Up @@ -1999,7 +1999,7 @@ method, new Metadata(), channelBufferUsed, PER_RPC_BUFFER_LIMIT, CHANNEL_BUFFER_
inOrder.verify(retriableStreamRecorder).newSubstream(0);
ArgumentCaptor<ClientStreamListener> sublistenerCaptor2 =
ArgumentCaptor.forClass(ClientStreamListener.class);
inOrder.verify(retriableStreamRecorder).postCommit();
verify(retriableStreamRecorder, never()).postCommit();
inOrder.verify(mockStream2).start(sublistenerCaptor2.capture());
inOrder.verify(mockStream2).isReady();
inOrder.verifyNoMoreInteractions();
Expand Down