Skip to main content

CdcSyncEngine

Struct CdcSyncEngine 

Source
pub struct CdcSyncEngine<C, O> { /* private fields */ }
Expand description

CDC-based sync engine that replicates changes from OLTP to OLAP.

Polls the CDC consumer for new events, converts them to DML, and applies them to the OLAP engine.

Features:

  • Batch INSERT: Consecutive INSERT events for the same table are grouped into a single multi-row INSERT for better OLAP performance.
  • CDC pruning: Optionally prunes processed CDC events after successful sync to prevent unbounded growth of the _rhei_cdc_log table.
  • Transaction safety: Each sync cycle is wrapped in a BEGIN/COMMIT on the OLAP side with ROLLBACK on failure. Note: the actual transactional guarantee is backend-dependent — DuckDB supports real transactions, while DataFusion treats BEGIN/COMMIT/ROLLBACK as no-ops, so a mid-cycle failure may leave OLAP partially updated.

Implementations§

Source§

impl<C, O> CdcSyncEngine<C, O>
where C: CdcConsumer, O: OlapEngine,

Source

pub fn new( cdc: C, olap: O, schema_registry: SchemaRegistry, batch_size: u32, ) -> Self

Create a new CdcSyncEngine.

  • cdc — CDC consumer that provides change events (e.g. SQLite trigger log).
  • olap — OLAP engine that receives the converted DML.
  • schema_registry — registry of table schemas used to build WHERE clauses and Arrow batches.
  • batch_size — maximum number of CDC events to fetch per sync_once call.

CDC pruning is enabled by default (prune_after_sync = true). Sync mode defaults to rhei_core::types::SyncMode::Destructive.

Source

pub fn with_prune_after_sync(self, prune: bool) -> Self

Set whether to prune processed CDC events after sync.

Source

pub fn with_sync_mode(self, mode: SyncMode) -> Self

Set the sync mode: Destructive (default) or Temporal (SCD Type 2).

Trait Implementations§

Source§

impl<C, O> SyncEngine for CdcSyncEngine<C, O>
where C: CdcConsumer, O: OlapEngine,

Source§

type Error = SyncError

Engine-specific error type returned by all fallible methods.
Source§

async fn sync_once(&self) -> Result<SyncResult, Self::Error>

Poll the CDC log and apply any new events to the OLAP engine. Read more
Source§

async fn status(&self) -> Result<SyncStatus, Self::Error>

Return a snapshot of the current replication state. Read more

Auto Trait Implementations§

§

impl<C, O> !Freeze for CdcSyncEngine<C, O>

§

impl<C, O> RefUnwindSafe for CdcSyncEngine<C, O>

§

impl<C, O> Send for CdcSyncEngine<C, O>
where C: Send, O: Send,

§

impl<C, O> Sync for CdcSyncEngine<C, O>
where C: Sync, O: Sync,

§

impl<C, O> Unpin for CdcSyncEngine<C, O>
where C: Unpin, O: Unpin,

§

impl<C, O> UnsafeUnpin for CdcSyncEngine<C, O>
where C: UnsafeUnpin, O: UnsafeUnpin,

§

impl<C, O> UnwindSafe for CdcSyncEngine<C, O>
where C: UnwindSafe, O: UnwindSafe,

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, 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
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,