Browse Source

Match Go DeleteCollection: propagate destroy errors

pull/8539/head
Chris Lu 2 weeks ago
parent
commit
d1d2b10212
  1. 9
      seaweed-volume/src/storage/disk_location.rs
  2. 8
      seaweed-volume/src/storage/store.rs

9
seaweed-volume/src/storage/disk_location.rs

@ -388,7 +388,7 @@ impl DiskLocation {
} }
/// Delete all volumes in a collection. /// Delete all volumes in a collection.
pub fn delete_collection(&mut self, collection: &str) {
pub fn delete_collection(&mut self, collection: &str) -> Result<(), VolumeError> {
let vids: Vec<VolumeId> = self let vids: Vec<VolumeId> = self
.volumes .volumes
.iter() .iter()
@ -401,7 +401,7 @@ impl DiskLocation {
crate::metrics::VOLUME_GAUGE crate::metrics::VOLUME_GAUGE
.with_label_values(&[&v.collection, "volume"]) .with_label_values(&[&v.collection, "volume"])
.dec(); .dec();
let _ = v.destroy();
v.destroy()?;
} }
} }
@ -422,6 +422,7 @@ impl DiskLocation {
ec_vol.destroy(); ec_vol.destroy();
} }
} }
Ok(())
} }
// ---- Metrics ---- // ---- Metrics ----
@ -871,7 +872,7 @@ mod tests {
.unwrap(); .unwrap();
assert_eq!(loc.volumes_len(), 3); assert_eq!(loc.volumes_len(), 3);
loc.delete_collection("pics");
loc.delete_collection("pics").unwrap();
assert_eq!(loc.volumes_len(), 1); assert_eq!(loc.volumes_len(), 1);
assert!(loc.find_volume(VolumeId(3)).is_some()); assert!(loc.find_volume(VolumeId(3)).is_some());
} }
@ -898,7 +899,7 @@ mod tests {
assert!(std::path::Path::new(&shard_path).exists()); assert!(std::path::Path::new(&shard_path).exists());
assert!(std::path::Path::new(&format!("{}/pics_7.ecj", dir)).exists()); assert!(std::path::Path::new(&format!("{}/pics_7.ecj", dir)).exists());
loc.delete_collection("pics");
loc.delete_collection("pics").unwrap();
assert!(!loc.has_ec_volume(VolumeId(7))); assert!(!loc.has_ec_volume(VolumeId(7)));
assert!(!std::path::Path::new(&shard_path).exists()); assert!(!std::path::Path::new(&shard_path).exists());

8
seaweed-volume/src/storage/store.rs

@ -373,11 +373,13 @@ impl Store {
// ---- Collection operations ---- // ---- Collection operations ----
/// Delete all volumes in a collection. /// Delete all volumes in a collection.
pub fn delete_collection(&mut self, collection: &str) {
pub fn delete_collection(&mut self, collection: &str) -> Result<(), String> {
for loc in &mut self.locations { for loc in &mut self.locations {
loc.delete_collection(collection);
loc.delete_collection(collection)
.map_err(|e| format!("delete collection {}: {}", collection, e))?;
} }
crate::metrics::delete_collection_metrics(collection); crate::metrics::delete_collection_metrics(collection);
Ok(())
} }
// ---- Metrics ---- // ---- Metrics ----
@ -987,7 +989,7 @@ mod tests {
.unwrap(); .unwrap();
assert_eq!(store.total_volume_count(), 3); assert_eq!(store.total_volume_count(), 3);
store.delete_collection("pics");
store.delete_collection("pics").unwrap();
assert_eq!(store.total_volume_count(), 1); assert_eq!(store.total_volume_count(), 1);
assert!(store.has_volume(VolumeId(3))); assert!(store.has_volume(VolumeId(3)));
} }

Loading…
Cancel
Save