Skip to main content

RaftLoop

Struct RaftLoop 

Source
pub struct RaftLoop<A: CommitApplier, P: PlanExecutor = NoopPlanExecutor> { /* private fields */ }
Expand description

Raft event loop coordinator.

Owns the MultiRaft state (behind Arc<Mutex>) and drives it via periodic ticks. Implements crate::transport::RaftRpcHandler (in super::handle_rpc) so it can be passed directly to NexarTransport::serve for incoming RPC dispatch.

The F: RequestForwarder generic parameter was removed in C-δ.6 when the SQL-string forwarding path was retired. Cross-node SQL routing now goes through gateway.execute / ExecuteRequest (C-β path).

Implementations§

Source§

impl<A: CommitApplier> RaftLoop<A>

Source

pub fn new( multi_raft: MultiRaft, transport: Arc<NexarTransport>, topology: Arc<RwLock<ClusterTopology>>, applier: A, ) -> Self

Source§

impl<A: CommitApplier, P: PlanExecutor> RaftLoop<A, P>

Source

pub fn with_plan_executor<P2: PlanExecutor>( self, executor: Arc<P2>, ) -> RaftLoop<A, P2>

Install a custom plan executor (for cluster mode — C-β path).

Source

pub fn loop_metrics(&self) -> Arc<LoopMetrics>

Shared handle to this loop’s standardized metrics.

Source

pub fn pending_groups(&self) -> usize

Count of Raft groups currently mounted on this node — used to render the raft_tick_loop_pending_groups gauge.

Source

pub fn begin_shutdown(&self)

Signal cooperative shutdown to every detached task spawned inside [super::tick::do_tick].

This is the entry point for test harnesses that want to tear down a RaftLoop without waiting for the external run() shutdown watch channel to propagate. In production the same signal is emitted automatically by run() when its external shutdown receiver fires.

Idempotent: calling this multiple times is a no-op after the first.

Source

pub fn subscribe_ready(&self) -> Receiver<bool>

Subscribe to the boot-time readiness signal.

The returned receiver starts at false and flips to true exactly once, after the first [super::tick::do_tick] completes phase 4 (apply committed entries). Used by the host crate to gate client-facing listener startup until the metadata raft group has produced its first applied entry.

Source

pub fn with_vshard_handler(self, handler: VShardEnvelopeHandler) -> Self

Set a handler for incoming VShardEnvelope messages.

Source

pub fn with_metadata_applier(self, applier: Arc<dyn MetadataApplier>) -> Self

Install the metadata applier used for group-0 commits.

The host crate (nodedb) calls this with a production applier that wraps an in-memory MetadataCache and additionally persists to redb / broadcasts catalog change events. The default NoopMetadataApplier is kept only for tests that don’t care.

Source

pub fn with_tick_interval(self, interval: Duration) -> Self

Source

pub fn with_catalog(self, catalog: Arc<ClusterCatalog>) -> Self

Attach a cluster catalog — used by the join flow to persist the updated topology + routing after a conf-change commits.

Source

pub fn node_id(&self) -> u64

This node’s id (exposed for handlers and tests).

Source

pub async fn run(&self, shutdown: Receiver<bool>)

Run the event loop until shutdown.

This drives Raft elections, heartbeats, and message dispatch. Call NexarTransport::serve separately with Arc<Self> as the handler.

When the externally-supplied shutdown receiver fires, the loop also propagates the signal to the internal cooperative-shutdown channel so every detached task spawned inside do_tick exits promptly and drops its Arc<Mutex<MultiRaft>> clone.

Source

pub fn propose(&self, vshard_id: u16, data: Vec<u8>) -> Result<(u64, u64)>

Propose a command to the Raft group owning the given vShard.

Returns (group_id, log_index) on success.

Source

pub fn propose_to_metadata_group(&self, data: Vec<u8>) -> Result<u64>

Propose a command directly to the metadata Raft group (group 0).

Used by the host crate’s metadata proposer and by integration tests that exercise the replicated-catalog path without a pgwire client. Fails with ClusterError::GroupNotFound if group 0 does not exist on this node, and with ClusterError::Raft(NotLeader) if this node is not the current leader of group 0.

Source

pub async fn propose_to_metadata_group_via_leader( &self, data: Vec<u8>, ) -> Result<u64>

Propose to the metadata Raft group, transparently forwarding to the current leader if this node is not it.

Tries a local propose first. On ClusterError::Raft(NotLeader { leader_hint }), looks up the hinted leader’s address in cluster topology and sends a crate::rpc_codec::MetadataProposeRequest over QUIC. The receiving leader applies the proposal locally and returns the log index.

On NotLeader { leader_hint: None } (election in progress, no observed leader yet) the call returns the original NotLeader error so the caller can decide whether to retry. We deliberately do not implement a wait-and-retry loop here because the caller (the host-side proposer) may have a shorter deadline than any reasonable retry budget.

The leader-side path through this function is identical to the bare propose_to_metadata_group — the only extra cost is an is_leader_locally check before the local propose.

Source

pub fn multi_raft_handle(&self) -> Arc<Mutex<MultiRaft>>

Returns the inner multi-raft handle. Exposed for tests and for the host crate’s metadata proposer so it can hold a second reference to the same underlying mutex without pulling the whole raft loop into the caller’s lifetime.

Source

pub fn group_statuses(&self) -> Vec<GroupStatus>

Snapshot all Raft group states for observability (SHOW RAFT GROUPS).

Source

pub fn propose_conf_change( &self, group_id: u64, change: &ConfChange, ) -> Result<(u64, u64)>

Propose a configuration change to a Raft group.

Returns (group_id, log_index) on success.

Trait Implementations§

Source§

impl<A, P> GroupStatusProvider for RaftLoop<A, P>

Source§

fn group_statuses(&self) -> Vec<GroupStatus>

Current status of every Raft group hosted on this node.
Source§

impl<A: CommitApplier, P: PlanExecutor> RaftRpcHandler for RaftLoop<A, P>

Source§

async fn handle_rpc(&self, rpc: RaftRpc) -> Result<RaftRpc>

Auto Trait Implementations§

§

impl<A, P> Freeze for RaftLoop<A, P>
where A: Freeze,

§

impl<A, P = NoopPlanExecutor> !RefUnwindSafe for RaftLoop<A, P>

§

impl<A, P> Send for RaftLoop<A, P>

§

impl<A, P> Sync for RaftLoop<A, P>

§

impl<A, P> Unpin for RaftLoop<A, P>
where A: Unpin,

§

impl<A, P> UnsafeUnpin for RaftLoop<A, P>
where A: UnsafeUnpin,

§

impl<A, P = NoopPlanExecutor> !UnwindSafe for RaftLoop<A, P>

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

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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