public void Handle(ElectionMessage.ViewChange message) { if (_state == ElectionsState.Shutdown) { return; } if (_state == ElectionsState.Idle) { return; } if (message.AttemptedView <= _lastInstalledView) { return; } Log.Debug("ELECTIONS: (V={view}) VIEWCHANGE FROM [{serverInternalHttp}, {serverId:B}].", message.AttemptedView, message.ServerInternalHttp, message.ServerId); if (message.AttemptedView > _lastAttemptedView) { ShiftToLeaderElection(message.AttemptedView); } if (_vcReceived.Add(message.ServerId) && _vcReceived.Count == _clusterSize / 2 + 1) { Log.Debug("ELECTIONS: (V={view}) MAJORITY OF VIEWCHANGE.", message.AttemptedView); if (AmILeaderOf(_lastAttemptedView)) { ShiftToPreparePhase(); } } }
public void SendViewChange(ElectionMessage.ViewChange msg, EndPoint destinationEndpoint, DateTime deadline) { SendViewChangeAsync(msg.ServerId, msg.ServerHttpEndPoint, msg.AttemptedView, deadline).ContinueWith(r => { if (r.Exception != null) { Log.Information(r.Exception, "View Change Send Failed to {Server}", destinationEndpoint); } }); }
private void ShiftToLeaderElection(int view) { Log.Debug("ELECTIONS: (V={view}) SHIFT TO LEADER ELECTION.", view); _state = ElectionsState.ElectingLeader; _vcReceived.Clear(); _prepareOkReceived.Clear(); _lastAttemptedView = view; _masterProposal = null; _master = null; _acceptsReceived.Clear(); var viewChangeMsg = new ElectionMessage.ViewChange(_nodeInfo.InstanceId, _nodeInfo.InternalHttp, view); Handle(viewChangeMsg); SendToAllExceptMe(viewChangeMsg); _publisher.Publish(TimerMessage.Schedule.Create(LeaderElectionProgressTimeout, _publisherEnvelope, new ElectionMessage.ElectionsTimedOut(view))); }