-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Make primary channel failover timeout configurable #39646
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
Open
parveensania
wants to merge
5
commits into
apache:master
Choose a base branch
from
parveensania:dp-timeout
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f2700d6
Make primary channel timeout configurable
parveensania ce6df3c
Merge branch 'apache:master' into dp-timeout
parveensania 3becc91
Update setting name primary_not_ready_wait_nanos to directpath_primar…
parveensania cece286
Addresing review comments
parveensania 046502e
Trigger CI
parveensania 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
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
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
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 |
|---|---|---|
|
|
@@ -87,7 +87,8 @@ private static FailoverChannel createForTest( | |
| fallback, | ||
| fallbackCallCredentials, | ||
| nanoClock, | ||
| rpcFailureThresholdNanos != null ? rpcFailureThresholdNanos : 0L); | ||
| rpcFailureThresholdNanos != null ? rpcFailureThresholdNanos : 0L, | ||
| () -> TimeUnit.SECONDS.toNanos(10)); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -290,6 +291,91 @@ public void testStateFallbackAfterPrimaryNotReady() { | |
| verify(mockFallbackChannel).newCall(any(), any()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTimeoutThresholdDecreaseTriggersFallbackEarlier() { | ||
| ManagedChannel mockChannel = mock(ManagedChannel.class); | ||
| ManagedChannel mockFallbackChannel = mock(ManagedChannel.class); | ||
| when(mockChannel.newCall(any(), any())).thenReturn(mock(ClientCall.class)); | ||
| when(mockFallbackChannel.newCall(any(), any())).thenReturn(mock(ClientCall.class)); | ||
| // Simulate primary being TRANSIENT_FAILURE from the start. | ||
| when(mockChannel.getState(false)).thenReturn(ConnectivityState.TRANSIENT_FAILURE); | ||
|
|
||
| AtomicLong time = new AtomicLong(0); | ||
| // Start with 10s timeout | ||
| AtomicLong timeoutThreshold = new AtomicLong(TimeUnit.SECONDS.toNanos(10)); | ||
|
|
||
| // Constructor seeds timer at time=0. | ||
| FailoverChannel failoverChannel = | ||
| FailoverChannel.forTest( | ||
| mockChannel, mockFallbackChannel, null, time::get, 0L, timeoutThreshold::get); | ||
|
|
||
| // Call at time=0. elapsed 0 <= 10s -> false. | ||
| failoverChannel.newCall(methodDescriptor, CallOptions.DEFAULT); | ||
| verify(mockChannel).newCall(any(), any()); | ||
|
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. can you verify no new interactions on the channel not used for all of these? |
||
|
|
||
| // Advance time by 5 seconds. | ||
| time.addAndGet(TimeUnit.SECONDS.toNanos(5)); | ||
|
|
||
| // Call at time=5s. elapsed 5s <= 10s -> false. | ||
| // Primary is used. | ||
| failoverChannel.newCall(methodDescriptor, CallOptions.DEFAULT); | ||
| verify(mockChannel, org.mockito.Mockito.times(2)).newCall(any(), any()); | ||
|
|
||
| // Decrease threshold to 2 seconds. | ||
| timeoutThreshold.set(TimeUnit.SECONDS.toNanos(2)); | ||
|
|
||
| // Call at time=5s. elapsed 5s > 2s -> true. | ||
| // Fallback is used. | ||
| failoverChannel.newCall(methodDescriptor, CallOptions.DEFAULT); | ||
| verify(mockFallbackChannel).newCall(any(), any()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTimeoutThresholdIncreaseDelaysFallback() { | ||
| ManagedChannel mockChannel = mock(ManagedChannel.class); | ||
| ManagedChannel mockFallbackChannel = mock(ManagedChannel.class); | ||
| when(mockChannel.newCall(any(), any())).thenReturn(mock(ClientCall.class)); | ||
| when(mockFallbackChannel.newCall(any(), any())).thenReturn(mock(ClientCall.class)); | ||
| // Simulate primary being TRANSIENT_FAILURE from the start. | ||
| when(mockChannel.getState(false)).thenReturn(ConnectivityState.TRANSIENT_FAILURE); | ||
|
|
||
| AtomicLong time = new AtomicLong(0); | ||
| // Start with 10s timeout | ||
| AtomicLong timeoutThreshold = new AtomicLong(TimeUnit.SECONDS.toNanos(10)); | ||
|
|
||
| // Constructor seeds timer at time=0. | ||
| FailoverChannel failoverChannel = | ||
| FailoverChannel.forTest( | ||
| mockChannel, mockFallbackChannel, null, time::get, 0L, timeoutThreshold::get); | ||
|
|
||
| // Advance time by 9 seconds. | ||
| time.addAndGet(TimeUnit.SECONDS.toNanos(9)); | ||
|
|
||
| // Call at time=9s. elapsed 9s <= 10s -> false. | ||
| // Primary is used. | ||
| failoverChannel.newCall(methodDescriptor, CallOptions.DEFAULT); | ||
| verify(mockChannel).newCall(any(), any()); | ||
|
|
||
| // Increase threshold to 20 seconds. | ||
| timeoutThreshold.set(TimeUnit.SECONDS.toNanos(20)); | ||
|
|
||
| // Advance time by 5 seconds (total 14s). | ||
| time.addAndGet(TimeUnit.SECONDS.toNanos(5)); | ||
|
|
||
| // Call at time=14s. elapsed 14s <= 20s -> false. | ||
| // Still routes to primary because of increased threshold | ||
| failoverChannel.newCall(methodDescriptor, CallOptions.DEFAULT); | ||
| verify(mockChannel, org.mockito.Mockito.times(2)).newCall(any(), any()); | ||
|
|
||
| // Advance time by 7s (total 21s). | ||
| time.addAndGet(TimeUnit.SECONDS.toNanos(7)); | ||
|
|
||
| // Call at time=21s. elapsed 21s > 20s -> true. | ||
| // Fallback is used. | ||
| failoverChannel.newCall(methodDescriptor, CallOptions.DEFAULT); | ||
| verify(mockFallbackChannel).newCall(any(), any()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testStateFallbackWhenPrimaryStartsNonReadyWithoutTransition() { | ||
| // Primary starts in a non-ready state and stays there. Even without a state transition, | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't during registration but after notification