@@ -656,22 +656,28 @@ impl Engine {
656656 end : impl AsRef < [ u8 ] > ,
657657 max_count : u64 ,
658658 ) -> Result < u64 > {
659- let mut chunks = self . meta_store . query_chunks ( begin, end, max_count) ?;
659+ let chunks = self . meta_store . query_chunks ( begin, end, max_count) ?;
660+ let mut offset = 0 ;
660661
661662 const BATCH_SIZE : Size = Size :: mebibyte ( 1 ) ;
662663 let mut write_batch = RocksDB :: new_write_batch ( ) ;
663- for ( chunk_id, meta) in & mut chunks {
664- if write_batch. size_in_bytes ( ) >= BATCH_SIZE . 0 as usize {
664+ for ( index , ( chunk_id, meta) ) in chunks. iter ( ) . enumerate ( ) {
665+ if write_batch. size_in_bytes ( ) >= BATCH_SIZE . 0 as _ {
665666 self . meta_store . write ( write_batch, true ) ?;
666667 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;
667672 }
668-
669673 self . meta_store
670- . remove_mut ( chunk_id, meta, & mut write_batch) ?;
671- self . meta_cache . remove ( chunk_id) ;
674+ . remove_mut ( & chunk_id, & meta, & mut write_batch) ?;
672675 }
673676 if !write_batch. is_empty ( ) {
674677 self . meta_store . write ( write_batch, true ) ?;
678+ for ( chunk_id, _) in & chunks[ offset..] {
679+ self . meta_cache . remove ( chunk_id) ;
680+ }
675681 }
676682 Ok ( chunks. len ( ) as _ )
677683 }
0 commit comments