Browse Source

Include disk-space-low in Volume.is_read_only() matching Go

rust-volume-server
Chris Lu 2 days ago
parent
commit
3c18084aef
  1. 11
      seaweed-volume/src/storage/disk_location.rs
  2. 10
      seaweed-volume/src/storage/volume.rs

11
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<VolumeId, Volume>,
ec_volumes: HashMap<VolumeId, EcVolume>,
pub is_disk_space_low: AtomicBool,
pub is_disk_space_low: Arc<AtomicBool>,
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();

10
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<AtomicBool>,
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 {

Loading…
Cancel
Save