@@ -62,6 +62,11 @@ pub struct Config {
6262
6363 /// ratio of randomly dropped entries
6464 pub random_drop_ratio : f64 ,
65+
66+ /// ratio of size to trigger write stall
67+ ///
68+ /// every new entry to insert will be dropped
69+ pub write_stall_threshold_ratio : f64 ,
6570}
6671
6772struct Frozen {
@@ -196,10 +201,16 @@ where
196201
197202 // append cache file and meta file
198203 let ( fid, sid, location) = {
199- // randomly drop if size exceeds the threshold
200- if self . size . load ( Ordering :: Relaxed ) as f64
201- >= self . config . capacity as f64 * self . config . trigger_random_drop_ratio
204+ let size_ratio = self . size . load ( Ordering :: Relaxed ) as f64 / self . config . capacity as f64 ;
205+ if self . config . write_stall_threshold_ratio > 0.0
206+ && size_ratio >= self . config . write_stall_threshold_ratio
207+ {
208+ // write stall
209+ return Ok ( ( ) ) ;
210+ } else if self . config . trigger_random_drop_ratio > 0.0
211+ && size_ratio >= self . config . trigger_random_drop_ratio
202212 {
213+ // random drop
203214 let mut rng = thread_rng ( ) ;
204215 if rng. gen_range ( 0.0 ..1.0 ) < self . config . random_drop_ratio {
205216 return Ok ( ( ) ) ;
@@ -553,8 +564,9 @@ mod tests {
553564 capacity : 16 * 1024 ,
554565 trigger_reclaim_garbage_ratio : 0.0 , // disabled
555566 trigger_reclaim_capacity_ratio : 0.75 ,
556- trigger_random_drop_ratio : 0.0 , // disabled
557- random_drop_ratio : 0.0 , // disabled
567+ trigger_random_drop_ratio : 0.0 , // disabled
568+ random_drop_ratio : 0.0 , // disabled
569+ write_stall_threshold_ratio : 0.0 , // disabled
558570 } ;
559571
560572 let store: ReadOnlyFileStore < u64 , Vec < u8 > > =
@@ -607,8 +619,9 @@ mod tests {
607619 capacity : 16 * 1024 ,
608620 trigger_reclaim_garbage_ratio : 0.0 , // disabled
609621 trigger_reclaim_capacity_ratio : 0.75 ,
610- trigger_random_drop_ratio : 0.0 , // disabled
611- random_drop_ratio : 0.0 , // disabled
622+ trigger_random_drop_ratio : 0.0 , // disabled
623+ random_drop_ratio : 0.0 , // disabled
624+ write_stall_threshold_ratio : 0.0 , // disabled
612625 } ;
613626
614627 let store: ReadOnlyFileStore < u64 , Vec < u8 > > =
0 commit comments