예제 #1
0
 internal static ImmutableHashSet <RoleLeaderChanged> DiffRolesLeader(Gossip oldGossip, Gossip newGossip, UniqueAddress selfUniqueAddress)
 {
     return(InternalDiffRolesLeader(oldGossip, newGossip, selfUniqueAddress).ToImmutableHashSet());
 }
예제 #2
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="from">TBD</param>
 public HeartbeatRsp(UniqueAddress from)
 {
     From = from;
 }
예제 #3
0
 /// <summary>
 /// Check to see if a node with the given address exists inside the heartbeat sender state.
 /// </summary>
 /// <param name="node">The node to check</param>
 /// <returns><c>true</c> if the heartbeat sender is already aware of this node. <c>false</c> otherwise.</returns>
 public bool Contains(UniqueAddress node)
 {
     return(Ring.Nodes.Contains(node));
 }
예제 #4
0
 public UniqueAddress Leader(UniqueAddress selfUniqueAddress)
 {
     return(LeaderOf(_members, selfUniqueAddress));
 }
예제 #5
0
 public bool HasMember(UniqueAddress node)
 {
     return(_membersMap.Value.ContainsKey(node));
 }
예제 #6
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="node">TBD</param>
 /// <returns>TBD</returns>
 public ClusterHeartbeatSenderState ReachableMember(UniqueAddress node)
 {
     return(MembershipChange(Ring.Copy(unreachable: Ring.Unreachable.Remove(node))));
 }
예제 #7
0
 /// <summary>
 /// Has this Gossip been seen by this node.
 /// </summary>
 public bool SeenByNode(UniqueAddress node)
 {
     return(_overview.Seen.Contains(node));
 }
예제 #8
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="observer">TBD</param>
 /// <param name="subject">TBD</param>
 /// <returns>TBD</returns>
 public Reachability Terminated(UniqueAddress observer, UniqueAddress subject)
 {
     return(Change(observer, subject, ReachabilityStatus.Terminated));
 }
예제 #9
0
        long CurrentVersion(UniqueAddress observer)
        {
            long version;

            return(_versions.TryGetValue(observer, out version) ? version : 0);
        }
예제 #10
0
 public HeartbeatNodeRing(UniqueAddress selfAddress, IEnumerable <UniqueAddress> nodes,
                          int monitoredByNumberOfNodes)
     : this(selfAddress, ImmutableSortedSet.Create(nodes.ToArray()), monitoredByNumberOfNodes)
 {
 }
예제 #11
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="observer">TBD</param>
 /// <param name="subject">TBD</param>
 /// <returns>TBD</returns>
 public Reachability Reachable(UniqueAddress observer, UniqueAddress subject)
 {
     return(Change(observer, subject, ReachabilityStatus.Reachable));
 }
예제 #12
0
 private void DoHeartbeatRsp(UniqueAddress from)
 {
     _log.Debug("Cluster Node [{0}] - Heartbeat response from [{1}]", _cluster.SelfAddress, from.Address);
     _state = _state.HeartbeatRsp(from);
 }
예제 #13
0
        internal static ImmutableList <SeenChanged> DiffSeen(Gossip oldGossip, Gossip newGossip, UniqueAddress selfUniqueAddress)
        {
            if (newGossip.Equals(oldGossip))
            {
                return(ImmutableList <SeenChanged> .Empty);
            }

            var newConvergence = newGossip.Convergence(selfUniqueAddress);
            var newSeenBy      = newGossip.SeenBy;

            if (!newConvergence.Equals(oldGossip.Convergence(selfUniqueAddress)) || !newSeenBy.SequenceEqual(oldGossip.SeenBy))
            {
                return(ImmutableList.Create(new SeenChanged(newConvergence, newSeenBy.Select(s => s.Address).ToImmutableHashSet())));
            }

            return(ImmutableList <SeenChanged> .Empty);
        }
예제 #14
0
 private static IEnumerable <RoleLeaderChanged> InternalDiffRolesLeader(Gossip oldGossip, Gossip newGossip, UniqueAddress selfUniqueAddress)
 {
     foreach (var role in oldGossip.AllRoles.Union(newGossip.AllRoles))
     {
         var newLeader = newGossip.RoleLeader(role, selfUniqueAddress);
         if (newLeader == null && oldGossip.RoleLeader(role, selfUniqueAddress) != null)
         {
             yield return(new RoleLeaderChanged(role, null));
         }
         if (newLeader != null && !newLeader.Equals(oldGossip.RoleLeader(role, selfUniqueAddress)))
         {
             yield return(new RoleLeaderChanged(role, newLeader.Address));
         }
     }
 }
