pub async fn cond_install_snapshot(
        &self,
        last_included_term: u64,
        last_included_index: u64,
        snapshot: &[u8],
    ) -> bool {
        let mut raft = self.inner.lock().unwrap();
        // 1.If server already applied newer log than snapshot, then we cannot roll back to stale snapshot
        // 2.If server already applied newer snapshot, it should refuse to install stale snapshot
        if raft.state.last_applied > last_included_index
            || last_included_index <= raft.state.last_included_index
        {
            info!("[Snapshot] S{} cond install snapshot FAILED with last_included_index = {}, last_included_term = {}",
                raft.me, last_included_index, last_included_term);
            return false;
        }
        info!("[Snapshot] S{} cond install snapshot SUCCESS with last_included_index = {}, last_included_term = {}",
            raft.me, last_included_index, last_included_term);
        raft.update_snapshot(snapshot);
        raft.state.last_included_term = last_included_term;
        // trim logs
        raft.trim_before_log_index(last_included_index);
        raft.state.last_included_index = last_included_index;
        raft.state.last_applied = last_included_index;
        raft.state.commit_index = raft.state.commit_index.max(last_included_index);
        true
    }
/// A service wants to switch to snapshot.  
///
/// Only do so if Raft hasn't have more recent info since it communicate
/// the snapshot on `apply_ch`.
A service wants to switch to snapshot.
Only do so if Raft hasn't have more recent info since it communicate
the snapshot on `apply_ch`.
A service wants to switch to snapshot . Only do so if Raft hasn ' t have more recent info since it communicate the snapshot on ` apply_ch ` .
pub async fn cond_install_snapshot(
        &self,
        last_included_term: u64,
        last_included_index: u64,
        snapshot: &[u8],
    ) -> bool {
        let mut raft = self.inner.lock().unwrap();
        // 1.If server already applied newer log than snapshot, then we cannot roll back to stale snapshot
        // 2.If server already applied newer snapshot, it should refuse to install stale snapshot
        if raft.state.last_applied > last_included_index
            || last_included_index <= raft.state.last_included_index
        {
            info!("[Snapshot] S{} cond install snapshot FAILED with last_included_index = {}, last_included_term = {}",
                raft.me, last_included_index, last_included_term);
            return false;
        }
        info!("[Snapshot] S{} cond install snapshot SUCCESS with last_included_index = {}, last_included_term = {}",
            raft.me, last_included_index, last_included_term);
        raft.update_snapshot(snapshot);
        raft.state.last_included_term = last_included_term;
        // trim logs
        raft.trim_before_log_index(last_included_index);
        raft.state.last_included_index = last_included_index;
        raft.state.last_applied = last_included_index;
        raft.state.commit_index = raft.state.commit_index.max(last_included_index);
        true
    }
pub async fn cond_install_snapshot ( & self , last_included_term : u64 , last_included_index : u64 , snapshot : & [ u8 ] , ) -> bool { let mut raft = self . inner . lock ( ) . unwrap ( ) ; // 1.If server already applied newer log than snapshot, then we cannot roll back to stale snapshot // 2.If server already applied newer snapshot, it should refuse to install stale snapshot if raft . state . last_applied > last_included_index || last_included_index <= raft . state . last_included_index { info ! ( " " raft me last_included_index last_included_term ) ; return false ; } info ! ( " " raft me last_included_index last_included_term ) ; raft . update_snapshot ( snapshot ) ; raft . state . last_included_term = last_included_term ; // trim logs raft . trim_before_log_index ( last_included_index ) ; raft . state . last_included_index = last_included_index ; raft . state . last_applied = last_included_index ; raft . state . commit_index = raft . state . commit_index . max ( last_included_index ) ; true }
A service wants to switch to snapshot.
A service wants to switch to snapshot .
&self
last_included_term
u64
last_included_index
u64
snapshot
&[u8]
&self
last_included_term
u64
last_included_index
u64
snapshot
&[u8]