pub fn rewrite(&mut self, rewrite_indexes: Vec<EntryIndex>, gate: Option<FileSeq>) {
        if rewrite_indexes.is_empty() {
            return;
        }
        self.global_stats
            .add(LogQueue::Rewrite, rewrite_indexes.len());

        let len = self.entry_indexes.len();
        if len == 0 {
            self.global_stats
                .delete(LogQueue::Rewrite, rewrite_indexes.len());
            return;
        }

        let first = self.first_index;
        let last = self.first_index + len as u64 - 1;
        let rewrite_first = std::cmp::max(rewrite_indexes[0].index, first);
        let rewrite_last = std::cmp::min(rewrite_indexes[rewrite_indexes.len() - 1].index, last);
        let mut rewrite_len = (rewrite_last + 1).saturating_sub(rewrite_first) as usize;
        if rewrite_len == 0 {
            self.global_stats
                .delete(LogQueue::Rewrite, rewrite_indexes.len());
            return;
        }

        let pos = (rewrite_first - first) as usize;
        // No normal log entry mixed in rewritten entries at the front.
        assert!(
            pos == 0 || self.entry_indexes[pos - 1].entries.unwrap().id.queue == LogQueue::Rewrite
        );
        let rewrite_pos = (rewrite_first - rewrite_indexes[0].index) as usize;

        for (i, rindex) in rewrite_indexes[rewrite_pos..rewrite_pos + rewrite_len]
            .iter()
            .enumerate()
        {
            let index = &mut self.entry_indexes[i + pos];
            if let Some(gate) = gate {
                debug_assert_eq!(index.entries.unwrap().id.queue, LogQueue::Append);
                if index.entries.unwrap().id.seq > gate {
                    // Some entries are overwritten by new appends.
                    rewrite_len = i;
                    break;
                }
            } else if index.entries.unwrap().id.queue == LogQueue::Append {
                // Squeeze operation encounters a new append.
                rewrite_len = i;
                break;
            }

            *index = rindex.into();
        }

        if gate.is_none() {
            self.global_stats
                .delete(LogQueue::Rewrite, rewrite_indexes.len());
        } else {
            self.global_stats.delete(LogQueue::Append, rewrite_len);
            self.global_stats
                .delete(LogQueue::Rewrite, rewrite_indexes.len() - rewrite_len);
        }

        self.rewrite_count = pos + rewrite_len;
    }
/// Rewrites some entries by modifying their location.
///
/// When `gate` is present, only append data no newer than it will be
/// rewritten.
///
/// # Panics
///
/// Panics if index of the first entry in `rewrite_indexes` is greater than
/// largest existing rewritten index + 1 (hole).
Rewrites some entries by modifying their location.
When `gate` is present, only append data no newer than it will be
rewritten.
Rewrites some entries by modifying their location . When ` gate ` is present only append data no newer than it will be rewritten .
pub fn rewrite(&mut self, rewrite_indexes: Vec<EntryIndex>, gate: Option<FileSeq>) {
        if rewrite_indexes.is_empty() {
            return;
        }
        self.global_stats
            .add(LogQueue::Rewrite, rewrite_indexes.len());
        let len = self.entry_indexes.len();
        if len == 0 {
            self.global_stats
                .delete(LogQueue::Rewrite, rewrite_indexes.len());
            return;
        }
        let first = self.first_index;
        let last = self.first_index + len as u64 - 1;
        let rewrite_first = std::cmp::max(rewrite_indexes[0].index, first);
        let rewrite_last = std::cmp::min(rewrite_indexes[rewrite_indexes.len() - 1].index, last);
        let mut rewrite_len = (rewrite_last + 1).saturating_sub(rewrite_first) as usize;
        if rewrite_len == 0 {
            self.global_stats
                .delete(LogQueue::Rewrite, rewrite_indexes.len());
            return;
        }
        let pos = (rewrite_first - first) as usize;
        // No normal log entry mixed in rewritten entries at the front.
        assert!(
            pos == 0 || self.entry_indexes[pos - 1].entries.unwrap().id.queue == LogQueue::Rewrite
        );
        let rewrite_pos = (rewrite_first - rewrite_indexes[0].index) as usize;
        for (i, rindex) in rewrite_indexes[rewrite_pos..rewrite_pos + rewrite_len]
            .iter()
            .enumerate()
        {
            let index = &mut self.entry_indexes[i + pos];
            if let Some(gate) = gate {
                debug_assert_eq!(index.entries.unwrap().id.queue, LogQueue::Append);
                if index.entries.unwrap().id.seq > gate {
                    // Some entries are overwritten by new appends.
                    rewrite_len = i;
                    break;
                }
            } else if index.entries.unwrap().id.queue == LogQueue::Append {
                // Squeeze operation encounters a new append.
                rewrite_len = i;
                break;
            }
            *index = rindex.into();
        }
        if gate.is_none() {
            self.global_stats
                .delete(LogQueue::Rewrite, rewrite_indexes.len());
        } else {
            self.global_stats.delete(LogQueue::Append, rewrite_len);
            self.global_stats
                .delete(LogQueue::Rewrite, rewrite_indexes.len() - rewrite_len);
        }
        self.rewrite_count = pos + rewrite_len;
    }
