@@ -3342,15 +3342,55 @@ impl Downstairs {
3342
3342
* requests for this client.
3343
3343
*/
3344
3344
fn new_work ( & mut self , client_id : u8 ) -> Vec < u64 > {
3345
- self . ds_new [ client_id as usize ] . drain ( ..) . collect ( )
3345
+ // Compute what should be in the ds_new cache, and assert that the cache
3346
+ // is valid. This should only run during debug builds (read: CI) and
3347
+ // should not affect release builds as this will degrade performance.
3348
+ let computed: usize = self
3349
+ . ds_active
3350
+ . values ( )
3351
+ . filter_map ( |job| {
3352
+ if let Some ( IOState :: New ) = job. state . get ( & client_id) {
3353
+ Some ( job. ds_id )
3354
+ } else {
3355
+ None
3356
+ }
3357
+ } )
3358
+ . count ( ) ;
3359
+
3360
+ let cached: Vec < u64 > =
3361
+ self . ds_new [ client_id as usize ] . drain ( ..) . collect ( ) ;
3362
+
3363
+ debug_assert_eq ! ( computed, cached. len( ) ) ;
3364
+
3365
+ // Assert that the io_state_count accounting is accurate.
3366
+ debug_assert_eq ! (
3367
+ self . io_state_count. new[ client_id as usize ] as usize ,
3368
+ cached. len( ) ,
3369
+ ) ;
3370
+
3371
+ cached
3346
3372
}
3347
3373
3348
3374
/**
3349
3375
* Called to requeue work that was previously found by calling
3350
3376
* [`new_work`], presumably due to flow control.
3351
3377
*/
3352
3378
fn requeue_work ( & mut self , client_id : u8 , work : & [ u64 ] ) {
3379
+ // Assert that the work we're requeuing is still new. This should only
3380
+ // run during debug builds (read: CI) and should not affect release
3381
+ // builds as this will degrade performance.
3382
+ for job_id in work {
3383
+ let job = self . ds_active . get_mut ( job_id) . unwrap ( ) ;
3384
+ debug_assert_eq ! ( * job. state. get( & client_id) . unwrap( ) , IOState :: New ) ;
3385
+ }
3386
+
3353
3387
self . ds_new [ client_id as usize ] . extend_from_slice ( work) ;
3388
+
3389
+ // Assert that the io_state_count accounting is accurate.
3390
+ debug_assert_eq ! (
3391
+ self . io_state_count. new[ client_id as usize ] as usize ,
3392
+ self . ds_new[ client_id as usize ] . len( ) ,
3393
+ ) ;
3354
3394
}
3355
3395
3356
3396
/**
0 commit comments