Repository navigation
fix(zookeeper): make membership reads sequential and resilient #11338
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
ReubenBond
merged 10 commits into
dotnet:main
from
ReubenBond:rb-zookeeper-connection-loss-retries
Sep 21, 2026
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
51fb59a
fix(zookeeper): retry connection-loss reads safely
ReubenBond d1b8f96
test(zookeeper): retain diagnostics through native teardown
ReubenBond bb3c319
test(zookeeper): observe actual legacy operation completion
ReubenBond 2af4afe
test(zookeeper): archive native read retry diagnostics
ReubenBond e995372
fix(zookeeper): preserve owner completion and failures
ReubenBond b865783
test(zookeeper): capture primary failure before teardown
ReubenBond 8dda170
fix(zookeeper): wait for reconnect before read retries
ReubenBond 2b295d6
fix(zookeeper): serialize reconnect recovery reads
ReubenBond 5856ccd
fix(zookeeper): read membership rows sequentially
ReubenBond 0972cfa
docs(zookeeper): clarify bounded reconnect wait
ReubenBond 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
Some comments aren't visible on the classic Files Changed page.
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
75 changes: 75 additions & 0 deletions
75
src/Orleans.Clustering.ZooKeeper/ZooKeeperReadRetryPolicy.cs
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,75 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.Logging; | ||
| using org.apache.zookeeper; | ||
| using Polly; | ||
| using Polly.Retry; | ||
|
|
||
| namespace Orleans.Runtime.Membership; | ||
|
|
||
| internal static partial class ZooKeeperReadRetryPolicy | ||
| { | ||
| internal const int MaxRetryAttempts = 4; | ||
| internal static readonly TimeSpan RetryDelay = TimeSpan.FromMilliseconds(250); | ||
|
|
||
| internal static ResiliencePipeline CreatePipeline(ILogger logger, TimeProvider timeProvider) => | ||
| new ResiliencePipelineBuilder { TimeProvider = timeProvider } | ||
| .AddRetry(new RetryStrategyOptions | ||
| { | ||
| MaxRetryAttempts = MaxRetryAttempts, | ||
| BackoffType = DelayBackoffType.Exponential, | ||
| Delay = RetryDelay, | ||
| ShouldHandle = new PredicateBuilder().Handle<KeeperException.ConnectionLossException>(), | ||
| OnRetry = args => | ||
| { | ||
| LogWarningRetryRead(logger, args.Outcome.Exception!, args.Context.OperationKey!, | ||
| args.AttemptNumber + 1, MaxRetryAttempts, args.RetryDelay.TotalMilliseconds); | ||
| return default; | ||
| } | ||
| }) | ||
| .Build(); | ||
|
|
||
| internal static ZooKeeperBasedMembershipTable.NativeOperations Wrap( | ||
| ZooKeeperBasedMembershipTable.NativeOperations native, | ||
| ResiliencePipeline pipeline, | ||
| CancellationToken cancellationToken) => | ||
| new( | ||
| path => ExecuteAsync("GetData", () => native.GetData(path), pipeline, cancellationToken), | ||
| path => ExecuteAsync("GetChildren", () => native.GetChildren(path), pipeline, cancellationToken), | ||
| path => ExecuteAsync("Sync", async () => | ||
| { | ||
| await native.Sync(path); | ||
| return true; | ||
| }, pipeline, cancellationToken), | ||
| native.Multi, | ||
| native.SetData); | ||
|
|
||
| private static async Task<T> ExecuteAsync<T>( | ||
| string operationName, | ||
| Func<Task<T>> operation, | ||
| ResiliencePipeline pipeline, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| var context = ResilienceContextPool.Shared.Get(operationName, cancellationToken); | ||
| try | ||
| { | ||
| return await pipeline.ExecuteAsync(async context => | ||
| { | ||
| context.CancellationToken.ThrowIfCancellationRequested(); | ||
| // Await actual native completion: cancellation ends admission, not an in-flight request. | ||
| return await operation(); | ||
| }, context); | ||
| } | ||
| finally | ||
| { | ||
| ResilienceContextPool.Shared.Return(context); | ||
| } | ||
| } | ||
|
|
||
| [LoggerMessage( | ||
| Level = LogLevel.Warning, | ||
| Message = "ZooKeeper {Operation} lost its connection. Retrying in {DelayMilliseconds}ms ({Retry}/{MaxRetries}).")] | ||
| private static partial void LogWarningRetryRead( | ||
| ILogger logger, Exception exception, string operation, int retry, int maxRetries, double delayMilliseconds); | ||
| } | ||
Oops, something went wrong.
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.