Commit 2e5923b0 authored by Nick Craver's avatar Nick Craver

Misc cleanup (including line endings for some)

parent d5fff16f
...@@ -103,7 +103,7 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e) ...@@ -103,7 +103,7 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e)
} }
private int privateFailCount; private int privateFailCount;
private static AsyncLocal<int> sharedFailCount = new AsyncLocal<int>(); private static readonly AsyncLocal<int> sharedFailCount = new AsyncLocal<int>();
private volatile int expectedFailCount; private volatile int expectedFailCount;
private readonly List<string> privateExceptions = new List<string>(); private readonly List<string> privateExceptions = new List<string>();
......
...@@ -97,8 +97,8 @@ public static bool TryParse(string range, out SlotRange value) ...@@ -97,8 +97,8 @@ public static bool TryParse(string range, out SlotRange value)
/// <param name="other">The other slot range to compare to.</param> /// <param name="other">The other slot range to compare to.</param>
public int CompareTo(SlotRange other) public int CompareTo(SlotRange other)
{ {
int delta = (int)this.from - (int)other.from; int delta = (int)from - (int)other.from;
return delta == 0 ? (int)this.to - (int)other.to : delta; return delta == 0 ? (int)to - (int)other.to : delta;
} }
/// <summary> /// <summary>
...@@ -161,7 +161,7 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s ...@@ -161,7 +161,7 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s
{ {
// Beware: Any exception thrown here will wreak silent havoc like inability to connect to cluster nodes or non returning calls // Beware: Any exception thrown here will wreak silent havoc like inability to connect to cluster nodes or non returning calls
this.serverSelectionStrategy = serverSelectionStrategy; this.serverSelectionStrategy = serverSelectionStrategy;
this.Origin = origin; Origin = origin;
using (var reader = new StringReader(nodes)) using (var reader = new StringReader(nodes))
{ {
string line; string line;
...@@ -178,7 +178,7 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s ...@@ -178,7 +178,7 @@ internal ClusterConfiguration(ServerSelectionStrategy serverSelectionStrategy, s
// make sure that things like clusterConfiguration[clusterConfiguration.Origin] // make sure that things like clusterConfiguration[clusterConfiguration.Origin]
// will work as expected. // will work as expected.
if (node.IsMyself) if (node.IsMyself)
this.Origin = node.EndPoint; Origin = node.EndPoint;
if (nodeLookup.ContainsKey(node.EndPoint)) if (nodeLookup.ContainsKey(node.EndPoint))
{ {
...@@ -286,7 +286,7 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or ...@@ -286,7 +286,7 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or
{ {
// https://redis.io/commands/cluster-nodes // https://redis.io/commands/cluster-nodes
this.configuration = configuration; this.configuration = configuration;
this.Raw = raw; Raw = raw;
var parts = raw.Split(StringSplits.Space); var parts = raw.Split(StringSplits.Space);
var flags = parts[2].Split(StringSplits.Comma); var flags = parts[2].Split(StringSplits.Comma);
...@@ -319,8 +319,7 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or ...@@ -319,8 +319,7 @@ internal ClusterNode(ClusterConfiguration configuration, string raw, EndPoint or
{ {
if (SlotRange.TryParse(parts[i], out SlotRange range)) if (SlotRange.TryParse(parts[i], out SlotRange range))
{ {
if (slots == null) slots = new List<SlotRange>(parts.Length - i); (slots ?? (slots = new List<SlotRange>(parts.Length - i))).Add(range);
slots.Add(range);
} }
} }
Slots = slots?.AsReadOnly() ?? NoSlots; Slots = slots?.AsReadOnly() ?? NoSlots;
...@@ -338,10 +337,9 @@ public IList<ClusterNode> Children ...@@ -338,10 +337,9 @@ public IList<ClusterNode> Children
List<ClusterNode> nodes = null; List<ClusterNode> nodes = null;
foreach (var node in configuration.Nodes) foreach (var node in configuration.Nodes)
{ {
if (node.ParentNodeId == this.NodeId) if (node.ParentNodeId == NodeId)
{ {
if (nodes == null) nodes = new List<ClusterNode>(); (nodes ?? (nodes = new List<ClusterNode>())).Add(node);
nodes.Add(node);
} }
} }
children = nodes?.AsReadOnly() ?? NoNodes; children = nodes?.AsReadOnly() ?? NoNodes;
...@@ -416,14 +414,14 @@ public int CompareTo(ClusterNode other) ...@@ -416,14 +414,14 @@ public int CompareTo(ClusterNode other)
{ {
if (other == null) return -1; if (other == null) return -1;
if (this.IsSlave != other.IsSlave) return IsSlave ? 1 : -1; // masters first if (IsSlave != other.IsSlave) return IsSlave ? 1 : -1; // masters first
if (IsSlave) // both slaves? compare by parent, so we get masters A, B, C and then slaves of A, B, C if (IsSlave) // both slaves? compare by parent, so we get masters A, B, C and then slaves of A, B, C
{ {
int i = string.CompareOrdinal(this.ParentNodeId, other.ParentNodeId); int i = string.CompareOrdinal(ParentNodeId, other.ParentNodeId);
if (i != 0) return i; if (i != 0) return i;
} }
return string.CompareOrdinal(this.NodeId, other.NodeId); return string.CompareOrdinal(NodeId, other.NodeId);
} }
/// <summary> /// <summary>
......
...@@ -98,7 +98,7 @@ internal static string TryGetAzureRoleInstanceIdNoThrow() ...@@ -98,7 +98,7 @@ internal static string TryGetAzureRoleInstanceIdNoThrow()
var currentRoleInstanceId = currentRoleInstanceProp.GetValue(null, null); var currentRoleInstanceId = currentRoleInstanceProp.GetValue(null, null);
roleInstanceId = currentRoleInstanceId.GetType().GetProperty("Id").GetValue(currentRoleInstanceId, null).ToString(); roleInstanceId = currentRoleInstanceId.GetType().GetProperty("Id").GetValue(currentRoleInstanceId, null).ToString();
if (String.IsNullOrEmpty(roleInstanceId)) if (string.IsNullOrEmpty(roleInstanceId))
{ {
roleInstanceId = null; roleInstanceId = null;
} }
...@@ -2050,7 +2050,7 @@ void add(string lk, string sk, string v) ...@@ -2050,7 +2050,7 @@ void add(string lk, string sk, string v)
add("Client-Name", "clientName", ClientName); add("Client-Name", "clientName", ClientName);
add("Server-Endpoint", "serverEndpoint", server.EndPoint.ToString()); add("Server-Endpoint", "serverEndpoint", server.EndPoint.ToString());
var hashSlot = message.GetHashSlot(this.ServerSelectionStrategy); var hashSlot = message.GetHashSlot(ServerSelectionStrategy);
// only add keyslot if its a valid cluster key slot // only add keyslot if its a valid cluster key slot
if (hashSlot != ServerSelectionStrategy.NoSlot) if (hashSlot != ServerSelectionStrategy.NoSlot)
{ {
......
...@@ -199,7 +199,7 @@ public void SetClusterConfiguration(ClusterConfiguration configuration) ...@@ -199,7 +199,7 @@ public void SetClusterConfiguration(ClusterConfiguration configuration)
multiplexer.Trace("Updating cluster ranges..."); multiplexer.Trace("Updating cluster ranges...");
multiplexer.UpdateClusterRange(configuration); multiplexer.UpdateClusterRange(configuration);
multiplexer.Trace("Resolving genealogy..."); multiplexer.Trace("Resolving genealogy...");
var thisNode = configuration.Nodes.FirstOrDefault(x => x.EndPoint.Equals(this.EndPoint)); var thisNode = configuration.Nodes.FirstOrDefault(x => x.EndPoint.Equals(EndPoint));
if (thisNode != null) if (thisNode != null)
{ {
List<ServerEndPoint> slaves = null; List<ServerEndPoint> slaves = null;
...@@ -212,8 +212,7 @@ public void SetClusterConfiguration(ClusterConfiguration configuration) ...@@ -212,8 +212,7 @@ public void SetClusterConfiguration(ClusterConfiguration configuration)
} }
else if (node.ParentNodeId == thisNode.NodeId) else if (node.ParentNodeId == thisNode.NodeId)
{ {
if (slaves == null) slaves = new List<ServerEndPoint>(); (slaves ?? (slaves = new List<ServerEndPoint>())).Add(multiplexer.GetServerEndPoint(node.EndPoint));
slaves.Add(multiplexer.GetServerEndPoint(node.EndPoint));
} }
} }
Master = master; Master = master;
......
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