Skip to main content

ServiceSubnetRegistry

Struct ServiceSubnetRegistry 

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

Tracks per-service-per-node subnet assignments carved from the cluster CIDR. Each (service_name, node_id) pair gets its own slice of size slice_prefix (default /28). Assignments are deterministic — the same (service, node) pair always maps to the same starting slot via FNV hash, with linear probing on collision. Mirrors NodeSliceAllocator’s pattern; see that type for the rationale (in particular the choice of FNV over DefaultHasher for cross-process reproducibility).

Snapshot/restore is wired the same way NodeSliceAllocator does it, so the scheduler’s Raft state can persist + replay assignments. The snapshot’s Vec<((String, String), IpNet)> is the wire-stable shape: avoid HashMap here because non-deterministic map ordering would yield unstable serialized bytes under postcard/serde.

Node IDs are stored as String (matching NodeSliceAllocator); the scheduler converts its own NodeId to/from String at the boundary.

Implementations§

Source§

impl ServiceSubnetRegistry

Source

pub fn new(cluster_cidr: IpNet, slice_prefix: u8) -> Result<Self>

Create a new service subnet registry that carves /slice_prefix-sized slices out of cluster_cidr.

§Errors

Returns OverlayError::InvalidCidr if slice_prefix is not strictly more specific than cluster_cidr.prefix_len(), or if it exceeds the address family’s maximum prefix length.

Source

pub fn assign(&mut self, service: &str, node: &str) -> Result<IpNet>

Assign (or return an existing) subnet for (service, node).

Idempotent: repeated calls with the same key return the same slice without re-assigning.

§Errors

Returns OverlayError::NoAvailableIps if every slice in the cluster CIDR is already assigned to some other (service, node) pair.

Source

pub fn release(&mut self, service: &str, node: &str) -> Option<IpNet>

Release the subnet for (service, node). Returns the freed slice if one was assigned, None otherwise.

Source

pub fn get(&self, service: &str, node: &str) -> Option<IpNet>

Look up the current assignment for (service, node), if any.

Source

pub fn assigned_count(&self) -> usize

Number of currently-assigned (service, node) pairs.

Source

pub fn capacity(&self) -> u64

Total number of slices the cluster CIDR can hold at the configured slice prefix.

Source

pub fn cluster_cidr(&self) -> IpNet

Cluster CIDR the registry operates over.

Source

pub fn slice_prefix(&self) -> u8

Slice prefix length (e.g. 28 for /28 slices).

Source

pub fn snapshot(&self) -> ServiceSubnetRegistrySnapshot

Build a persistable snapshot for Raft / durable leader state.

The returned snapshot has assignments sorted by (service, node) so the serialized bytes are deterministic across processes — important when Raft compares snapshots by hash.

Source

pub fn restore(snapshot: ServiceSubnetRegistrySnapshot) -> Result<Self>

Rebuild a registry from a snapshot.

§Errors

Returns OverlayError::InvalidCidr if the snapshot’s slice prefix is inconsistent with its assignments, or if any assigned slice is not contained in the cluster CIDR.

Trait Implementations§

Source§

impl Clone for ServiceSubnetRegistry

Source§

fn clone(&self) -> ServiceSubnetRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServiceSubnetRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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