From 3d726387ac5fb7e0c91de1dd0542e973dc048fc2 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 17 Mar 2026 19:01:10 -0700 Subject: [PATCH] Include preallocate in compaction space check matching Go Go uses max(preallocate, estimatedCompactSize) for the free space check. Rust was only using the estimated volume size, which could start a compaction that fails mid-way if preallocate exceeds the volume size. --- seaweed-volume/src/storage/store.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/seaweed-volume/src/storage/store.rs b/seaweed-volume/src/storage/store.rs index c722e8ac2..94dbbda3f 100644 --- a/seaweed-volume/src/storage/store.rs +++ b/seaweed-volume/src/storage/store.rs @@ -780,16 +780,18 @@ impl Store { let dir = self.locations[loc_idx].directory.clone(); let (_, free) = crate::storage::disk_location::get_disk_stats(&dir); - // Compute required space from current volume sizes - let required_space = { + // Compute required space: use the larger of preallocate or estimated volume size + // matching Go's CompactVolume space check + let space_needed = { let (_, v) = self.find_volume(vid).unwrap(); - v.dat_file_size().unwrap_or(0) + v.idx_file_size() + let estimated = v.dat_file_size().unwrap_or(0) + v.idx_file_size(); + std::cmp::max(preallocate, estimated) }; - if free < required_space { + if free < space_needed { return Err(format!( "not enough free space to compact volume {}. Required: {}, Free: {}", - vid.0, required_space, free + vid.0, space_needed, free )); }