pub(crate) fn become_leader(&mut self) {
        info!("{:#x} become leader at term {}", self.id, self.term);
        assert_ne!(
            self.state,
            StateType::Follower,
            "invalid transition [follower->leader]"
        );
        // self.step = Some(Box::new(Self::step_leader));
        self.reset(self.term);
        // self.tick = Some(Box::new(tick_election));
        self.lead = self.id;
        self.state = StateType::Leader;
        // Followers enter replicate mode when they've been successfully probed
        // (perhaps after having received a snapshot as a result). The leader is
        // trivially in this state. Note that r.reset() has initialized this
        // progress with the last index already.
        self.prs.progress.must_get_mut(&self.id).become_replicate();

        // conservatively set the pending_config_index to the last index in the
        // log. There may or may not be a pending config change. but it's
        // safe to delay any future proposals until we commit all our
        // pending log entries, and scanning the entire tail of the log
        // could be expensive.
        self.pending_config_index = self.raft_log.last_index();

        let empty_ent = Entry::new();
        // This won't happen because we just called reset() above.
        assert!(
            self.append_entry(&mut [empty_ent.clone()]),
            "empty entry was dropped"
        );
        // As a special case, don't count the initial empty entry towards the
        // uncommitted log quota. The is because we want to preseve the
        // behavior of allowing the one entry larger than quota if the current
        // usage is zero.
        self.reduce_uncommitted_size(&[empty_ent.clone()]);
    }
// become_leader transform this peer's state to leader
become_leader transform this peer's state to leader
become_leader transform this peer ' s state to leader
pub(crate) fn become_leader(&mut self) {
        info!("{:#x} become leader at term {}", self.id, self.term);
        assert_ne!(
            self.state,
            StateType::Follower,
            "invalid transition [follower->leader]"
        );
        // self.step = Some(Box::new(Self::step_leader));
        self.reset(self.term);
        // self.tick = Some(Box::new(tick_election));
        self.lead = self.id;
        self.state = StateType::Leader;
        // Followers enter replicate mode when they've been successfully probed
        // (perhaps after having received a snapshot as a result). The leader is
        // trivially in this state. Note that r.reset() has initialized this
        // progress with the last index already.
        self.prs.progress.must_get_mut(&self.id).become_replicate();
        // conservatively set the pending_config_index to the last index in the
        // log. There may or may not be a pending config change. but it's
        // safe to delay any future proposals until we commit all our
        // pending log entries, and scanning the entire tail of the log
        // could be expensive.
        self.pending_config_index = self.raft_log.last_index();
        let empty_ent = Entry::new();
        // This won't happen because we just called reset() above.
        assert!(
            self.append_entry(&mut [empty_ent.clone()]),
            "empty entry was dropped"
        );
        // As a special case, don't count the initial empty entry towards the
        // uncommitted log quota. The is because we want to preseve the
        // behavior of allowing the one entry larger than quota if the current
        // usage is zero.
        self.reduce_uncommitted_size(&[empty_ent.clone()]);
    }
pub ( crate ) fn become_leader ( & mut self ) { info ! ( " " self id self term ) ; assert_ne ! ( self state StateType Follower " " ) ; // self.step = Some(Box::new(Self::step_leader)); self . reset ( self . term ) ; // self.tick = Some(Box::new(tick_election)); self . lead = self . id ; self . state = StateType :: Leader ; // Followers enter replicate mode when they've been successfully probed // (perhaps after having received a snapshot as a result). The leader is // trivially in this state. Note that r.reset() has initialized this // progress with the last index already. self . prs . progress . must_get_mut ( & self . id ) . become_replicate ( ) ; // conservatively set the pending_config_index to the last index in the // log. There may or may not be a pending config change. but it's // safe to delay any future proposals until we commit all our // pending log entries, and scanning the entire tail of the log // could be expensive. self . pending_config_index = self . raft_log . last_index ( ) ; let empty_ent = Entry :: new ( ) ; // This won't happen because we just called reset() above. assert ! ( self append_entry ( mut [ empty_ent clone ( ) ] ) " " ) ; // As a special case, don't count the initial empty entry towards the // uncommitted log quota. The is because we want to preseve the // behavior of allowing the one entry larger than quota if the current // usage is zero. self . reduce_uncommitted_size ( & [ empty_ent . clone ( ) ] ) ; }
become_leader transform this peer's state to leader
become_leader transform this peer ' s state to leader
&mut self