MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / validate_slice_routing

Function validate_slice_routing

nodedb-cluster/src/distributed_array/handler.rs:199–217  ·  view source on GitHub ↗

Validate that a SLICE request is routed to the correct shard. Returns `Ok(())` when `prefix_bits == 0` (no validation) or when `local_vshard_id` falls within the Hilbert ranges carried by the request. Returns `Err(ClusterError::WrongOwner)` when this shard no longer covers any of the requested ranges, indicating a stale routing table.

(req: &ArrayShardSliceReq, local_vshard_id: u32)

Source from the content-addressed store, hash-verified

197/// Returns `Err(ClusterError::WrongOwner)` when this shard no longer covers
198/// any of the requested ranges, indicating a stale routing table.
199fn validate_slice_routing(req: &ArrayShardSliceReq, local_vshard_id: u32) -> Result<()> {
200 if req.prefix_bits == 0 || req.slice_hilbert_ranges.is_empty() {
201 return Ok(());
202 }
203 // Compute which vShards overlap the slice ranges. If local_vshard_id is not
204 // among them, this node no longer owns the required Hilbert range.
205 let covered = array_vshards_for_slice(
206 &req.slice_hilbert_ranges,
207 req.prefix_bits,
208 crate::routing::VSHARD_COUNT,
209 )?;
210 if covered.binary_search(&local_vshard_id).is_err() {
211 return Err(ClusterError::WrongOwner {
212 vshard_id: local_vshard_id,
213 expected_owner_node: None,
214 });
215 }
216 Ok(())
217}
218
219/// Validate that a DELETE request is routed to the correct shard.
220///

Calls 2

array_vshards_for_sliceFunction · 0.85
is_emptyMethod · 0.45