Commit aa198df8 authored by Marc Gravell's avatar Marc Gravell

Apply per-primary round-robin when selecting replicas - fix #610

parent d33ccfab
...@@ -341,6 +341,10 @@ internal void AutoConfigure(PhysicalConnection connection) ...@@ -341,6 +341,10 @@ internal void AutoConfigure(PhysicalConnection connection)
} }
} }
int _nextReplicaOffset;
internal uint NextReplicaOffset() // used to round-robin between multiple replicas
=> (uint) System.Threading.Interlocked.Increment(ref _nextReplicaOffset);
internal Task Close() internal Task Close()
{ {
var tmp = interactive; var tmp = interactive;
......
...@@ -240,9 +240,11 @@ private ServerEndPoint FindSlave(ServerEndPoint endpoint, RedisCommand command) ...@@ -240,9 +240,11 @@ private ServerEndPoint FindSlave(ServerEndPoint endpoint, RedisCommand command)
if (endpoint.IsSlave && endpoint.IsSelectable(command)) return endpoint; if (endpoint.IsSlave && endpoint.IsSelectable(command)) return endpoint;
var slaves = endpoint.Slaves; var slaves = endpoint.Slaves;
for (int i = 0; i < slaves.Length; i++) var len = slaves.Length;
uint startOffset = len <= 1 ? 0 : endpoint.NextReplicaOffset();
for (int i = 0; i < len; i++)
{ {
endpoint = slaves[i]; endpoint = slaves[(int)(((uint)i + startOffset) % len)];
if (endpoint.IsSlave && endpoint.IsSelectable(command)) return endpoint; if (endpoint.IsSlave && endpoint.IsSelectable(command)) return endpoint;
} }
return null; return null;
......
# Release Notes # Release Notes
## 1.2.3
- fix: when using `redis-cluster` with multiple replicas, use round-robin when selecting replica (#610)
## 1.2.2 (preview): ## 1.2.2 (preview):
- **UNAVAILABLE**: .NET 4.0 support is not in this build, due to [a build issue](https://github.com/dotnet/cli/issues/5993) - looking into solutions - **UNAVAILABLE**: .NET 4.0 support is not in this build, due to [a build issue](https://github.com/dotnet/cli/issues/5993) - looking into solutions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment