pub async fn defensive_no_dirty_log(&self) -> anyhow::Result<()> {
        if !*self.defensive.read().await {
            return Ok(());
        }

        let log = self.log.read().await;
        let sm = self.sm.read().await;
        let last_log_id = log.iter().last().map(|(_index, entry)| entry.log_id).unwrap_or_default();
        let last_applied = sm.last_applied_log;

        if last_log_id.index > last_applied.index && last_log_id < last_applied {
            return Err(anyhow::anyhow!("greater index log is smaller than last_applied"));
        }

        Ok(())
    }
/// Ensure that logs that have greater index than last_applied should have greater log_id.
/// Invariant must hold: `log.log_id.index > last_applied.index` implies `log.log_id > last_applied`.
Ensure that logs that have greater index than last_applied should have greater log_id.
Ensure that logs that have greater index than last_applied should have greater log_id .
pub async fn defensive_no_dirty_log(&self) -> anyhow::Result<()> {
        if !*self.defensive.read().await {
            return Ok(());
        }
        let log = self.log.read().await;
        let sm = self.sm.read().await;
        let last_log_id = log.iter().last().map(|(_index, entry)| entry.log_id).unwrap_or_default();
        let last_applied = sm.last_applied_log;
        if last_log_id.index > last_applied.index && last_log_id < last_applied {
            return Err(anyhow::anyhow!("greater index log is smaller than last_applied"));
        }
        Ok(())
    }
pub async fn defensive_no_dirty_log ( & self ) -> anyhow :: Result < ( ) > { if ! * self . defensive . read ( ) . await { return Ok ( ( ) ) ; } let log = self . log . read ( ) . await ; let sm = self . sm . read ( ) . await ; let last_log_id = log . iter ( ) . last ( ) . map ( | ( _index , entry ) | entry . log_id ) . unwrap_or_default ( ) ; let last_applied = sm . last_applied_log ; if last_log_id . index > last_applied . index && last_log_id < last_applied { return Err ( anyhow :: anyhow ! ( " " ) ) ; } Ok ( ( ) ) }
Ensure that logs that have greater index than last_applied should have greater log_id.
Ensure that logs that have greater index than last_applied should have greater log_id .
&self
&self