예제 #15
0
 /// <summary>
 /// Creates a new <see cref="Member"/>.
 /// </summary>
 /// <param name="uniqueAddress">The address of the member.</param>
 /// <param name="upNumber">The upNumber of the member, as assigned by the leader at the time the node joined the cluster.</param>
 /// <param name="status">The status of this member.</param>
 /// <param name="roles">The roles for this member. Can be empty.</param>
 /// <param name="appVersion">Application version</param>
 /// <returns>A new member instance.</returns>
 internal static Member Create(UniqueAddress uniqueAddress, int upNumber, MemberStatus status, ImmutableHashSet <string> roles, AppVersion appVersion)
 {
     return(new Member(uniqueAddress, upNumber, status, roles, appVersion));
 }
예제 #16
0
 long NextVersion(UniqueAddress observer)
 {
     return(CurrentVersion(observer) + 1);
 }
예제 #17
0
 public HeartbeatRsp(UniqueAddress from, long sequenceNr, long creationTimeNanos)
 {
     From              = from;
     SequenceNr        = sequenceNr;
     CreationTimeNanos = creationTimeNanos;
 }
예제 #18
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="node">TBD</param>
 /// <returns>TBD</returns>
 public bool IsReachable(UniqueAddress node)
 {
     return(IsAllReachable || !AllUnreachableOrTerminated.Contains(node));
 }
예제 #19
0
 /// <summary>
 /// Marks the gossip as seen by only this node (address) by replacing the 'gossip.overview.seen'
 /// </summary>
 public Gossip OnlySeen(UniqueAddress node)
 {
     return(Copy(overview: _overview.Copy(seen: ImmutableHashSet.Create(node))));
 }
예제 #20
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="observer">TBD</param>
 /// <param name="subject">TBD</param>
 /// <returns>TBD</returns>
 public bool IsReachable(UniqueAddress observer, UniqueAddress subject)
 {
     return(Status(observer, subject) == ReachabilityStatus.Reachable);
 }
예제 #21
0
 public bool IsLeader(UniqueAddress node, UniqueAddress selfUniqueAddress)
 {
     return(Leader(selfUniqueAddress) == node && node != null);
 }
예제 #22
0
 internal Member(UniqueAddress uniqueAddress, int upNumber, MemberStatus status, IEnumerable <string> roles, AppVersion appVersion)
     : this(uniqueAddress, upNumber, status, roles.ToImmutableHashSet(), appVersion)
 {
 }
예제 #23
0
 public Member GetMember(UniqueAddress node)
 {
     return(_membersMap.Value.GetOrElse(node,
                                        Member.Removed(node))); // placeholder for removed member
 }
예제 #24
0
 /// <inheritdoc cref="object.GetHashCode"/>
 public override int GetHashCode()
 {
     return(UniqueAddress.GetHashCode());
 }
예제 #25
0
 public GossipStatus(UniqueAddress from, VectorClock version)
 {
     _from    = from;
     _version = version;
 }
예제 #26
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="uniqueAddress">TBD</param>
 /// <param name="roles">TBD</param>
 /// <param name="appVersion">Application version</param>
 /// <returns>TBD</returns>
 internal static Member Create(UniqueAddress uniqueAddress, ImmutableHashSet <string> roles, AppVersion appVersion)
 {
     return(new Member(uniqueAddress, int.MaxValue, MemberStatus.Joining, roles, appVersion));
 }
예제 #27
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="from">TBD</param>
 public ExpectedFirstHeartbeat(UniqueAddress from)
 {
     From = from;
 }
예제 #28
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="node">TBD</param>
 /// <returns>TBD</returns>
 internal static Member Removed(UniqueAddress node)
 {
     return(new Member(node, int.MaxValue, MemberStatus.Removed, ImmutableHashSet.Create <string>(), Util.AppVersion.Zero));
 }
예제 #29
0
 /// <summary>
 /// Adds a new <see cref="UniqueAddress"/> to the heartbeat sender's state.
 /// </summary>
 /// <param name="node">The node to add.</param>
 /// <returns>An updated copy of the state now including this member.</returns>
 public ClusterHeartbeatSenderState AddMember(UniqueAddress node)
 {
     return(MembershipChange(Ring + node));
 }
예제 #30
0
        internal static ImmutableList <LeaderChanged> DiffLeader(Gossip oldGossip, Gossip newGossip, UniqueAddress selfUniqueAddress)
        {
            var newLeader = newGossip.Leader(selfUniqueAddress);

            if ((newLeader == null && oldGossip.Leader(selfUniqueAddress) == null) ||
                newLeader != null && newLeader.Equals(oldGossip.Leader(selfUniqueAddress)))
            {
                return(ImmutableList <LeaderChanged> .Empty);
            }

            return(ImmutableList.Create(newLeader == null
                ? new LeaderChanged(null)
                : new LeaderChanged(newLeader.Address)));
        }