-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(bigtable): recycle channel on consecutive new stream failures #13245
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -469,4 +469,98 @@ void testRecycledChannelDoesNotRejoinPool() throws InterruptedException { | |
|
|
||
| pool.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void testRecycleChannelOnConsecutiveFailures() { | ||
| when(channelSupplier.get()).thenReturn(channel); | ||
| when(channel.newCall(any(), any())).thenReturn(clientCall); | ||
| doNothing().when(clientCall).start(listener.capture(), any()); | ||
|
|
||
| ChannelPoolDpImpl pool = | ||
| new ChannelPoolDpImpl(channelSupplier, defaultConfig, debugTagTracer, bgExecutor); | ||
|
|
||
| for (int i = 0; i < 4; i++) { | ||
| pool.newStream(FakeSessionGrpc.getOpenSessionMethod(), CallOptions.DEFAULT) | ||
| .start(mock(Listener.class), new Metadata()); | ||
| listener.getValue().onClose(Status.UNAVAILABLE, new Metadata()); | ||
|
|
||
| // Should not be recycled yet | ||
| verify(channel, times(0)).shutdown(); | ||
| verify(channelSupplier, times(1)).get(); | ||
| } | ||
|
|
||
| // 5th failure | ||
| pool.newStream(FakeSessionGrpc.getOpenSessionMethod(), CallOptions.DEFAULT) | ||
| .start(mock(Listener.class), new Metadata()); | ||
| listener.getValue().onClose(Status.UNAVAILABLE, new Metadata()); | ||
|
|
||
| // Now it should be recycled | ||
| verify(channel, times(1)).shutdown(); | ||
| verify(channelSupplier, times(2)).get(); | ||
|
|
||
| pool.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void testResetConsecutiveFailuresOnSuccess() { | ||
| when(channelSupplier.get()).thenReturn(channel); | ||
| when(channel.newCall(any(), any())).thenReturn(clientCall); | ||
| doNothing().when(clientCall).start(listener.capture(), any()); | ||
| doReturn(Attributes.EMPTY).when(clientCall).getAttributes(); | ||
|
|
||
| ChannelPoolDpImpl pool = | ||
| new ChannelPoolDpImpl(channelSupplier, defaultConfig, debugTagTracer, bgExecutor); | ||
|
|
||
| // 4 failures | ||
| for (int i = 0; i < 4; i++) { | ||
| pool.newStream(FakeSessionGrpc.getOpenSessionMethod(), CallOptions.DEFAULT) | ||
| .start(mock(Listener.class), new Metadata()); | ||
| listener.getValue().onClose(Status.UNAVAILABLE, new Metadata()); | ||
| } | ||
| verify(channel, times(0)).shutdown(); | ||
|
|
||
| // A success: onHeaders (which calls onBeforeSessionStart) | ||
| pool.newStream(FakeSessionGrpc.getOpenSessionMethod(), CallOptions.DEFAULT) | ||
| .start(mock(Listener.class), new Metadata()); | ||
|
|
||
| PeerInfo peerInfo = PeerInfo.newBuilder().setApplicationFrontendId(555).build(); | ||
| Metadata headers = new Metadata(); | ||
| headers.put( | ||
| SessionStreamImpl.PEER_INFO_KEY, | ||
| Base64.getEncoder().encodeToString(peerInfo.toByteArray())); | ||
| listener.getValue().onHeaders(headers); | ||
| listener.getValue().onClose(Status.OK, new Metadata()); | ||
|
|
||
| // Another 4 failures - should still not recycle because counter was reset | ||
| for (int i = 0; i < 4; i++) { | ||
| pool.newStream(FakeSessionGrpc.getOpenSessionMethod(), CallOptions.DEFAULT) | ||
| .start(mock(Listener.class), new Metadata()); | ||
| listener.getValue().onClose(Status.UNAVAILABLE, new Metadata()); | ||
| } | ||
| verify(channel, times(0)).shutdown(); | ||
|
|
||
| pool.close(); | ||
| } | ||
|
|
||
| @Test | ||
| void testCancelledDoesNotIncrementFailures() { | ||
| when(channelSupplier.get()).thenReturn(channel); | ||
| when(channel.newCall(any(), any())).thenReturn(clientCall); | ||
| doNothing().when(clientCall).start(listener.capture(), any()); | ||
|
|
||
| ChannelPoolDpImpl pool = | ||
| new ChannelPoolDpImpl(channelSupplier, defaultConfig, debugTagTracer, bgExecutor); | ||
|
|
||
| for (int i = 0; i < 10; i++) { | ||
| pool.newStream(FakeSessionGrpc.getOpenSessionMethod(), CallOptions.DEFAULT) | ||
| .start(mock(Listener.class), new Metadata()); | ||
| listener.getValue().onClose(Status.CANCELLED, new Metadata()); | ||
| } | ||
|
|
||
| // Should never be recycled | ||
| verify(channel, times(0)).shutdown(); | ||
| verify(channelSupplier, times(1)).get(); | ||
|
|
||
| pool.close(); | ||
| } | ||
|
Contributor
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. Should we add a test to verify that if there's a channel that's recently recycled, don't trigger recycle on failure?
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. oh, you mean test for the backoff?
Contributor
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. Yeah, just a test to make sure the guardrail on recycling actually works? |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.