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
impl ServiceSubnetRegistry
Sourcepub fn new(cluster_cidr: IpNet, slice_prefix: u8) -> Result<Self>
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.
Sourcepub fn assign(&mut self, service: &str, node: &str) -> Result<IpNet>
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.
Sourcepub fn release(&mut self, service: &str, node: &str) -> Option<IpNet>
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.
Sourcepub fn get(&self, service: &str, node: &str) -> Option<IpNet>
pub fn get(&self, service: &str, node: &str) -> Option<IpNet>
Look up the current assignment for (service, node), if any.
Sourcepub fn assigned_count(&self) -> usize
pub fn assigned_count(&self) -> usize
Number of currently-assigned (service, node) pairs.
Sourcepub fn capacity(&self) -> u64
pub fn capacity(&self) -> u64
Total number of slices the cluster CIDR can hold at the configured slice prefix.
Sourcepub fn cluster_cidr(&self) -> IpNet
pub fn cluster_cidr(&self) -> IpNet
Cluster CIDR the registry operates over.
Sourcepub fn slice_prefix(&self) -> u8
pub fn slice_prefix(&self) -> u8
Slice prefix length (e.g. 28 for /28 slices).
Sourcepub fn snapshot(&self) -> ServiceSubnetRegistrySnapshot
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.
Sourcepub fn restore(snapshot: ServiceSubnetRegistrySnapshot) -> Result<Self>
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
impl Clone for ServiceSubnetRegistry
Source§fn clone(&self) -> ServiceSubnetRegistry
fn clone(&self) -> ServiceSubnetRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ServiceSubnetRegistry
impl RefUnwindSafe for ServiceSubnetRegistry
impl Send for ServiceSubnetRegistry
impl Sync for ServiceSubnetRegistry
impl Unpin for ServiceSubnetRegistry
impl UnsafeUnpin for ServiceSubnetRegistry
impl UnwindSafe for ServiceSubnetRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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