-
Notifications
You must be signed in to change notification settings - Fork 2.2k
App Config - Startup retry #47857
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?
App Config - Startup retry #47857
Changes from all commits
3a43016
1a87bd9
6c2a36e
dc1db90
89f36c4
29368b5
3e187f7
f28db8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -242,6 +242,43 @@ void backoffClient(String endpoint) { | |
| autoFailoverClients.get(endpoint).updateBackoffEndTime(Instant.now().plusNanos(backoffTime)); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the duration in milliseconds until the next client becomes available (exits backoff). | ||
| * Returns 0 if a client is already available, or the minimum wait time if all clients are in backoff. | ||
| * | ||
| * @return duration in milliseconds until next client is available, or 0 if one is available now | ||
| */ | ||
| long getMillisUntilNextClientAvailable() { | ||
| Instant now = Instant.now(); | ||
| Instant earliestAvailable = Instant.MAX; | ||
|
|
||
| // Check configured clients | ||
| if (clients != null) { | ||
| for (AppConfigurationReplicaClient client : clients) { | ||
| Instant backoffEnd = client.getBackoffEndTime(); | ||
| if (!backoffEnd.isAfter(now)) { | ||
| return 0; // Client available now | ||
| } | ||
| if (backoffEnd.isBefore(earliestAvailable)) { | ||
| earliestAvailable = backoffEnd; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Check auto-failover clients | ||
| for (AppConfigurationReplicaClient client : autoFailoverClients.values()) { | ||
| Instant backoffEnd = client.getBackoffEndTime(); | ||
| if (!backoffEnd.isAfter(now)) { | ||
| return 0; // Client available now | ||
| } | ||
| if (backoffEnd.isBefore(earliestAvailable)) { | ||
| earliestAvailable = backoffEnd; | ||
| } | ||
| } | ||
|
|
||
| return earliestAvailable.toEpochMilli() - now.toEpochMilli(); | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
Comment on lines
+251
to
+280
|
||
|
|
||
| /** | ||
| * Updates the synchronization token for the specified client endpoint. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,11 @@ public class AppConfigurationProperties { | |
|
|
||
| private Duration refreshInterval; | ||
|
|
||
| /** | ||
| * The timeout duration for retry attempts during startup. | ||
| */ | ||
| private Duration startupTimeout = Duration.ofSeconds(100); | ||
|
|
||
| /** | ||
| * @return the enabled | ||
| */ | ||
|
|
@@ -78,6 +83,20 @@ public void setRefreshInterval(Duration refreshInterval) { | |
| this.refreshInterval = refreshInterval; | ||
| } | ||
|
|
||
| /** | ||
| * @return the startupTimeout | ||
| */ | ||
| public Duration getStartupTimeout() { | ||
| return startupTimeout; | ||
| } | ||
|
|
||
| /** | ||
| * @param startupTimeout the startupTimeout to set | ||
| */ | ||
| public void setStartupTimeout(Duration startupTimeout) { | ||
| this.startupTimeout = startupTimeout; | ||
| } | ||
|
|
||
| /** | ||
| * Validates at least one store is configured for use, and that they are valid. | ||
| * @throws IllegalArgumentException when duplicate endpoints are configured | ||
|
|
@@ -115,5 +134,11 @@ public void validateAndInit() { | |
| if (refreshInterval != null) { | ||
| Assert.isTrue(refreshInterval.getSeconds() >= 1, "Minimum refresh interval time is 1 Second."); | ||
| } | ||
mrm9084 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (startupTimeout == null) { | ||
| throw new IllegalArgumentException("startupTimeout cannot be null."); | ||
| } | ||
| if (startupTimeout.getSeconds() < 30 || startupTimeout.getSeconds() > 600) { | ||
| throw new IllegalArgumentException("startupTimeout must be between 30 and 600 seconds."); | ||
| } | ||
|
Comment on lines
+137
to
+142
|
||
| } | ||
| } | ||
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.
The method
getMillisUntilNextClientAvailableis not used anywhere in the production code. It's only called in tests. This suggests that either the method should be removed as dead code, or it should be integrated into the retry logic. Consider removing this method or using it in the startup retry implementation.