fn campaign(&mut self, t: CampaignType) {
        if !self.promotable() {
            // This path should not be hit (callers are supposed to check), but
            // better safe than sorry.
            warn!(
                "{:#x} is unprootable; campaign() should have been called",
                self.id
            );
        }
        let mut term = 0;
        let mut vote_msg = MessageType::MsgHup;
        if t == CampaignType::CampaignPreElection {
            self.become_precandidate();
            vote_msg = MessageType::MsgPreVote;
            // PreVote RPCs are sent for the next term before we've incremented self.Term.
            term = self.term + 1;
        } else {
            self.become_candidate();
            vote_msg = MessageType::MsgVote;
            term = self.term;
        }

        let (_, _, res) = self.poll(self.id, vote_msg, true);
        if res == VoteWon {
            // We won the election after voting for ourselves (which must mean that
            // this is a *single-node* cluster). Advance to the next state.
            if t == CampaignType::CampaignPreElection {
                self.campaign(CampaignType::CampaignElection);
            } else {
                self.become_leader();
            }
            return;
        }
        let mut ids = self
            .prs
            .config
            .voters
            .ids()
            .iter()
            .map(|id| *id)
            .filter(|id| *id != self.id)
            .collect::<Vec<_>>();
        // TODO: why sort?
        ids.sort_by_key(|key| *key);
        ids.iter().for_each(|id| {
            info!(
                "{:#x} [logterm: {}, index: {}] sent {:?} request to {:#x} at term {}",
                self.id,
                self.raft_log.last_term(),
                self.raft_log.last_index(),
                vote_msg,
                id,
                self.term,
            );
            let mut msg = Message::new();
            msg.set_term(term);
            msg.set_index(self.raft_log.last_index());
            msg.set_to(*id);
            msg.set_field_type(vote_msg);
            msg.set_logTerm(self.raft_log.last_term());
            if t == CampaignType::CampaignTransfer {
                msg.set_context(Bytes::from(format!("{:?}", t)));
            }
            self.send(msg);
        });
    }
// campaign transition the raft instance to candidate state. This must only be
// called after verifying that this is a legitimate transition.
campaign transition the raft instance to candidate state. This must only be
called after verifying that this is a legitimate transition.
campaign transition the raft instance to candidate state . This must only be called after verifying that this is a legitimate transition .
fn campaign(&mut self, t: CampaignType) {
        if !self.promotable() {
            // This path should not be hit (callers are supposed to check), but
            // better safe than sorry.
            warn!(
                "{:#x} is unprootable; campaign() should have been called",
                self.id
            );
        }
        let mut term = 0;
        let mut vote_msg = MessageType::MsgHup;
        if t == CampaignType::CampaignPreElection {
            self.become_precandidate();
            vote_msg = MessageType::MsgPreVote;
            // PreVote RPCs are sent for the next term before we've incremented self.Term.
            term = self.term + 1;
        } else {
            self.become_candidate();
            vote_msg = MessageType::MsgVote;
            term = self.term;
        }
        let (_, _, res) = self.poll(self.id, vote_msg, true);
        if res == VoteWon {
            // We won the election after voting for ourselves (which must mean that
            // this is a *single-node* cluster). Advance to the next state.
            if t == CampaignType::CampaignPreElection {
                self.campaign(CampaignType::CampaignElection);
            } else {
                self.become_leader();
            }
            return;
        }
        let mut ids = self
            .prs
            .config
            .voters
            .ids()
            .iter()
            .map(|id| *id)
            .filter(|id| *id != self.id)
            .collect::<Vec<_>>();
        // TODO: why sort?
        ids.sort_by_key(|key| *key);
        ids.iter().for_each(|id| {
            info!(
                "{:#x} [logterm: {}, index: {}] sent {:?} request to {:#x} at term {}",
                self.id,
                self.raft_log.last_term(),
                self.raft_log.last_index(),
                vote_msg,
                id,
                self.term,
            );
            let mut msg = Message::new();
            msg.set_term(term);
            msg.set_index(self.raft_log.last_index());
            msg.set_to(*id);
            msg.set_field_type(vote_msg);
            msg.set_logTerm(self.raft_log.last_term());
            if t == CampaignType::CampaignTransfer {
                msg.set_context(Bytes::from(format!("{:?}", t)));
            }
            self.send(msg);
        });
    }
fn campaign ( & mut self , t : CampaignType ) { if ! self . promotable ( ) { // This path should not be hit (callers are supposed to check), but // better safe than sorry. warn ! ( " " self id ) ; } let mut term = 0 ; let mut vote_msg = MessageType :: MsgHup ; if t == CampaignType :: CampaignPreElection { self . become_precandidate ( ) ; vote_msg = MessageType :: MsgPreVote ; // PreVote RPCs are sent for the next term before we've incremented self.Term. term = self . term + 1 ; } else { self . become_candidate ( ) ; vote_msg = MessageType :: MsgVote ; term = self . term ; } let ( _ , _ , res ) = self . poll ( self . id , vote_msg , true ) ; if res == VoteWon { // We won the election after voting for ourselves (which must mean that // this is a *single-node* cluster). Advance to the next state. if t == CampaignType :: CampaignPreElection { self . campaign ( CampaignType :: CampaignElection ) ; } else { self . become_leader ( ) ; } return ; } let mut ids = self . prs . config . voters . ids ( ) . iter ( ) . map ( | id | * id ) . filter ( | id | * id != self . id ) . collect :: < Vec < _ > > ( ) ; // TODO: why sort? ids . sort_by_key ( | key | * key ) ; ids . iter ( ) . for_each ( | id | { info ! ( " " self id self raft_log last_term ( ) self raft_log last_index ( ) vote_msg id self term ) ; let mut msg = Message :: new ( ) ; msg . set_term ( term ) ; msg . set_index ( self . raft_log . last_index ( ) ) ; msg . set_to ( * id ) ; msg . set_field_type ( vote_msg ) ; msg . set_logTerm ( self . raft_log . last_term ( ) ) ; if t == CampaignType :: CampaignTransfer { msg . set_context ( Bytes :: from ( format ! ( " " t ) ) ) ; } self . send ( msg ) ; } ) ; }
campaign transition the raft instance to candidate state.
campaign transition the raft instance to candidate state .
&mut self
t
CampaignType