Skip to content

Commit

Permalink
try to recreate multi-threaded panic, without success. (#536)
Browse files Browse the repository at this point in the history
It's supposed to happen when multiple threads, maybe, trigger the
loading of packs at the same time. There are 15 packs to load
here but apparently that doesn't manage to trigger it.
  • Loading branch information
Byron committed Sep 21, 2022
1 parent 730384d commit 53b5086
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions git-odb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ git-actor = { path = "../git-actor" }
pretty_assertions = "1.0.0"
filetime = "0.2.15"
maplit = "1.0.2"
num_cpus = "1.13.1"
crossbeam-channel = "0.5.6"

[package.metadata.docs.rs]
features = ["document-features", "serde1"]
Expand Down
Git LFS file not shown
9 changes: 6 additions & 3 deletions git-odb/tests/fixtures/make_repo_multi_index.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
set -eu -o pipefail

omit_multi_index=${1:-no}

git init -q
git config commit.gpgsign false

Expand All @@ -26,6 +28,7 @@ for round in $(seq $rounds); do
write_files "${dirs[$dir_index]}" $num_files "$round"
git add .
git commit -qm "$round $num_files"
git repack
done

echo hello world > referee
Expand All @@ -34,6 +37,6 @@ git commit -qm "to be forgotten"
git tag -m "a tag object" referrer
git reset --hard HEAD~1

# speed up all access by creating a pack
git gc --aggressive
git multi-pack-index write
if [ "$omit_multi_index" == "no" ]; then
git multi-pack-index write
fi
51 changes: 47 additions & 4 deletions git-odb/tests/odb/regression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,58 @@ mod repo_with_small_packs {
use crate::odb::{fixture_path, hex_to_id};

#[test]
fn all_packed_objects_can_be_found() {
let store = git_odb::at(fixture_path("repos/small-packs.git/objects")).unwrap();
fn all_packed_objects_can_be_found() -> crate::Result {
let store = git_odb::at(fixture_path("repos/small-packs.git/objects"))?;
let mut buf = Vec::new();
assert!(
store
.try_find(hex_to_id("ecc68100297fff843a7eef8df0d0fb80c1c8bac5"), &mut buf)
.unwrap()
.try_find(hex_to_id("ecc68100297fff843a7eef8df0d0fb80c1c8bac5"), &mut buf)?
.is_some(),
"object is present and available"
);
Ok(())
}

#[test]
#[cfg(feature = "internal-testing-git-features-parallel")]
fn multi_threaded_access_will_not_panic() {
for arg in ["no", "without-multi-index"] {
let base = git_testtools::scripted_fixture_repo_read_only_with_args("make_repo_multi_index.sh", Some(arg))
.unwrap()
.join(".git")
.join("objects");
let store = git_odb::at(base).unwrap();
let (tx, barrier) = crossbeam_channel::unbounded::<()>();
let handles = (0..num_cpus::get()).map(|tid| {
std::thread::spawn({
let store = store.clone();
let barrier = barrier.clone();
move || {
barrier.recv().ok();
let mut buf = Vec::new();
let mut count = 0;
for id in store.iter().unwrap() {
let id = id.unwrap();
assert!(
store.try_find(id, &mut buf).is_ok(),
"Thread {} could not find {}",
tid,
id
);
count += 1;
}
count
}
})
});

std::thread::sleep(std::time::Duration::from_millis(50));
drop(tx);
let expected = store.iter().unwrap().count();
for handle in handles {
let actual = handle.join().expect("no panic");
assert_eq!(actual, expected);
}
}
}
}
16 changes: 8 additions & 8 deletions git-odb/tests/odb/store/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn multi_index_access() -> crate::Result {
assert!(handle.find(oid, &mut buf).is_ok());
count += 1;
}
assert_eq!(count, 868);
assert_eq!(count, 1732);

assert_eq!(
handle.store_ref().metrics(),
Expand All @@ -71,8 +71,8 @@ fn multi_index_access() -> crate::Result {
num_refreshes: 1,
open_reachable_indices: 1,
known_reachable_indices: 1,
open_reachable_packs: 1,
known_packs: 1,
open_reachable_packs: 15,
known_packs: 15,
unused_slots: 31,
loose_dbs: 1,
unreachable_indices: 0,
Expand All @@ -91,8 +91,8 @@ fn multi_index_access() -> crate::Result {
num_refreshes: 2,
open_reachable_indices: 1,
known_reachable_indices: 1,
open_reachable_packs: 1,
known_packs: 1,
open_reachable_packs: 15,
known_packs: 15,
unused_slots: 31,
loose_dbs: 1,
unreachable_indices: 0,
Expand All @@ -115,7 +115,7 @@ fn multi_index_access() -> crate::Result {
open_reachable_indices: 1,
known_reachable_indices: 1,
open_reachable_packs: 0,
known_packs: 1,
known_packs: 15,
unused_slots: 31,
loose_dbs: 1,
unreachable_indices: 0,
Expand Down Expand Up @@ -147,7 +147,7 @@ fn multi_index_keep_open() -> crate::Result {
open_reachable_indices: 1,
known_reachable_indices: 1,
open_reachable_packs: 0,
known_packs: 1,
known_packs: 15,
unused_slots: 31,
loose_dbs: 1,
unreachable_indices: 0,
Expand Down Expand Up @@ -176,7 +176,7 @@ fn multi_index_keep_open() -> crate::Result {
open_reachable_indices: 1,
known_reachable_indices: 1,
open_reachable_packs: 0, /*no pack is open anymore at least as seen from the index*/
known_packs: 1,
known_packs: 15,
unused_slots: 30,
loose_dbs: 1,
unreachable_indices: 1,
Expand Down

0 comments on commit 53b5086

Please sign in to comment.