From 8e4df35999e607ac1676987f25f6bcb9bef5f3bd Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 17 Mar 2026 19:02:18 -0700 Subject: [PATCH] Treat MaxVolumeCount==0 as unlimited matching Go's hasFreeDiskLocation Go's hasFreeDiskLocation returns true immediately when MaxVolumeCount is 0, treating it as unlimited. Rust was computing effective_free as <= 0 for max==0, rejecting the location. This could fail volume creation during early startup before the first heartbeat adjusts max. --- seaweed-volume/src/storage/store.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/seaweed-volume/src/storage/store.rs b/seaweed-volume/src/storage/store.rs index 94dbbda3f..94ace8894 100644 --- a/seaweed-volume/src/storage/store.rs +++ b/seaweed-volume/src/storage/store.rs @@ -139,12 +139,18 @@ impl Store { if &loc.disk_type != disk_type { continue; } - // Go formula: currentFreeCount = (MaxVolumeCount - VolumesLen()) * DataShardsCount - EcShardCount() - // currentFreeCount /= DataShardsCount + // Go treats MaxVolumeCount == 0 as unlimited (hasFreeDiskLocation) let max = loc.max_volume_count.load(Ordering::Relaxed) as i64; - let free_count = (max - loc.volumes_len() as i64) * DATA_SHARDS_COUNT as i64 - - loc.ec_shard_count() as i64; - let effective_free = free_count / DATA_SHARDS_COUNT as i64; + let effective_free = if max == 0 { + i64::MAX // unlimited + } else { + // Go formula: currentFreeCount = (MaxVolumeCount - VolumesLen()) * DataShardsCount - EcShardCount() + // currentFreeCount /= DataShardsCount + let free_count = (max - loc.volumes_len() as i64) + * DATA_SHARDS_COUNT as i64 + - loc.ec_shard_count() as i64; + free_count / DATA_SHARDS_COUNT as i64 + }; if effective_free <= 0 { continue; }