示例#1
0
 private void HeartBeatTimeoutElapsed(object sender, ElapsedEventArgs e)
 {
     DetachEventListeners();
     Logger.Log("INFO (F):: Follower's HB timed out. PROMOTION TIME.");
     NodeRegistryCache.GetInstance().PromoteFollowerToCandidate(this);
     HeartBeatTimeout.Stop();
     HeartBeatTimeout.Close();
 }
示例#2
0
 internal void HeartBeatSignalReceivedFromLeader(long p)
 {
     Logger.Log(string.Format("INFO (L) :: HB SIGNAL (REC) from leader."));
     lock (lockerObject)
     {
         if (NodeRegistryCache.GetInstance().CurrentNode != null && NodeRegistryCache.GetInstance().CurrentNode is Leader)
         {
             DetachEventListerners();
         }
         NodeRegistryCache.GetInstance().DemoteLeaderToFollower();
     }
 }
示例#3
0
        public void SendHeartBeatMessage()
        {
            Logger.Log(string.Format("INFO (L) :: Initiating sending heartbeat signals for term {0}.", GetTerm()));
            var dummyFollowers = NodeRegistryCache.GetInstance().Get();

            foreach (var follower in dummyFollowers)
            {
                try
                {
                    Task.Run(() => { MessageBroker.GetInstance().LeaderSendHeartbeatAsync(follower, this.CurrentStateData.Term); });
                }
                catch (Exception exp)
                {
                    Logger.Log(exp);
                }
            }
            if (dummyFollowers == null || dummyFollowers.Count == 0)
            {
                Logger.Log("INFO (L) :: No followers registered to the cluster Or Leader is not aware of any follower.");
            }
        }
 public void SendRequestVotesToFollowers()
 {
     try
     {
         totalResponseReceivedForCurrentTerm++;
         positiveVotes = new Dictionary <String, long>();
         positiveVotes.Add(this.GetNodeId(), this.GetTerm());
         var nodeRegistry = NodeRegistryCache.GetInstance();
         foreach (Node node in nodeRegistry.Get())
         {
             if (!node.GetNodeId().Equals(this.nodeId))
             {
                 MessageBroker.GetInstance().CandidateSendRequestVoteAsync(node, CurrentStateData.Term);
             }
         }
     }
     catch (Exception exp)
     {
         Logger.Log(exp);
     }
 }
 private void electionTimeoutElapsed(object sender, ElapsedEventArgs e)
 {
     if (!TryGettingConsensus())
     {
         RestartElectionTimeout();
         // Election timed out without reaching at consensus. Trying re election
         Console.WriteLine("Election timed out without reaching at consensus. Trying re election");
         SendRequestVotesToFollowers();
     }
     else
     {
         Logger.Log("INFO (C) :: Quorum won.");
         lock (lockerObject)
         {
             if (NodeRegistryCache.GetInstance().CurrentNode != null && NodeRegistryCache.GetInstance().CurrentNode is Candidate)
             {
                 DetachEventListerners();
                 NodeRegistryCache.GetInstance().PromoteCandidateToLeader(this);
                 electionTimeout.Stop();
             }
         }
         //Dispose();
     }
 }