fn check_log_term_in_append(&self, args: &AppendEntriesArgs) -> Option<ConflictInfo> {
        let last_included_index = self.state.last_included_index;
        let last_included_term = self.state.last_included_term;
        let mut conflict_info = ConflictInfo {
            term: last_included_term,
            first_index: last_included_index,
            reason: ConflictReason::TermMismatch,
        };
        if args.prev_log_index < last_included_index {
            conflict_info.reason = ConflictReason::AlreadySnapshot;
        } else if args.prev_log_index == last_included_index {
            if args.prev_log_term == last_included_term {
                return None;
            }
        } else {
            let prev_log_idx = self.log_index_to_idx(args.prev_log_index);
            if let Some(log) = self.logs.get(prev_log_idx) {
                if log.term == args.prev_log_term {
                    return None;
                } else {
                    conflict_info.term = log.term;
                    conflict_info.first_index = self.get_first_index_of_term(log.term).unwrap();
                }
            } else {
                conflict_info.reason = ConflictReason::NoEntry;
                conflict_info.term = self.last_log_term();
                conflict_info.first_index = self.last_log_index();
            }
        }
        Some(conflict_info)
    }
/// Check whether leader's log at AppendRPCArg.prev_index match with local logs
///
/// Only be called in `request_append()`
Check whether leader's log at AppendRPCArg.prev_index match with local logs
Only be called in `request_append()`
Check whether leader ' s log at AppendRPCArg . prev_index match with local logs Only be called in ` request_append () `
fn check_log_term_in_append(&self, args: &AppendEntriesArgs) -> Option<ConflictInfo> {
        let last_included_index = self.state.last_included_index;
        let last_included_term = self.state.last_included_term;
        let mut conflict_info = ConflictInfo {
            term: last_included_term,
            first_index: last_included_index,
            reason: ConflictReason::TermMismatch,
        };
        if args.prev_log_index < last_included_index {
            conflict_info.reason = ConflictReason::AlreadySnapshot;
        } else if args.prev_log_index == last_included_index {
            if args.prev_log_term == last_included_term {
                return None;
            }
        } else {
            let prev_log_idx = self.log_index_to_idx(args.prev_log_index);
            if let Some(log) = self.logs.get(prev_log_idx) {
                if log.term == args.prev_log_term {
                    return None;
                } else {
                    conflict_info.term = log.term;
                    conflict_info.first_index = self.get_first_index_of_term(log.term).unwrap();
                }
            } else {
                conflict_info.reason = ConflictReason::NoEntry;
                conflict_info.term = self.last_log_term();
                conflict_info.first_index = self.last_log_index();
            }
        }
        Some(conflict_info)
    }
fn check_log_term_in_append ( & self , args : & AppendEntriesArgs ) -> Option < ConflictInfo > { let last_included_index = self . state . last_included_index ; let last_included_term = self . state . last_included_term ; let mut conflict_info = ConflictInfo { term : last_included_term , first_index : last_included_index , reason : ConflictReason :: TermMismatch , } ; if args . prev_log_index < last_included_index { conflict_info . reason = ConflictReason :: AlreadySnapshot ; } else if args . prev_log_index == last_included_index { if args . prev_log_term == last_included_term { return None ; } } else { let prev_log_idx = self . log_index_to_idx ( args . prev_log_index ) ; if let Some ( log ) = self . logs . get ( prev_log_idx ) { if log . term == args . prev_log_term { return None ; } else { conflict_info . term = log . term ; conflict_info . first_index = self . get_first_index_of_term ( log . term ) . unwrap ( ) ; } } else { conflict_info . reason = ConflictReason :: NoEntry ; conflict_info . term = self . last_log_term ( ) ; conflict_info . first_index = self . last_log_index ( ) ; } } Some ( conflict_info ) }
Check whether leader's log at AppendRPCArg.prev_index match with local logs
Only be called in `request_append()`
Check whether leader ' s log at AppendRPCArg . prev_index match with local logs Only be called in ` request_append () `
&self
args
&AppendEntriesArgs
&self
args
&AppendEntriesArgs