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 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-22 11:38:48 -08:00
1 parent 31fd0b834e
commit cbeaa63e2e
2 files changed
+70 -2

No files matched your search

+33
View File
@@ -1353,6 +1353,23 @@ async fn fetch_one_interval(
map: EcShardMap<'_>,
) -> io::Result<(Vec<u8>, 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<VolumeServerState>,
vid: VolumeId,
shard_id: ShardId,
) -> Option<Vec<String>> {
let store = state.store.read().unwrap();
store.find_ec_volume(vid)?.shard_read_hints(shard_id)
}
fn forget_shard_read_hints(state: &Arc<VolumeServerState>, 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<VolumeServerState>, vid: VolumeId, shard_id: ShardId) {
@@ -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<ShardId, Vec<String>>,
/// 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<ShardId, Vec<String>>,
/// 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<Vec<String>> {
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]