Skip to content

Commit

Permalink
Merge pull request #23 from microsoft/philon/merge-from-ser
Browse files Browse the repository at this point in the history
Merge latest changes from StackExchange.Redis
  • Loading branch information
philon-msft authored Jun 17, 2021
2 parents 79067f3 + dd3b15d commit 5e1a506
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
1 change: 1 addition & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- performance optimization for PING accuracy (#1714 via eduardobr)
- improvement to reconnect logic (exponential backoff) (#1735 via deepakverma)
- refresh replica endpoint list on failover (#1684 by laurauzcategui)

## 2.2.4

Expand Down
18 changes: 15 additions & 3 deletions src/StackExchange.Redis/ConnectionMultiplexer.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,19 @@ private async Task<EndPointCollection> GetEndpointsFromClusterNodes(ServerEndPoi
try
{
var clusterConfig = await ExecuteAsyncImpl(message, ResultProcessor.ClusterNodes, null, server).ForAwait();
return new EndPointCollection(clusterConfig.Nodes.Select(node => node.EndPoint).ToList());
var clusterEndpoints = new EndPointCollection(clusterConfig.Nodes.Select(node => node.EndPoint).ToList());
// Loop through nodes in the cluster and update nodes relations to other nodes
ServerEndPoint serverEndpoint = null;
foreach (EndPoint endpoint in clusterEndpoints)
{
serverEndpoint = GetServerEndPoint(endpoint);
if (serverEndpoint != null)
{
serverEndpoint.UpdateNodeRelations(clusterConfig);
}

}
return clusterEndpoints;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -2564,8 +2576,8 @@ public ConnectionMultiplexer GetSentinelMasterConnection(ConfigurationOptions co

lock (sentinelConnectionChildren)
{
if (sentinelConnectionChildren.ContainsKey(config.ServiceName) && !sentinelConnectionChildren[config.ServiceName].IsDisposed)
return sentinelConnectionChildren[config.ServiceName];
if (sentinelConnectionChildren.TryGetValue(config.ServiceName, out var sentinelConnectionChild) && !sentinelConnectionChild.IsDisposed)
return sentinelConnectionChild;
}

bool success = false;
Expand Down
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/Interfaces/IBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IBatch : IDatabaseAsync
{
/// <summary>
/// Execute the batch operation, sending all queued commands to the server.
/// Note that this operation is neither synchronous nor truly asyncronous - it
/// Note that this operation is neither synchronous nor truly asynchronous - it
/// simply enqueues the buffered messages. To check on completion, you should
/// check the individual responses.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/ResultProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2081,7 +2081,7 @@ public override bool SetResult(PhysicalConnection connection, Message message, i
{
if (result.StartsWith(CommonReplies.authFail_trimmed) || result.StartsWith(CommonReplies.NOAUTH))
{
connection.RecordConnectionFailed(ConnectionFailureType.AuthenticationFailure, new Exception(result.ToString() + " Verify if the Redis password provided is correct."));
connection.RecordConnectionFailed(ConnectionFailureType.AuthenticationFailure, new Exception(result.ToString() + " Verify if the Redis password provided is correct. Attempted command: " + message.Command));
}
else if (result.StartsWith(CommonReplies.loading))
{
Expand Down
38 changes: 22 additions & 16 deletions src/StackExchange.Redis/ServerEndPoint.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -196,26 +196,32 @@ public void SetClusterConfiguration(ClusterConfiguration configuration)
Multiplexer.Trace("Updating cluster ranges...");
Multiplexer.UpdateClusterRange(configuration);
Multiplexer.Trace("Resolving genealogy...");
var thisNode = configuration.Nodes.FirstOrDefault(x => x.EndPoint.Equals(EndPoint));
if (thisNode != null)
UpdateNodeRelations(configuration);
Multiplexer.Trace("Cluster configured");
}
}

public void UpdateNodeRelations(ClusterConfiguration configuration)
{
var thisNode = configuration.Nodes.FirstOrDefault(x => x.EndPoint.Equals(EndPoint));
if (thisNode != null)
{
Multiplexer.Trace($"Updating node relations for {thisNode.EndPoint.ToString()}...");
List<ServerEndPoint> replicas = null;
ServerEndPoint master = null;
foreach (var node in configuration.Nodes)
{
List<ServerEndPoint> replicas = null;
ServerEndPoint master = null;
foreach (var node in configuration.Nodes)
if (node.NodeId == thisNode.ParentNodeId)
{
master = Multiplexer.GetServerEndPoint(node.EndPoint);
}
else if (node.ParentNodeId == thisNode.NodeId)
{
if (node.NodeId == thisNode.ParentNodeId)
{
master = Multiplexer.GetServerEndPoint(node.EndPoint);
}
else if (node.ParentNodeId == thisNode.NodeId)
{
(replicas ?? (replicas = new List<ServerEndPoint>())).Add(Multiplexer.GetServerEndPoint(node.EndPoint));
}
(replicas ?? (replicas = new List<ServerEndPoint>())).Add(Multiplexer.GetServerEndPoint(node.EndPoint));
}
Master = master;
Replicas = replicas?.ToArray() ?? Array.Empty<ServerEndPoint>();
}
Multiplexer.Trace("Cluster configured");
Master = master;
Replicas = replicas?.ToArray() ?? Array.Empty<ServerEndPoint>();
}
}

Expand Down

0 comments on commit 5e1a506

Please sign in to comment.