Commit 9019f58b authored by Antoine Cellerier's avatar Antoine Cellerier

Fix regression from 6b317395:...

Fix regression from 6b317395: clusterConfiguration[clusterConfiguration.Origin] should always reference the node contacted when running CLUSTER NODES.
parent c1cd4081
...@@ -182,9 +182,17 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s ...@@ -182,9 +182,17 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s
{ {
if (string.IsNullOrWhiteSpace(line)) continue; if (string.IsNullOrWhiteSpace(line)) continue;
var node = new ClusterNode(this, line, origin); var node = new ClusterNode(this, line, origin);
// Be resilient to ":0 {master,slave},fail,noaddr" nodes // Be resilient to ":0 {master,slave},fail,noaddr" nodes
if (node.IsNoAddr) if (node.IsNoAddr)
continue; continue;
// Override the origin value with the endpoint advertised with the target node to
// make sure that things like clusterConfiguration[clusterConfiguration.Origin]
// will work as expected.
if (node.IsMyself)
this.origin = node.EndPoint;
if (nodeLookup.ContainsKey(node.EndPoint)) if (nodeLookup.ContainsKey(node.EndPoint))
{ {
// Deal with conflicting node entries for the same endpoint // Deal with conflicting node entries for the same endpoint
...@@ -288,6 +296,8 @@ public sealed class ClusterNode : IEquatable<ClusterNode>, IComparable<ClusterN ...@@ -288,6 +296,8 @@ public sealed class ClusterNode : IEquatable<ClusterNode>, IComparable<ClusterN
private readonly EndPoint endpoint; private readonly EndPoint endpoint;
private readonly bool isMyself;
private readonly bool isSlave; private readonly bool isSlave;
private readonly bool isNoAddr; private readonly bool isNoAddr;
...@@ -315,11 +325,15 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or ...@@ -315,11 +325,15 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or
var flags = parts[2].Split(StringSplits.Comma); var flags = parts[2].Split(StringSplits.Comma);
endpoint = Format.TryParseEndPoint(parts[1]); endpoint = Format.TryParseEndPoint(parts[1]);
if (endpoint == null && flags.Contains("myself")) if (flags.Contains("myself"))
{ {
// Unconfigured cluster nodes might report themselves as endpoint ":{port}", isMyself = true;
// hence the origin fallback value to make sure that we can address them if (endpoint == null)
endpoint = origin; {
// Unconfigured cluster nodes might report themselves as endpoint ":{port}",
// hence the origin fallback value to make sure that we can address them
endpoint = origin;
}
} }
nodeId = parts[0]; nodeId = parts[0];
...@@ -369,6 +383,11 @@ public IList<ClusterNode> Children ...@@ -369,6 +383,11 @@ public IList<ClusterNode> Children
/// </summary> /// </summary>
public EndPoint EndPoint { get { return endpoint; } } public EndPoint EndPoint { get { return endpoint; } }
/// <summary>
/// Gets whether this is the node which responded to the CLUSTER NODES request
/// </summary>
public bool IsMyself { get { return isMyself; } }
/// <summary> /// <summary>
/// Gets whether this node is a slave /// Gets whether this node is a slave
/// </summary> /// </summary>
......
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