From 3c18084aeff615e99cc607c3cf022ed4833abd67 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 17 Mar 2026 18:10:50 -0700 Subject: [PATCH] Include disk-space-low in Volume.is_read_only() matching Go --- seaweed-volume/src/storage/disk_location.rs | 11 +++++++---- seaweed-volume/src/storage/volume.rs | 10 +++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/seaweed-volume/src/storage/disk_location.rs b/seaweed-volume/src/storage/disk_location.rs index f7c02f500..9358cedea 100644 --- a/seaweed-volume/src/storage/disk_location.rs +++ b/seaweed-volume/src/storage/disk_location.rs @@ -8,6 +8,7 @@ use std::collections::{HashMap, HashSet}; use std::fs; use std::io; use std::sync::atomic::{AtomicBool, AtomicI32, AtomicU64, Ordering}; +use std::sync::Arc; use tracing::{info, warn}; @@ -33,7 +34,7 @@ pub struct DiskLocation { pub original_max_volume_count: i32, volumes: HashMap, ec_volumes: HashMap, - pub is_disk_space_low: AtomicBool, + pub is_disk_space_low: Arc, pub available_space: AtomicU64, pub min_free_space: MinFreeSpace, } @@ -69,7 +70,7 @@ impl DiskLocation { original_max_volume_count: max_volume_count, volumes: HashMap::new(), ec_volumes: HashMap::new(), - is_disk_space_low: AtomicBool::new(false), + is_disk_space_low: Arc::new(AtomicBool::new(false)), available_space: AtomicU64::new(0), min_free_space, }) @@ -188,7 +189,8 @@ impl DiskLocation { 0, // no preallocate on load Version::current(), ) { - Ok(v) => { + Ok(mut v) => { + v.location_disk_space_low = self.is_disk_space_low.clone(); crate::metrics::VOLUME_GAUGE .with_label_values(&[&collection, "volume"]) .inc(); @@ -343,7 +345,7 @@ impl DiskLocation { preallocate: u64, version: Version, ) -> Result<(), VolumeError> { - let v = Volume::new( + let mut v = Volume::new( &self.directory, &self.idx_directory, collection, @@ -354,6 +356,7 @@ impl DiskLocation { preallocate, version, )?; + v.location_disk_space_low = self.is_disk_space_low.clone(); crate::metrics::VOLUME_GAUGE .with_label_values(&[collection, "volume"]) .inc(); diff --git a/seaweed-volume/src/storage/volume.rs b/seaweed-volume/src/storage/volume.rs index 885813da2..742590d6b 100644 --- a/seaweed-volume/src/storage/volume.rs +++ b/seaweed-volume/src/storage/volume.rs @@ -12,6 +12,7 @@ use std::fs::{self, File, OpenOptions}; use std::io::{self, Read, Seek, SeekFrom, Write}; use std::path::Path; +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::sync::{Condvar, Mutex}; use std::time::{SystemTime, UNIX_EPOCH}; @@ -470,6 +471,10 @@ pub struct Volume { no_write_or_delete: bool, no_write_can_delete: bool, + /// Shared flag from the parent DiskLocation indicating low disk space. + /// Matches Go's `v.location.isDiskSpaceLow` checked in `IsReadOnly()`. + pub location_disk_space_low: Arc, + last_modified_ts_seconds: u64, last_append_at_ns: u64, @@ -541,6 +546,7 @@ impl Volume { }, no_write_or_delete: false, no_write_can_delete: false, + location_disk_space_low: Arc::new(AtomicBool::new(false)), last_modified_ts_seconds: 0, last_append_at_ns: 0, last_compact_index_offset: 0, @@ -1614,7 +1620,9 @@ impl Volume { } pub fn is_read_only(&self) -> bool { - self.no_write_or_delete || self.no_write_can_delete + self.no_write_or_delete + || self.no_write_can_delete + || self.location_disk_space_low.load(Ordering::Relaxed) } pub fn is_no_write_or_delete(&self) -> bool {