Skip to content

Commit

Permalink
Update SplitBrainResolver.cs (#3266)
Browse files Browse the repository at this point in the history
* Fix exception that can occur when remaining and unreachable variables both have zero elements
  • Loading branch information
mrrd authored and Aaronontheweb committed Jan 11, 2018
1 parent 44dd71f commit fb13b33
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/core/Akka.Cluster/SplitBrainResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,14 @@ public IEnumerable<Member> Apply(NetworkPartitionContext context)
var unreachable = MembersWithRole(context.Unreachable);

if (remaining.Count < unreachable.Count) return context.Remaining;
else if (remaining.Count > unreachable.Count) return context.Unreachable;
else
{
// if the parts are of equal size the part containing the node with the lowest address is kept.
var oldest = remaining.Union(unreachable).First();
return remaining.Contains(oldest)
? context.Unreachable
: context.Remaining;
}
if (remaining.Count > unreachable.Count) return context.Unreachable;
if (remaining.IsEmpty && unreachable.IsEmpty) return new Member[0];

// if the parts are of equal size the part containing the node with the lowest address is kept.
var oldest = remaining.Union(unreachable).First();
return remaining.Contains(oldest)
? context.Unreachable
: context.Remaining;
}

private ImmutableSortedSet<Member> MembersWithRole(ImmutableSortedSet<Member> members) => string.IsNullOrEmpty(Role)
Expand Down Expand Up @@ -341,4 +340,4 @@ private void ResetStabilityTimeout()
_stabilityTask = Context.System.Scheduler.ScheduleTellOnceCancelable(_stabilityTimeout, Self, StabilityReached.Instance, ActorRefs.NoSender);
}
}
}
}

0 comments on commit fb13b33

Please sign in to comment.