Transaction

Struct Transaction 

Source
pub struct Transaction {
    pub transaction_id: u32,
    pub commit_timestamp: DateTime<Utc>,
    pub commit_lsn: Option<Lsn>,
    pub events: Vec<ChangeEvent>,
    pub is_final_batch: bool,
}
Expand description

Represents a complete PostgreSQL transaction from BEGIN to COMMIT

A Transaction contains all the change events that occurred within a single database transaction. Workers process entire transactions atomically to ensure consistency at the destination.

When PostgreSQL streaming mode is enabled (protocol v2+), large in-progress transactions are sent in chunks between StreamStart and StreamStop messages. The final commit is signaled by StreamCommit. This struct supports both modes:

  • Normal Mode: Events collected between BEGIN and COMMIT
  • Streaming Mode: Events collected between StreamStart and StreamStop, with batch processing for high-performance ingestion

Both modes use batch-based processing where transactions are sent to the consumer when event count reaches batch_size. The is_final_batch flag indicates when to commit the database transaction.

Fields§

§transaction_id: u32

Transaction ID from PostgreSQL

§commit_timestamp: DateTime<Utc>

Commit timestamp of the transaction

§commit_lsn: Option<Lsn>

LSN of the commit

§events: Vec<ChangeEvent>

All change events in this transaction (INSERT, UPDATE, DELETE, TRUNCATE) Events are in the order they occurred within the transaction

§is_final_batch: bool

Whether this is the final batch of a transaction When true, destination should commit the database transaction When false, destination should keep the transaction open for more batches

Implementations§

Source§

impl Transaction

Source

pub fn new(transaction_id: u32, commit_timestamp: DateTime<Utc>) -> Self

Create a new transaction with the given ID and timestamp

Source

pub fn new_batch( transaction_id: u32, commit_timestamp: DateTime<Utc>, is_final: bool, ) -> Self

Create a new transaction batch (can be used for both normal and streaming)

Source

pub fn new_streaming( transaction_id: u32, commit_timestamp: DateTime<Utc>, is_final: bool, ) -> Self

Create a new streaming transaction batch (alias for new_batch for compatibility)

Source

pub fn add_event(&mut self, event: ChangeEvent)

Add an event to this transaction

Source

pub fn set_commit_lsn(&mut self, lsn: Lsn)

Set the commit LSN

Source

pub fn event_count(&self) -> usize

Get the number of events in this transaction

Source

pub fn is_empty(&self) -> bool

Check if this transaction is empty (no events)

Source

pub fn set_final_batch(&mut self, is_final: bool)

Mark this as the final batch of a transaction

Trait Implementations§

Source§

impl Debug for Transaction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Transaction

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Transaction

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,