pub fn rewrite ( & mut self , rewrite_indexes : Vec < EntryIndex > , gate : Option < FileSeq > ) { if rewrite_indexes . is_empty ( ) { return ; } self . global_stats . add ( LogQueue :: Rewrite , rewrite_indexes . len ( ) ) ; let len = self . entry_indexes . len ( ) ; if len == 0 { self . global_stats . delete ( LogQueue :: Rewrite , rewrite_indexes . len ( ) ) ; return ; } let first = self . first_index ; let last = self . first_index + len as u64 - 1 ; let rewrite_first = std :: cmp :: max ( rewrite_indexes [ 0 ] . index , first ) ; let rewrite_last = std :: cmp :: min ( rewrite_indexes [ rewrite_indexes . len ( ) - 1 ] . index , last ) ; let mut rewrite_len = ( rewrite_last + 1 ) . saturating_sub ( rewrite_first ) as usize ; if rewrite_len == 0 { self . global_stats . delete ( LogQueue :: Rewrite , rewrite_indexes . len ( ) ) ; return ; } let pos = ( rewrite_first - first ) as usize ; // No normal log entry mixed in rewritten entries at the front. assert ! ( pos 0 self entry_indexes [ pos 1 ] entries unwrap ( ) id queue LogQueue Rewrite ) ; let rewrite_pos = ( rewrite_first - rewrite_indexes [ 0 ] . index ) as usize ; for ( i , rindex ) in rewrite_indexes [ rewrite_pos .. rewrite_pos + rewrite_len ] . iter ( ) . enumerate ( ) { let index = & mut self . entry_indexes [ i + pos ] ; if let Some ( gate ) = gate { debug_assert_eq ! ( index entries unwrap ( ) id queue LogQueue Append ) ; if index . entries . unwrap ( ) . id . seq > gate { // Some entries are overwritten by new appends. rewrite_len = i ; break ; } } else if index . entries . unwrap ( ) . id . queue == LogQueue :: Append { // Squeeze operation encounters a new append. rewrite_len = i ; break ; } * index = rindex . into ( ) ; } if gate . is_none ( ) { self . global_stats . delete ( LogQueue :: Rewrite , rewrite_indexes . len ( ) ) ; } else { self . global_stats . delete ( LogQueue :: Append , rewrite_len ) ; self . global_stats . delete ( LogQueue :: Rewrite , rewrite_indexes . len ( ) - rewrite_len ) ; } self . rewrite_count = pos + rewrite_len ; }
Rewrites some entries by modifying their location.
Rewrites some entries by modifying their location .
&mut self
rewrite_indexes
Vec<EntryIndex>
gate
Option<FileSeq>
panics
Panics if index of the first entry in `rewrite_indexes` is greater than
largest existing rewritten index + 1 (hole).
Panics if index of the first entry in ` rewrite_indexes ` is greater than largest existing rewritten index + 1 ( hole ) .