pub struct MigrationSourceHandler { /* private fields */ }Expand description
Handles the source node’s role in daemon migration.
The source handler:
- Takes a snapshot of the daemon (phase 0)
- Buffers events arriving for the daemon during migration (phases 0-3)
- Stops accepting writes at cutover (phase 4)
- Unregisters the daemon and cleans up (phase 5)
Implementations§
Source§impl MigrationSourceHandler
impl MigrationSourceHandler
Sourcepub fn new(daemon_registry: Arc<DaemonRegistry>) -> Self
pub fn new(daemon_registry: Arc<DaemonRegistry>) -> Self
Create a new source handler.
Sourcepub fn start_snapshot(
&self,
daemon_origin: u64,
target_node: u64,
orchestrator_node: u64,
) -> Result<StateSnapshot, MigrationError>
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.
Sourcepub fn orchestrator_node(&self, daemon_origin: u64) -> Option<u64>
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.
Sourcepub fn buffer_event(
&self,
daemon_origin: u64,
event: CausalEvent,
) -> Result<bool, MigrationError>
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).
Sourcepub fn is_migrating(&self, daemon_origin: u64) -> bool
pub fn is_migrating(&self, daemon_origin: u64) -> bool
Check if a daemon is being migrated from this node.
Sourcepub fn take_buffered_events(
&self,
daemon_origin: u64,
) -> Result<Vec<CausalEvent>, MigrationError>
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.
Sourcepub fn on_cutover(
&self,
daemon_origin: u64,
) -> Result<Vec<CausalEvent>, MigrationError>
pub fn on_cutover( &self, daemon_origin: u64, ) -> Result<Vec<CausalEvent>, MigrationError>
Phase 4: Cutover — stop accepting writes for this daemon.
Sourcepub fn cleanup(&self, daemon_origin: u64) -> Result<(), MigrationError>
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.
Sourcepub fn abort(&self, daemon_origin: u64) -> Result<(), MigrationError>
pub fn abort(&self, daemon_origin: u64) -> Result<(), MigrationError>
Abort a migration — return to normal operation.
Clears migration state. The daemon remains registered locally.
Sourcepub fn phase(&self, daemon_origin: u64) -> Option<MigrationPhase>
pub fn phase(&self, daemon_origin: u64) -> Option<MigrationPhase>
Get the current phase of a migration on this source.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Number of active source-side migrations.
Sourcepub fn buffered_event_count(&self, daemon_origin: u64) -> Option<usize>
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.