From cbeaa63e2ed490768b49cee332efa19697f79f82 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 22 Nov 2026 11:38:48 -0800 Subject: [PATCH] seaweed-volume: ask a delisted EC shard holder before rebuilding the shard Mirrors Go: a complete lookup that places a shard nowhere moves its cached holders to read hints, which fetch_one_interval tries before reconstructing and drops once they fail. Deletes and recovery keep using only the placed locations. Co-Authored-By: Claude Opus 5.5 --- seaweed-volume/src/server/store_ec.rs | 33 ++++++++++++++++ .../src/storage/erasure_coding/ec_volume.rs | 39 ++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/seaweed-volume/src/server/store_ec.rs b/seaweed-volume/src/server/store_ec.rs index b8485371ae..6f7c7981b6 100644 --- a/seaweed-volume/src/server/store_ec.rs +++ b/seaweed-volume/src/server/store_ec.rs @@ -1353,6 +1353,23 @@ async fn fetch_one_interval( map: EcShardMap<'_>, ) -> io::Result<(Vec, bool)> { let EcInterval { vid, shard_id, .. } = iv; + if map.locations.get(&shard_id).is_none_or(Vec::is_empty) + && let Some(hints) = shard_read_hints(state, vid, shard_id) + { + match read_remote_ec_shard_interval(state, &hints, iv).await { + Ok(read) => return Ok(read), + Err(e) => { + tracing::debug!( + "read ec shard {}.{} from delisted holders {:?} failed: {}", + vid.0, + shard_id, + hints, + e + ); + forget_shard_read_hints(state, vid, shard_id); + } + } + } // Direct peer read against the cached locations for this shard. if let Some(sources) = map.locations.get(&shard_id) && !sources.is_empty() @@ -1837,6 +1854,22 @@ async fn recover_one_remote_ec_shard_interval( } } +fn shard_read_hints( + state: &Arc, + vid: VolumeId, + shard_id: ShardId, +) -> Option> { + let store = state.store.read().unwrap(); + store.find_ec_volume(vid)?.shard_read_hints(shard_id) +} + +fn forget_shard_read_hints(state: &Arc, vid: VolumeId, shard_id: ShardId) { + let store = state.store.read().unwrap(); + if let Some(ecv) = store.find_ec_volume(vid) { + ecv.forget_shard_read_hints(shard_id); + } +} + /// Drop a confirmed-corrupt shard's cached location so later reads go straight /// to reconstruction — Go's `forgetShardId` reached through the volume. fn forget_shard_location(state: &Arc, vid: VolumeId, shard_id: ShardId) { diff --git a/seaweed-volume/src/storage/erasure_coding/ec_volume.rs b/seaweed-volume/src/storage/erasure_coding/ec_volume.rs index 3f856e3262..bf0f8f8f0a 100644 --- a/seaweed-volume/src/storage/erasure_coding/ec_volume.rs +++ b/seaweed-volume/src/storage/erasure_coding/ec_volume.rs @@ -31,6 +31,11 @@ pub(crate) struct ShardLocationCache { /// Maps shard ID -> list of server addresses where that shard exists. /// Used for distributed EC reads across the cluster. locations: HashMap>, + /// Holders a complete lookup stopped placing a shard on (Go's + /// `ShardReadHints`). Only reads consult them, before reconstructing: such a + /// holder may still answer, and may be the one that journaled a delete. + /// Deletes never do. + read_hints: HashMap>, /// Wall-clock timestamp of the most recent successful `LookupEcVolume` /// refresh of `locations`. `None` until the first refresh. Drives the /// staleness heuristic in `cached_lookup_ec_shard_locations` (mirrors Go's @@ -1741,8 +1746,13 @@ impl EcVolume { let mut cache = self.shard_locations.write().unwrap(); for (shard_id, addrs) in locations { if addrs.is_empty() { - cache.locations.remove(&shard_id); + if let Some(known) = cache.locations.remove(&shard_id) + && !known.is_empty() + { + cache.read_hints.insert(shard_id, known); + } } else { + cache.read_hints.remove(&shard_id); cache.locations.insert(shard_id, addrs); } } @@ -1787,6 +1797,19 @@ impl EcVolume { (cache.locations.clone(), cache.refreshed_at) } + pub(crate) fn shard_read_hints(&self, shard_id: ShardId) -> Option> { + let cache = self.shard_locations.read().unwrap(); + cache.read_hints.get(&shard_id).cloned() + } + + pub(crate) fn forget_shard_read_hints(&self, shard_id: ShardId) { + self.shard_locations + .write() + .unwrap() + .read_hints + .remove(&shard_id); + } + /// Mark the cached map for a prompt re-check after a read failed against one /// of its locations. pub(crate) fn mark_shard_locations_stale(&self) { @@ -5482,9 +5505,21 @@ mod tests { ); // A shard the master places nowhere is dropped, not kept at an address - // a delete would trust. + // a delete would trust; its holder stays a place a read can ask first. let merged = vol.merge_shard_locations(HashMap::from([(0, Vec::new())])); assert_eq!(merged, HashMap::from([(1, vec!["c:3".to_string()])])); + assert_eq!(vol.shard_read_hints(0), Some(vec!["a:1".to_string()])); + vol.merge_shard_locations(HashMap::from([(0, Vec::new())])); + assert_eq!( + vol.shard_read_hints(0), + Some(vec!["a:1".to_string()]), + "a later reply placing the shard nowhere keeps the hint" + ); + vol.merge_shard_locations(HashMap::from([(0, vec!["d:4".to_string()])])); + assert_eq!(vol.shard_read_hints(0), None); + vol.merge_shard_locations(HashMap::from([(0, Vec::new())])); + vol.forget_shard_read_hints(0); + assert_eq!(vol.shard_read_hints(0), None); } #[test]