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: u32Transaction 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: boolWhether 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
impl Transaction
Sourcepub fn new(transaction_id: u32, commit_timestamp: DateTime<Utc>) -> Self
pub fn new(transaction_id: u32, commit_timestamp: DateTime<Utc>) -> Self
Create a new transaction with the given ID and timestamp
Sourcepub fn new_batch(
transaction_id: u32,
commit_timestamp: DateTime<Utc>,
is_final: bool,
) -> Self
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)
Sourcepub fn new_streaming(
transaction_id: u32,
commit_timestamp: DateTime<Utc>,
is_final: bool,
) -> Self
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)
Sourcepub fn add_event(&mut self, event: ChangeEvent)
pub fn add_event(&mut self, event: ChangeEvent)
Add an event to this transaction
Sourcepub fn set_commit_lsn(&mut self, lsn: Lsn)
pub fn set_commit_lsn(&mut self, lsn: Lsn)
Set the commit LSN
Sourcepub fn event_count(&self) -> usize
pub fn event_count(&self) -> usize
Get the number of events in this transaction
Sourcepub fn set_final_batch(&mut self, is_final: bool)
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
impl Debug for Transaction
Source§impl<'de> Deserialize<'de> for Transaction
impl<'de> Deserialize<'de> for Transaction
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Transaction
impl RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnwindSafe for Transaction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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