parameters: (self)
docstring: Processes the leader election. If no election is in progress then a new election is started. If an election is
          in progress we check to see if the election is ready to proceed. If so, we election a new leader and terminate
          the election.
  
          The exception to the rule is when the cluster is part of a minority partition. In this case no elections
          are allowed to proceed.
  
          :return: None
docstring_summary: Processes the leader election. If no election is in progress then a new election is started. If an election is
          in progress we check to see if the election is ready to proceed. If so, we election a new leader and terminate
          the election.
docstring_tokens: Processes the leader election . If no election is in progress then a new election is started . If an election is in progress we check to see if the election is ready to proceed . If so we election a new leader and terminate the election .
function: def _elect_leader(self):
          """
          Processes the leader election. If no election is in progress then a new election is started. If an election is
          in progress we check to see if the election is ready to proceed. If so, we election a new leader and terminate
          the election.
  
          The exception to the rule is when the cluster is part of a minority partition. In this case no elections
          are allowed to proceed.
  
          :return: None
          """
          if self.current_cluster_size < self.peak_cluster_size/2:
              return
  
          if self.current_election is None:
              logging.info("No leader, node=%s forcing election.", self.node_id)
              self.current_election = election.Election(self.nodes, self.current_node_time)
              best_candidate = self.current_election.get_best_candidate()
  
              logging.info("Node %s voting for %s", self.node_id, best_candidate)
  
              for node_id in self.node_id_set:
                  self.current_election.tally(best_candidate, node_id)
                  self._send(msg.ELECT_LEADER, msgpack.packb((best_candidate, node_id, self.current_election_id)))
              return
  
          if not self.current_election.ready(self.current_node_time):
              if self.current_election.undecideable(self.current_node_time):
                  logging.info("Election is undecideable, forcing re-election.")
                  self.current_election = None
                  self.leader_node_id = None
              return
  
          self.leader_node_id = self.current_election.get_winner()
          self.current_election = None
          self.current_election_id += 1
  
          logging.info("On node=%s, elected new leader=%s in election %s",
                       self.node_id, self.leader_node_id, self.current_election_id - 1)
function_tokens: def _elect_leader ( self ) : if self . current_cluster_size < self . peak_cluster_size / 2 : return if self . current_election is None : logging . info ( "No leader, node=%s forcing election." , self . node_id ) self . current_election = election . Election ( self . nodes , self . current_node_time ) best_candidate = self . current_election . get_best_candidate ( ) logging . info ( "Node %s voting for %s" , self . node_id , best_candidate ) for node_id in self . node_id_set : self . current_election . tally ( best_candidate , node_id ) self . _send ( msg . ELECT_LEADER , msgpack . packb ( ( best_candidate , node_id , self . current_election_id ) ) ) return if not self . current_election . ready ( self . current_node_time ) : if self . current_election . undecideable ( self . current_node_time ) : logging . info ( "Election is undecideable, forcing re-election." ) self . current_election = None self . leader_node_id = None return self . leader_node_id = self . current_election . get_winner ( ) self . current_election = None self . current_election_id += 1 logging . info ( "On node=%s, elected new leader=%s in election %s" , self . node_id , self . leader_node_id , self . current_election_id - 1 )