@@ -657,26 +657,26 @@ impl Engine {
657657 max_count : u64 ,
658658 ) -> Result < u64 > {
659659 let chunks = self . meta_store . query_chunks ( begin, end, max_count) ?;
660- let chunks_len = chunks. len ( ) ;
660+ let mut offset = 0 ;
661+
661662 const BATCH_SIZE : Size = Size :: mebibyte ( 1 ) ;
662663 let mut write_batch = RocksDB :: new_write_batch ( ) ;
663- let mut persist_end = 0 ;
664664 for ( index, ( chunk_id, meta) ) in chunks. iter ( ) . enumerate ( ) {
665665 if write_batch. size_in_bytes ( ) >= BATCH_SIZE . 0 as _ {
666666 self . meta_store . write ( write_batch, true ) ?;
667- for i in persist_end..index + 1 {
668- self . meta_cache . remove ( & chunks[ i] . 0 ) ;
669- }
670- persist_end = index + 1 ;
671667 write_batch = RocksDB :: new_write_batch ( ) ;
668+ for ( chunk_id, _) in & chunks[ offset..index] {
669+ self . meta_cache . remove ( chunk_id) ;
670+ }
671+ offset = index;
672672 }
673673 self . meta_store
674674 . remove_mut ( & chunk_id, & meta, & mut write_batch) ?;
675675 }
676676 if !write_batch. is_empty ( ) {
677677 self . meta_store . write ( write_batch, true ) ?;
678- for i in persist_end..chunks_len {
679- self . meta_cache . remove ( & chunks [ i ] . 0 ) ;
678+ for ( chunk_id , _ ) in & chunks [ offset.. ] {
679+ self . meta_cache . remove ( chunk_id ) ;
680680 }
681681 }
682682 Ok ( chunks. len ( ) as _ )
0 commit comments