Skip to main content

MigrationController

Struct MigrationController 

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

Manages the state machine for a single migration.

§Example

use lattice_embed::migration::{MigrationController, MigrationPlan};
use lattice_embed::EmbeddingModel;

let plan = MigrationPlan {
    id: "mig-001".to_string(),
    source_model: EmbeddingModel::BgeSmallEnV15,
    target_model: EmbeddingModel::BgeBaseEnV15,
    total_embeddings: 100,
    batch_size: 50,
    created_at: "2026-01-27T00:00:00Z".to_string(),
};

let mut ctrl = MigrationController::new(plan);
ctrl.start().unwrap();
ctrl.record_progress(50).unwrap();

let report = ctrl.progress();
assert!(report.state.is_active());
assert_eq!(report.state.processed(), 50);

Implementations§

Source§

impl MigrationController

Source

pub fn new(plan: MigrationPlan) -> Self

Create a new migration controller from a plan.

Source

pub fn start(&mut self) -> Result<(), MigrationError>

Start the migration (Planned -> InProgress).

Source

pub fn record_progress( &mut self, newly_processed: usize, ) -> Result<(), MigrationError>

Record that newly_processed embeddings were completed.

Source

pub fn record_error(&mut self)

Record a non-fatal error during processing.

Source

pub fn record_skip(&mut self, reason: SkipReason) -> Result<(), MigrationError>

Record an item that will be permanently skipped.

§Example
use lattice_embed::migration::{MigrationController, MigrationPlan, SkipReason};
use lattice_embed::EmbeddingModel;

let plan = MigrationPlan {
    id: "mig-001".to_string(),
    source_model: EmbeddingModel::BgeSmallEnV15,
    target_model: EmbeddingModel::BgeBaseEnV15,
    total_embeddings: 100,
    batch_size: 50,
    created_at: "2026-01-27T00:00:00Z".to_string(),
};

let mut ctrl = MigrationController::new(plan);
ctrl.start().unwrap();
ctrl.record_skip(SkipReason::ContentTooLarge { size: 50000, max: 8192 }).unwrap();
assert_eq!(ctrl.state().skipped(), 1);
Source

pub fn skip_reasons(&self) -> &[SkipReason]

Returns the list of reasons why entries were skipped during migration.

Source

pub fn effective_coverage(&self) -> f64

Returns the effective coverage fraction (0.0–1.0) of the migration.

Source

pub fn pause(&mut self, reason: impl Into<String>) -> Result<(), MigrationError>

Pause the migration (InProgress -> Paused).

Source

pub fn resume(&mut self) -> Result<(), MigrationError>

Resume the migration (Paused/Failed -> InProgress).

Source

pub fn fail(&mut self, error: impl Into<String>) -> Result<(), MigrationError>

Fail the migration (InProgress -> Failed).

Source

pub fn cancel(&mut self) -> Result<(), MigrationError>

Cancel the migration (any non-terminal state -> Cancelled).

Source

pub fn progress(&self) -> MigrationProgress

Get a snapshot of current progress.

Source

pub fn state(&self) -> &MigrationState

Returns the current migration state.

Source

pub fn plan(&self) -> &MigrationPlan

Returns the migration plan.

Trait Implementations§

Source§

impl Debug for MigrationController

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