From c527cfd8c7240813f25a51fb067046f1376d7bef Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 10 Mar 2026 12:35:21 -0700 Subject: [PATCH] fix: guard against nil needle map before compaction sync Add an early check for None needle map in do_compact_by_index, matching Go's defensive nil check (commit 889ae7d22). In Rust the store RwLock prevents the concurrent vacuum race that Go fixes with atomic.Bool, but the nil guard is still useful as defensive code. --- seaweed-volume/src/storage/volume.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/seaweed-volume/src/storage/volume.rs b/seaweed-volume/src/storage/volume.rs index 18a15974f..502eb88e1 100644 --- a/seaweed-volume/src/storage/volume.rs +++ b/seaweed-volume/src/storage/volume.rs @@ -1800,6 +1800,14 @@ impl Volume { where F: Fn(i64) -> bool, { + // Guard against nil needle map (matches Go's nil check before compaction sync) + if self.nm.is_none() { + return Err(VolumeError::Io(io::Error::new( + io::ErrorKind::Other, + format!("volume {} needle map is nil", self.id), + ))); + } + // Record state before compaction for makeupDiff self.last_compact_index_offset = self.nm.as_ref().map_or(0, |nm| nm.index_file_size()); self.last_compact_revision = self.super_block.compaction_revision;