Commit 33072cb8 authored by Marc Gravell's avatar Marc Gravell

Merge pull request #331 from antoinecellerier/cluster-fixes

Fix cluster configuration regressions from 6b317395
parents c0d064f5 9019f58b
......@@ -182,9 +182,17 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s
{
if (string.IsNullOrWhiteSpace(line)) continue;
var node = new ClusterNode(this, line, origin);
// Be resilient to ":0 {master,slave},fail,noaddr" nodes
if (node.IsNoAddr)
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))
{
// Deal with conflicting node entries for the same endpoint
......@@ -288,6 +296,8 @@ public sealed class ClusterNode : IEquatable<ClusterNode>, IComparable<ClusterN
private readonly EndPoint endpoint;
private readonly bool isMyself;
private readonly bool isSlave;
private readonly bool isNoAddr;
......@@ -315,7 +325,17 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or
var flags = parts[2].Split(StringSplits.Comma);
endpoint = Format.TryParseEndPoint(parts[1]);
if (flags.Contains("myself"))
{
isMyself = true;
if (endpoint == null)
{
// 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];
isSlave = flags.Contains("slave");
isNoAddr = flags.Contains("noaddr");
......@@ -363,6 +383,11 @@ public IList<ClusterNode> Children
/// </summary>
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>
/// Gets whether this node is a slave
/// </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