From a6af5cb75d5d3401bced8d9c0e30242ac32344e7 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 3 Dec 2026 16:46:07 -0800 Subject: [PATCH] volume(rs): skip the missing-.dat check while a volume is compacting Mirrors the Go change: the heartbeat reads the commit-start status without waiting for the commit, and a Windows commit removes the .dat before it renames the compacted one in, so the check dropped the volume from a heartbeat taken in that gap. Co-Authored-By: Claude Opus 5.5 --- seaweed-volume/src/server/heartbeat.rs | 57 +++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/seaweed-volume/src/server/heartbeat.rs b/seaweed-volume/src/server/heartbeat.rs index b2ed42fc75..f69b037fdc 100644 --- a/seaweed-volume/src/server/heartbeat.rs +++ b/seaweed-volume/src/server/heartbeat.rs @@ -1391,7 +1391,9 @@ fn build_heartbeat_with_ec_status( // whose .dat legitimately lives in cloud storage. Only a present .dat is // cached for 30s; a missing one is re-checked every heartbeat so the volume // stays suppressed until the file returns. See issues/10004 - if status.file_count > 0 && !vol.has_remote_file() { + // A commit on Windows removes the .dat before it renames the + // compacted one in, so a compacting volume is not checked. + if status.file_count > 0 && !vol.has_remote_file() && !vol.is_compacting() { const DISK_CHECK_INTERVAL_NS: i64 = 30 * 1_000_000_000; let now_ns = SystemTime::now() .duration_since(UNIX_EPOCH) @@ -3776,4 +3778,57 @@ mod tests { assert_eq!(heartbeat.ec_shards[0].file_count, 3); assert_eq!(heartbeat.ec_shards[0].delete_count, 1); } + + // The commit-start status keeps the volume reported while a commit runs, + // so the missing-.dat check must not drop it in the gap of a Windows swap. + #[test] + fn test_compacting_volume_is_not_taken_for_phantom() { + use crate::storage::needle::needle::Needle; + use crate::storage::types::{Cookie, NeedleId}; + + let temp_dir = tempfile::tempdir().unwrap(); + let dir = temp_dir.path().to_str().unwrap(); + let vid = VolumeId(1368); + let mut store = Store::new(NeedleMapKind::InMemory); + store + .add_location( + dir, + dir, + 8, + DiskType::HardDrive, + MinFreeSpace::Percent(1.0), + Vec::new(), + ) + .unwrap(); + store + .add_volume(vid, DiskType::HardDrive, &VolumeSpec::default()) + .unwrap(); + let mut n = Needle { + id: NeedleId(1), + cookie: Cookie(1), + data_size: 4, + data: b"live".to_vec(), + ..Needle::default() + }; + store.write_volume_needle(vid, &mut n, true).unwrap(); + let (_, vol) = store.find_volume(vid).unwrap(); + let dat = vol.file_name(".dat"); + let swapping = format!("{dat}.swapping"); + std::fs::rename(&dat, &swapping).unwrap(); + + let claim = vol.claim_compaction().unwrap(); + let during = build_heartbeat(&test_config(), &mut store); + drop(claim); + let after = build_heartbeat(&test_config(), &mut store); + std::fs::rename(&swapping, &dat).unwrap(); + assert_eq!( + during.volumes.len(), + 1, + "a compacting volume was dropped from the report" + ); + assert!( + after.volumes.is_empty(), + "a volume whose .dat is missing was reported" + ); + } }