| @@ -298,6 +298,101 @@ fn an_index_load_is_registered_before_its_slot_is_reserved() -> Result { · 297 unmodified lines |
| 298 | Ok(()) | 298 | Ok(()) |
| 299 | } | 299 | } |
| 300 | | 300 | |
| | 301 | #[cfg(feature = "parallel")] |
| | 302 | #[test] |
| | 303 | fn a_handle_rechecks_its_snapshot_after_waiting_for_an_index_loader() -> Result { |
| | 304 | use std::{ |
| | 305 | sync::{ |
| | 306 | Arc, |
| | 307 | atomic::{AtomicBool, Ordering}, |
| | 308 | }, |
| | 309 | time::Duration, |
| | 310 | }; |
| | 311 | |
| | 312 | use gix_odb::store::init::debug::Point; |
| | 313 | |
| | 314 | let mut fixture = OdbFixture::from_script()?; |
| | 315 | fixture.install_pack(Database::Primary, Pack::A)?; |
| | 316 | fixture.install_pack(Database::Alternate, Pack::B)?; |
| | 317 | fixture.corrupt_index(Database::Alternate, Pack::B)?; |
| | 318 | fixture.set_alternate(true)?; |
| | 319 | |
| | 320 | let (point_tx, point_rx) = crossbeam_channel::unbounded(); |
| | 321 | let (resume_waiter_tx, resume_waiter_rx) = crossbeam_channel::bounded(0); |
| | 322 | let pause_waiter = Arc::new(AtomicBool::new(false)); |
| | 323 | let debug = gix_odb::store::init::debug::Options::new({ |
| | 324 | let pause_waiter = Arc::clone(&pause_waiter); |
| | 325 | move |point| { |
| | 326 | point_tx |
| | 327 | .send(point) |
| | 328 | .expect("the test receives every synchronization point"); |
| | 329 | if matches!(point, Point::IndexRetrySlotLocking { .. }) && pause_waiter.swap(false, Ordering::SeqCst) { |
| | 330 | resume_waiter_rx |
| | 331 | .recv() |
| | 332 | .expect("the test releases the stale handle's retry"); |
| | 333 | } |
| | 334 | } |
| | 335 | }); |
| | 336 | let mut handle = gix_odb::at_opts( |
| | 337 | fixture.objects_dir(Database::Primary), |
| | 338 | fixture.manifest.object_hash, |
| | 339 | Vec::new(), |
| | 340 | gix_odb::store::init::Options { |
| | 341 | slots: gix_odb::store::init::Slots::Limit(2), |
| | 342 | debug: Some(debug), |
| | 343 | ..Default::default() |
| | 344 | }, |
| | 345 | )? |
| | 346 | .into_arc()?; |
| | 347 | assert_object(&handle, &fixture.manifest.pack(Pack::A).object_ids[0])?; |
| | 348 | let second_object_id = fixture.manifest.pack(Pack::B).object_ids[0]; |
| | 349 | handle |
| | 350 | .try_header(&second_object_id) |
| | 351 | .expect_err("the second index records a failed load before it can be retried"); |
| | 352 | handle.refresh_never(); |
| | 353 | let stale = handle.clone(); |
| | 354 | let loader = handle.clone(); |
| | 355 | fixture.publish(Database::Alternate, Pack::B, Component::Index)?; |
| | 356 | point_rx.try_iter().for_each(drop); |
| | 357 | |
| | 358 | let lookup = move |handle: gix_odb::HandleArc| { |
| | 359 | std::thread::spawn(move || { |
| | 360 | handle |
| | 361 | .try_header(&second_object_id) |
| | 362 | .map(|header| header.is_some()) |
| | 363 | .map_err(|err| err.to_string()) |
| | 364 | }) |
| | 365 | }; |
| | 366 | pause_waiter.store(true, Ordering::SeqCst); |
| | 367 | let stale_thread = lookup(stale); |
| | 368 | loop { |
| | 369 | let point = point_rx |
| | 370 | .recv_timeout(Duration::from_secs(10)) |
| | 371 | .expect("the stale handle is about to lock the failed index for a retry"); |
| | 372 | if matches!(point, Point::IndexRetrySlotLocking { .. }) { |
| | 373 | break; |
| | 374 | } |
| | 375 | } |
| | 376 | // Another loader publishes the repaired index while the stale handle is paused before acquiring its retry lock. |
| | 377 | let loaded = lookup(loader).join().expect("the loader does not panic"); |
| | 378 | resume_waiter_tx |
| | 379 | .send(()) |
| | 380 | .expect("the stale handle is waiting for its release"); |
| | 381 | |
| | 382 | assert!( |
| | 383 | loaded.expect("the loader lookup succeeds"), |
| | 384 | "the loading handle finds the object" |
| | 385 | ); |
| | 386 | assert!( |
| | 387 | stale_thread |
| | 388 | .join() |
| | 389 | .expect("the stale lookup does not panic") |
| | 390 | .expect("the stale lookup succeeds"), |
| | 391 | "the stale handle observes the index published while it waited" |
| | 392 | ); |
| | 393 | Ok(()) |
| | 394 | } |
| | 395 | |
| 301 | #[cfg(feature = "parallel")] | 396 | #[cfg(feature = "parallel")] |
| 302 | #[test] | 397 | #[test] |
| 303 | fn debug_hooks_coordinate_contending_failed_index_loaders() -> Result { | 398 | fn debug_hooks_coordinate_contending_failed_index_loaders() -> Result { |