rust: trim the new comments in the volume loader

This commit is contained in:
Chris Lu
2026-08-06 15:30:20 -07:00
parent 12c8df3405
commit a67079dba5
2 changed files with 18 additions and 26 deletions
+12 -17
View File
@@ -122,9 +122,8 @@ impl DiskLocation {
// Scan for .dat files
let entries = fs::read_dir(&self.directory)?;
let mut dat_files: Vec<(String, VolumeId)> = Vec::new();
// One entry per volume id, holding every collection name that claims it
// in scan order -- the loader tries them in turn and keeps the first
// that opens, so a corrupt candidate does not shadow a good one.
// Every collection claiming an id, in scan order; open_volumes keeps
// the first that opens.
let mut to_load: Vec<(VolumeId, Vec<String>)> = Vec::new();
let mut queued: HashMap<VolumeId, usize> = HashMap::new();
let mut seen = HashSet::new();
@@ -255,16 +254,14 @@ impl DiskLocation {
Ok(())
}
/// Open the volumes the directory scan selected, on a pool of worker
/// threads. Opening a volume is dominated by reading its .idx into the
/// needle map, so a disk holding thousands of them takes thousands of
/// serial index reads to come up. Mirrors Go's concurrentLoadingVolumes,
/// including its max(cores, 10) worker count -- the work is IO-bound, so
/// the floor keeps a small-core box from loading one volume at a time.
/// Open the volumes the directory scan selected. Opening one is dominated
/// by reading its .idx into the needle map, so a disk holding thousands
/// takes thousands of serial index reads to come up; mirrors Go's
/// concurrentLoadingVolumes down to the max(cores, 10) worker count, whose
/// floor keeps a small-core box off one-at-a-time on IO-bound work.
///
/// Each id carries every collection name that claims it, tried in scan
/// order until one opens: an id is only spoken for once a volume actually
/// loads, so a corrupt `colA_5.dat` still leaves `colB_5.dat` a chance.
/// An id is only spoken for once a volume actually loads, so a corrupt
/// `colA_5.dat` still leaves `colB_5.dat` a chance.
fn open_volumes(
&self,
to_load: Vec<(VolumeId, Vec<String>)>,
@@ -1552,9 +1549,8 @@ mod tests {
assert!(ids.contains(&VolumeId(2)));
}
// Two collections can name the same volume id on one disk. The id is only
// spoken for once a volume actually opens, so a candidate that fails to
// load must not shadow a good one behind it.
// Two collections can name the same volume id on one disk; a candidate
// that fails to open must not shadow a good one behind it.
#[test]
fn test_open_volumes_falls_back_past_a_corrupt_candidate() {
let tmp = TempDir::new().unwrap();
@@ -1583,8 +1579,7 @@ mod tests {
loc.close();
}
// Same id under another collection, with a superblock this build
// cannot read -- Volume::new fails on it.
// Same id under another collection, unopenable.
let mut bad = vec![0u8; 16];
bad[0] = 9; // unsupported version
std::fs::write(format!("{}/bad_9.dat", dir), &bad).unwrap();
+6 -9
View File
@@ -1974,11 +1974,9 @@ impl Volume {
/// Extra bytes mean an unindexed trailing record (a torn append);
/// appending after one would place the next needle at an offset the
/// 8-byte .idx encoding may not represent, so the volume is quarantined
/// read-only instead. Mirrors Go's verifyNeedleIntegrity, including its
/// v3-only tail check: v1/v2 volumes predate the append timestamp the
/// check rides along with, and Go serves them read-write regardless, so
/// checking them here would flip a whole legacy cluster read-only the
/// first time it boots on this server.
/// read-only instead. Mirrors Go's verifyNeedleIntegrity, whose tail
/// check is v3-only -- a v1/v2 volume Go serves read-write must not go
/// read-only here.
fn verify_needle_integrity(
&mut self,
actual_offset: i64,
@@ -4120,10 +4118,9 @@ mod tests {
);
}
// Go only compares the .dat tail on v3 volumes -- the comparison rides
// along with the v3 append-timestamp read -- so it serves a v1/v2 volume
// with an unindexed tail read-write. Checking it here anyway flipped every
// such volume read-only, which on a legacy cluster is the whole disk.
// Go's tail check is v3-only, so it serves a v1/v2 volume with an
// unindexed tail read-write. Checking it here flipped whole legacy disks
// read-only on their first boot under this server.
#[test]
fn test_integrity_skips_dat_tail_check_before_v3() {
let tmp = TempDir::new().unwrap();