11use std:: path:: { Path , PathBuf } ;
22
33use bitvec:: slice:: BitSlice ;
4+ use common:: counter:: conditioned_counter:: ConditionedCounter ;
45use common:: counter:: hardware_counter:: HardwareCounterCell ;
56use common:: counter:: iterator_hw_measurement:: HwMeasurementIteratorExt ;
67use common:: types:: PointOffsetType ;
@@ -29,6 +30,7 @@ pub struct MmapBoolIndex {
2930 falses_count : usize ,
3031 trues_slice : DynamicMmapFlags ,
3132 falses_slice : DynamicMmapFlags ,
33+ populated : bool ,
3234}
3335
3436impl MmapBoolIndex {
@@ -79,21 +81,32 @@ impl MmapBoolIndex {
7981 indexed_count : 0 ,
8082 trues_count : 0 ,
8183 falses_count : 0 ,
84+ populated : populate,
8285 } )
8386 }
8487
88+ fn make_conditioned_counter < ' a > (
89+ & self ,
90+ hw_counter : & ' a HardwareCounterCell ,
91+ ) -> ConditionedCounter < ' a > {
92+ let on_disk = !self . populated ; // Measure if on disk.
93+ ConditionedCounter :: new ( on_disk, hw_counter)
94+ }
95+
8596 fn set_or_insert (
8697 & mut self ,
8798 id : u32 ,
8899 has_true : bool ,
89100 has_false : bool ,
90101 hw_counter : & HardwareCounterCell ,
91102 ) -> OperationResult < ( ) > {
103+ let hw_counter = self . make_conditioned_counter ( hw_counter) ;
104+
92105 // Set or insert the flags
93106 let prev_true =
94- set_or_insert_flag ( & mut self . trues_slice , id as usize , has_true, hw_counter) ?;
107+ set_or_insert_flag ( & mut self . trues_slice , id as usize , has_true, & hw_counter) ?;
95108 let prev_false =
96- set_or_insert_flag ( & mut self . falses_slice , id as usize , has_false, hw_counter) ?;
109+ set_or_insert_flag ( & mut self . falses_slice , id as usize , has_false, & hw_counter) ?;
97110
98111 let was_indexed = prev_true || prev_false;
99112 let is_indexed = has_true || has_false;
@@ -209,6 +222,8 @@ impl MmapBoolIndex {
209222 is_true : bool ,
210223 hw_counter : & HardwareCounterCell ,
211224 ) -> bool {
225+ let hw_counter = self . make_conditioned_counter ( hw_counter) ;
226+
212227 hw_counter
213228 . payload_index_io_read_counter ( )
214229 . incr_delta ( size_of :: < bool > ( ) ) ;
@@ -227,12 +242,14 @@ impl MmapBoolIndex {
227242 & ' a self ,
228243 hw_counter : & ' a HardwareCounterCell ,
229244 ) -> impl Iterator < Item = ( bool , IdIter < ' a > ) > + ' a {
245+ let hw_counter = self . make_conditioned_counter ( hw_counter) ;
246+
230247 [
231248 ( false , Box :: new ( self . falses_slice . iter_trues ( ) ) as IdIter ) ,
232249 ( true , Box :: new ( self . trues_slice . iter_trues ( ) ) as IdIter ) ,
233250 ]
234251 . into_iter ( )
235- . measure_hw_with_cell_and_fraction ( hw_counter, u8:: BITS as usize , |i| {
252+ . measure_hw_with_acc ( hw_counter. new_accumulator ( ) , u8:: BITS as usize , |i| {
236253 i. payload_index_io_read_counter ( )
237254 } )
238255 }
@@ -272,7 +289,7 @@ fn set_or_insert_flag(
272289 flags : & mut DynamicMmapFlags ,
273290 key : usize ,
274291 value : bool ,
275- hw_counter : & HardwareCounterCell ,
292+ hw_counter : & ConditionedCounter ,
276293) -> OperationResult < bool > {
277294 let counter = hw_counter. payload_index_io_write_counter ( ) ;
278295
@@ -314,7 +331,8 @@ impl FieldIndexBuilderTrait for MmapBoolIndexBuilder {
314331 payload : & [ & serde_json:: Value ] ,
315332 hw_counter : & HardwareCounterCell ,
316333 ) -> OperationResult < ( ) > {
317- self . 0 . add_point ( id, payload, hw_counter)
334+ let hw_counter = self . 0 . make_conditioned_counter ( hw_counter) ;
335+ self . 0 . add_point ( id, payload, & hw_counter)
318336 }
319337
320338 fn finalize ( self ) -> OperationResult < Self :: FieldIndexType > {
@@ -335,10 +353,12 @@ impl ValueIndexer for MmapBoolIndex {
335353 return Ok ( ( ) ) ;
336354 }
337355
356+ let hw_counter = self . make_conditioned_counter ( hw_counter) ;
357+
338358 let has_true = values. iter ( ) . any ( |v| * v) ;
339359 let has_false = values. iter ( ) . any ( |v| !* v) ;
340360
341- self . set_or_insert ( id, has_true, has_false, hw_counter) ?;
361+ self . set_or_insert ( id, has_true, has_false, & hw_counter) ?;
342362
343363 Ok ( ( ) )
344364 }
@@ -369,6 +389,7 @@ impl PayloadFieldIndex for MmapBoolIndex {
369389 falses_count,
370390 trues_slice,
371391 falses_slice,
392+ populated : _,
372393 } = self ;
373394
374395 * indexed_count = calculated_indexed_count as usize ;
@@ -391,6 +412,7 @@ impl PayloadFieldIndex for MmapBoolIndex {
391412 falses_count : _,
392413 trues_slice,
393414 falses_slice,
415+ populated : _,
394416 } = self ;
395417
396418 let trues_flusher = trues_slice. flusher ( ) ;
@@ -415,6 +437,8 @@ impl PayloadFieldIndex for MmapBoolIndex {
415437 condition : & ' a FieldCondition ,
416438 hw_counter : & ' a HardwareCounterCell ,
417439 ) -> Option < Box < dyn Iterator < Item = PointOffsetType > + ' a > > {
440+ let hw_counter = self . make_conditioned_counter ( hw_counter) ;
441+
418442 match & condition. r#match {
419443 Some ( Match :: Value ( MatchValue {
420444 value : ValueVariants :: Bool ( value) ,
@@ -423,9 +447,11 @@ impl PayloadFieldIndex for MmapBoolIndex {
423447 . get_slice_for ( * value)
424448 . iter_ones ( )
425449 . map ( |x| x as PointOffsetType )
426- . measure_hw_with_cell_and_fraction ( hw_counter, u8:: BITS as usize , |i| {
427- i. payload_index_io_read_counter ( )
428- } ) ;
450+ . measure_hw_with_acc_and_fraction (
451+ hw_counter. new_accumulator ( ) ,
452+ u8:: BITS as usize ,
453+ |i| i. payload_index_io_read_counter ( ) ,
454+ ) ;
429455 Some ( Box :: new ( iter) )
430456 }
431457 _ => None ,
@@ -437,6 +463,8 @@ impl PayloadFieldIndex for MmapBoolIndex {
437463 condition : & FieldCondition ,
438464 hw_counter : & HardwareCounterCell ,
439465 ) -> Option < CardinalityEstimation > {
466+ let hw_counter = self . make_conditioned_counter ( hw_counter) ;
467+
440468 match & condition. r#match {
441469 Some ( Match :: Value ( MatchValue {
442470 value : ValueVariants :: Bool ( value) ,
0 commit comments