/// <summary> /// This patches the booked instances that are pending in case the configuration of the cluster changes. This /// should be called only when we learn a ConfigurationChangeState i.e. when we receive an accepted for /// such a message. This won't "learn" the message, as in applying it on the cluster configuration, but will /// just update properly the set of acceptors for pending instances. /// </summary> public override void PatchBookedInstances(ClusterMessage.ConfigurationChangeState value) { if (value.Join != null) { foreach (InstanceId instanceId in _bookedInstances.Keys) { PaxosInstance instance = _paxosInstances.getPaxosInstance(instanceId); if (instance.Acceptors != null) { instance.Acceptors.Remove(CommonState.configuration().Members[value.Join]); GetLog(typeof(ProposerContext)).debug("For booked instance " + instance + " removed gone member " + CommonState.configuration().Members[value.Join] + " added joining member " + value.JoinUri); if (!instance.Acceptors.Contains(value.JoinUri)) { instance.Acceptors.Add(value.JoinUri); } } } } else if (value.Leave != null) { foreach (InstanceId instanceId in _bookedInstances.Keys) { PaxosInstance instance = _paxosInstances.getPaxosInstance(instanceId); if (instance.Acceptors != null) { GetLog(typeof(ProposerContext)).debug("For booked instance " + instance + " removed leaving member " + value.Leave + " (at URI " + CommonState.configuration().Members[value.Leave] + ")"); instance.Acceptors.Remove(CommonState.configuration().Members[value.Leave]); } } } }
public override bool HasQuorum() { int availableMembers = ( int )Iterables.count(_heartbeatContext.Alive); int totalMembers = CommonState.configuration().Members.Count; return(Quorums.isQuorum(availableMembers, totalMembers)); }
public override void Elected(string roleName, InstanceId instanceId, InstanceId electorId, long version) { if (electorId != null) { if (electorId.Equals(MyId)) { GetLog(this.GetType()).debug("I elected instance " + instanceId + " for role " + roleName + " at version " + version); if (version < _electorVersion) { return; } } else if (electorId.Equals(_lastElector) && (version < _electorVersion && version > 1)) { GetLog(this.GetType()).warn("Election result for role " + roleName + " received from elector instance " + electorId + " with version " + version + ". I had version " + _electorVersion + " for elector " + _lastElector); return; } else { GetLog(this.GetType()).debug("Setting elector to " + electorId + " and its version to " + version); } this._electorVersion = version; this._lastElector = electorId; } CommonState.configuration().elected(roleName, instanceId); _clusterListeners.notify(_executor, listener => listener.elected(roleName, instanceId, CommonState.configuration().getUriForId(instanceId))); }
public override void Left(InstanceId node) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.net.URI member = commonState.configuration().getUriForId(node); URI member = CommonState.configuration().getUriForId(node); CommonState.configuration().left(node); InvalidateElectorIfNecessary(node); _clusterListeners.notify(_executor, listener => listener.leftCluster(node, member)); }
public override bool IsFailedBasedOnSuspicions(InstanceId node) { IList <InstanceId> suspicionsForNode = GetSuspicionsOf(node); int countOfInstancesSuspectedByMe = GetSuspicionsFor(MyId).Count; /* * If more than half *non suspected instances* suspect this node, fail it. This takes care of partitions * that contain less than half of the cluster, ensuring that they will eventually detect the disconnect without * waiting to have a majority of suspicions. This is accomplished by counting as quorum only instances * that are not suspected by me. */ return(suspicionsForNode.Count > (CommonState.configuration().Members.Count - countOfInstancesSuspectedByMe) / 2); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: public void acquiredConfiguration(final java.util.Map<org.neo4j.cluster.InstanceId, java.net.URI> memberList, final java.util.Map<String, org.neo4j.cluster.InstanceId> roles, final java.util.Set<org.neo4j.cluster.InstanceId> failedInstances) public override void AcquiredConfiguration(IDictionary <InstanceId, URI> memberList, IDictionary <string, InstanceId> roles, ISet <InstanceId> failedInstances) { CommonState.configuration().Members = memberList; CommonState.configuration().Roles = roles; foreach (InstanceId failedInstance in failedInstances) { if (!failedInstance.Equals(Me)) { LogProvider.getLog(typeof(ClusterContextImpl)).debug("Adding instance " + failedInstance + " as failed from the start"); _heartbeatContext.failed(failedInstance); } } }
/// <summary> /// Get all of the servers which suspect a specific member. /// </summary> /// <param name="instanceId"> for the member of interest. </param> /// <returns> a set of servers which suspect the specified member. </returns> public override IList <InstanceId> GetSuspicionsOf(InstanceId instanceId) { IList <InstanceId> suspicions = new List <InstanceId>(); foreach (InstanceId member in CommonState.configuration().MemberIds) { ISet <InstanceId> memberSuspicions = _nodeSuspicions[member]; if (memberSuspicions != null && !_failed.Contains(member) && memberSuspicions.Contains(instanceId)) { suspicions.Add(member); } } return(suspicions); }
public override void Joined(InstanceId instanceId, URI atURI) { CommonState.configuration().joined(instanceId, atURI); if (CommonState.configuration().Members.ContainsKey(Me)) { // Make sure this node is in cluster before notifying of others joining and leaving _clusterListeners.notify(_executor, listener => listener.joinedCluster(instanceId, atURI)); } // else: // This typically happens in situations when several nodes join at once, and the ordering // of join messages is a little out of whack. _currentlyJoiningInstances.Remove(instanceId); InvalidateElectorIfNecessary(instanceId); }
public override string ToString() { return("Me: " + Me + " Bound at: " + CommonState.boundAt() + " Config:" + CommonState.configuration() + " Current state: " + CommonState); }
public override bool IsElectedAs(string roleName) { return(Me.Equals(CommonState.configuration().getElected(roleName))); }
public override void Unelected(string roleName, InstanceId instanceId, InstanceId electorId, long version) { CommonState.configuration().unelected(roleName); _clusterListeners.notify(_executor, listener => listener.unelected(roleName, instanceId, CommonState.configuration().getUriForId(instanceId))); }
public override void Left() { Timeouts.cancelAllTimeouts(); CommonState.configuration().left(); _clusterListeners.notify(_executor, ClusterListener.leftCluster); }
public override void Joined() { CommonState.configuration().joined(Me, CommonState.boundAt()); _clusterListeners.notify(_executor, listener => listener.enteredCluster(CommonState.configuration())); }