-
Notifications
You must be signed in to change notification settings - Fork 4k
Move name resolution retry from managed channel to name resolver (take #2) #9812
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9e25431
Name resolution retry from channel to name resolver
temawi e648cb6
Review feedback changes.
temawi 76a0f28
Fix problem with calling wrong refreshNameResolution()
temawi 55962ba
More precise use of DnsNameResolver in tests
temawi 6e269f8
Review feedback
temawi 72b8400
Call callback in NamesResolved.
temawi 18c215d
ManagedChannelImpl to wrap the NameResolver
temawi 31dcdc3
BackoffPolicyRetryScheduler uses sync context to serialize
temawi db466e3
Fail RetryingNameResolver if double-wrapped
temawi d0110be
BackoffPolicyRetryScheduler only usable within a sync context
temawi a01b4b9
Retry when initial service config is invalid
temawi 25d50e8
Don't call listener if NR already shut down
temawi 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
85 changes: 85 additions & 0 deletions
85
core/src/main/java/io/grpc/internal/BackoffPolicyRetryScheduler.java
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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Copyright 2023 The gRPC Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.grpc.internal; | ||
|
|
||
| import io.grpc.SynchronizationContext; | ||
| import io.grpc.SynchronizationContext.ScheduledHandle; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| /** | ||
| * Schedules a retry operation according to a {@link BackoffPolicy}. The retry is run within a | ||
| * {@link SynchronizationContext}. At most one retry is scheduled at a time. | ||
| */ | ||
| final class BackoffPolicyRetryScheduler implements RetryScheduler { | ||
| private final ScheduledExecutorService scheduledExecutorService; | ||
| private final SynchronizationContext syncContext; | ||
| private final BackoffPolicy.Provider policyProvider; | ||
|
|
||
| private BackoffPolicy policy; | ||
| private ScheduledHandle scheduledHandle; | ||
|
|
||
| private static final Logger logger = Logger.getLogger( | ||
| BackoffPolicyRetryScheduler.class.getName()); | ||
|
|
||
| BackoffPolicyRetryScheduler(BackoffPolicy.Provider policyProvider, | ||
| ScheduledExecutorService scheduledExecutorService, | ||
| SynchronizationContext syncContext) { | ||
| this.policyProvider = policyProvider; | ||
| this.scheduledExecutorService = scheduledExecutorService; | ||
| this.syncContext = syncContext; | ||
| } | ||
|
|
||
| /** | ||
| * Schedules a future retry operation. Only allows one retry to be scheduled at any given time. | ||
| */ | ||
| @Override | ||
| public void schedule(Runnable retryOperation) { | ||
| syncContext.throwIfNotInThisSynchronizationContext(); | ||
|
|
||
| if (policy == null) { | ||
| policy = policyProvider.get(); | ||
| } | ||
| // If a retry is already scheduled, take no further action. | ||
| if (scheduledHandle != null && scheduledHandle.isPending()) { | ||
| return; | ||
| } | ||
| long delayNanos = policy.nextBackoffNanos(); | ||
| scheduledHandle = syncContext.schedule(retryOperation, delayNanos, TimeUnit.NANOSECONDS, | ||
| scheduledExecutorService); | ||
| logger.log(Level.FINE, "Scheduling DNS resolution backoff for {0}ns", delayNanos); | ||
| } | ||
|
|
||
| /** | ||
| * Resets the {@link BackoffPolicyRetryScheduler} and cancels any pending retry task. The policy | ||
| * will be cleared thus also resetting any state associated with it (e.g. a backoff multiplier). | ||
| */ | ||
| @Override | ||
| public void reset() { | ||
| syncContext.throwIfNotInThisSynchronizationContext(); | ||
|
|
||
| syncContext.execute(() -> { | ||
| if (scheduledHandle != null && scheduledHandle.isPending()) { | ||
| scheduledHandle.cancel(); | ||
| } | ||
| policy = null; | ||
| }); | ||
| } | ||
|
|
||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright 2023 The gRPC Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.grpc.internal; | ||
|
|
||
| /** | ||
| * This interface is used to schedule future retry attempts for a failed operation. The retry delay | ||
| * and the number of attempt is defined by implementing classes. Implementations should assure | ||
| * that only one future retry operation is ever scheduled at a time. | ||
| */ | ||
| public interface RetryScheduler { | ||
|
|
||
| /** | ||
| * A request to schedule a future retry (or retries) for a failed operation. Noop if an operation | ||
| * has already been scheduled. | ||
| */ | ||
| void schedule(Runnable retryOperation); | ||
|
|
||
| /** | ||
| * Resets the scheduler, effectively cancelling any future retry operation. | ||
| */ | ||
| void reset(); | ||
| } |
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.