Skip to main content

CrossShardEdgeManager

Struct CrossShardEdgeManager 

Source
pub struct CrossShardEdgeManager { /* private fields */ }
Expand description

Manages edges that cross shard boundaries.

When a local node has an edge to a node on another shard, this manager:

  1. Tracks the pending cross-shard edges
  2. Coordinates resolution of ghost nodes
  3. Handles edge decay synchronization across shards

§Thread Safety

This type is not thread-safe. Wrap in a mutex if concurrent access is needed.

Implementations§

Source§

impl CrossShardEdgeManager

Source

pub fn new() -> Self

Create a new cross-shard edge manager.

§Example
let manager = CrossShardEdgeManager::new();
assert_eq!(manager.edge_count(), 0);
Source

pub fn with_capacity(capacity: usize) -> Self

Create a new manager with pre-allocated capacity.

§Arguments
  • capacity - Initial capacity for edge maps
Source

pub fn add_outgoing_edge(&mut self, edge: CrossShardEdge)

Register an outgoing cross-shard edge.

The edge is added to both the outgoing edges map and the pending resolution queue. Call clear_pending() after resolving ghost nodes.

§Arguments
  • edge - The cross-shard edge to register
§Example
let edge = CrossShardEdge {
    from_node: local_id,
    to_node: remote_id,
    to_shard: ShardId::new(1),
    weight: 0.5,
};
manager.add_outgoing_edge(edge);
Source

pub fn add_outgoing_edges( &mut self, edges: impl IntoIterator<Item = CrossShardEdge>, )

Register multiple outgoing edges at once.

More efficient than calling add_outgoing_edge in a loop.

§Arguments
  • edges - Iterator of edges to register
Source

pub fn add_incoming_edge(&mut self, edge: CrossShardEdge)

Register an incoming cross-shard edge.

Incoming edges are from nodes on other shards that point to a node we own locally.

§Arguments
  • edge - The cross-shard edge to register
Source

pub fn pending_edges(&self) -> &[CrossShardEdge]

Get all pending edges that need ghost node resolution.

These are edges that have been registered but whose target nodes have not yet been fetched from their remote shards.

§Returns

A slice of pending cross-shard edges.

Source

pub fn pending_count(&self) -> usize

Get the number of pending edges.

Source

pub fn has_pending(&self) -> bool

Check if there are pending edges.

Source

pub fn clear_pending(&mut self)

Clear pending edges after resolution.

Call this after successfully fetching ghost node data for all pending edges.

Source

pub fn take_pending(&mut self) -> Vec<CrossShardEdge>

Take ownership of pending edges and clear the queue.

This is useful when you need to process the edges and don’t want to clone them.

§Returns

The vector of pending edges.

Source

pub fn get_outgoing(&self, node_id: &NodeId) -> Option<&Vec<CrossShardEdge>>

Get outgoing edges for a node.

§Arguments
  • node_id - The local node ID to look up
§Returns

The list of cross-shard edges from this node, if any.

Source

pub fn get_incoming(&self, node_id: &NodeId) -> Option<&Vec<CrossShardEdge>>

Get incoming edges for a node.

§Arguments
  • node_id - The local node ID to look up
§Returns

The list of cross-shard edges to this node, if any.

Source

pub fn has_outgoing(&self, node_id: &NodeId) -> bool

Check if a node has outgoing cross-shard edges.

Source

pub fn has_incoming(&self, node_id: &NodeId) -> bool

Check if a node has incoming cross-shard edges.

Source

pub fn remove_shard_edges(&mut self, shard_id: ShardId) -> usize

Remove edges to/from a specific shard.

This is useful when a shard goes offline and all edges to/from it should be invalidated.

§Arguments
  • shard_id - The shard whose edges should be removed
§Returns

The number of edges that were removed.

Source

pub fn remove_node_edges(&mut self, node_id: &NodeId) -> (usize, usize)

Remove all edges for a specific local node.

Call this when a local node is deleted.

§Arguments
  • node_id - The node whose edges should be removed
§Returns

A tuple of (outgoing_removed, incoming_removed).

Source

pub fn decay_edges(&mut self, rate: f64, threshold: f64) -> Vec<CrossShardEdge>

Decay cross-shard edge weights.

Applies exponential decay to all edge weights and removes edges that fall below the threshold.

§Arguments
  • rate - Decay rate (0.0 to 1.0), e.g., 0.1 means 10% decay
  • threshold - Minimum weight threshold; edges below this are pruned
§Returns

Vector of edges that were pruned due to low weight.

Source

pub fn strengthen_edge( &mut self, from_node: &NodeId, to_node: &NodeId, amount: f64, ) -> Option<f64>

Strengthen an edge weight.

§Arguments
  • from_node - Source node ID
  • to_node - Target node ID
  • amount - Amount to add to the weight
§Returns

The new weight if the edge was found, None otherwise.

Source

pub fn connected_shards(&self) -> Vec<ShardId>

Get all unique remote shards that have edges.

§Returns

A sorted, deduplicated vector of shard IDs.

Source

pub fn edges_by_shard(&self) -> HashMap<ShardId, Vec<&CrossShardEdge>>

Get edges grouped by target shard.

Useful for batching requests to remote shards.

§Returns

A map of shard ID to edges targeting that shard.

Source

pub fn pending_by_shard(&self) -> HashMap<ShardId, Vec<&CrossShardEdge>>

Get pending edges grouped by target shard.

Useful for batching ghost node resolution requests.

Source

pub fn edge_count(&self) -> usize

Total number of cross-shard edges (outgoing + incoming).

Source

pub fn outgoing_count(&self) -> usize

Number of outgoing cross-shard edges.

Source

pub fn incoming_count(&self) -> usize

Number of incoming cross-shard edges.

Source

pub fn nodes_with_outgoing(&self) -> usize

Number of unique local nodes with outgoing edges.

Source

pub fn nodes_with_incoming(&self) -> usize

Number of unique local nodes with incoming edges.

Source

pub fn clear(&mut self)

Clear all edges.

Source

pub fn is_empty(&self) -> bool

Check if the manager has any edges.

Source

pub fn stats(&self) -> CrossShardEdgeStats

Get statistics about cross-shard edges.

Trait Implementations§

Source§

impl Default for CrossShardEdgeManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more