Skip to main content

MigrationSourceHandler

Struct MigrationSourceHandler 

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

Handles the source node’s role in daemon migration.

The source handler:

  1. Takes a snapshot of the daemon (phase 0)
  2. Buffers events arriving for the daemon during migration (phases 0-3)
  3. Stops accepting writes at cutover (phase 4)
  4. Unregisters the daemon and cleans up (phase 5)

Implementations§

Source§

impl MigrationSourceHandler

Source

pub fn new(daemon_registry: Arc<DaemonRegistry>) -> Self

Create a new source handler.

Source

pub fn start_snapshot( &self, daemon_origin: u64, target_node: u64, orchestrator_node: u64, ) -> Result<StateSnapshot, MigrationError>

Phase 0: Take snapshot of a local daemon.

Registers the migration and returns the snapshot for transfer. orchestrator_node is the node that initiated this migration; SnapshotReady / CleanupComplete replies are routed to it rather than to whatever hop forwarded the wire packet.

Source

pub fn orchestrator_node(&self, daemon_origin: u64) -> Option<u64>

Recorded orchestrator for an active source-side migration.

Returns None once the migration has been cleaned up.

Source

pub fn buffer_event( &self, daemon_origin: u64, event: CausalEvent, ) -> Result<bool, MigrationError>

Buffer an event arriving for a daemon during migration.

Events are buffered during Snapshot through Replay phases. Returns Ok(true) if buffered, Ok(false) if no migration active or past cutover. Returns Err if the daemon was cut over (writes rejected).

Source

pub fn is_migrating(&self, daemon_origin: u64) -> bool

Check if a daemon is being migrated from this node.

Source

pub fn take_buffered_events( &self, daemon_origin: u64, ) -> Result<Vec<CausalEvent>, MigrationError>

Get buffered events for transfer to the target (during snapshot/transfer/restore/replay phases — i.e. the same phases that buffer_event accepts writes in).

Drains the buffer — events are moved, not copied.

Returns WrongPhase if invoked after cutover. Pre-fix the call had no phase guard, so a caller that drained post-cutover would silently get an empty Vec (since on_cutover already drained the buffer to its return value and any post-cutover writes are rejected by buffer_event). Distinguishing “no events were buffered” from “you called drain in the wrong phase” via a typed error catches the latter at the boundary instead of letting it manifest as missing-event diagnostics downstream.

Source

pub fn on_cutover( &self, daemon_origin: u64, ) -> Result<Vec<CausalEvent>, MigrationError>

Phase 4: Cutover — stop accepting writes for this daemon.

Source

pub fn cleanup(&self, daemon_origin: u64) -> Result<(), MigrationError>

Phase 5: Cleanup — unregister daemon from this node.

Removes the daemon from the local registry and clears migration state. Requires the migration to be in Cutover (the only phase after which the source’s daemon copy is safe to retire); any pre-cutover call would otherwise unregister a live daemon while the target is still restoring, stranding new traffic in DaemonNotFound and losing source-side buffered_events.

When no migration record exists for daemon_origin, this is a no-op success. A forged or replayed CleanupComplete for an origin we never migrated must NOT unregister an unrelated local daemon — the unregister is gated on migrations membership and the Cutover phase, which together prove this handler authored the migration whose target now owns the daemon.

Source

pub fn abort(&self, daemon_origin: u64) -> Result<(), MigrationError>

Abort a migration — return to normal operation.

Clears migration state. The daemon remains registered locally.

Source

pub fn phase(&self, daemon_origin: u64) -> Option<MigrationPhase>

Get the current phase of a migration on this source.

Source

pub fn active_count(&self) -> usize

Number of active source-side migrations.

Source

pub fn buffered_event_count(&self, daemon_origin: u64) -> Option<usize>

Currently-buffered event count for daemon_origin’s active migration, if one exists. Used by snapshot-source adapters to populate MigrationSnapshot::buffered_events truthfully instead of hardcoding 0.

Trait Implementations§

Source§

impl Debug for MigrationSourceHandler

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> 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> 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<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