risingwave_common/transaction/
transaction_message.rs1use enum_as_inner::EnumAsInner;
16use tokio::sync::oneshot;
17
18use crate::array::StreamChunk;
19use crate::transaction::transaction_id::TxnId;
20use crate::transaction::transaction_message::TxnMsg::{Begin, Data, End, Rollback};
21use crate::util::epoch::Epoch;
22
23#[derive(Debug, EnumAsInner)]
24pub enum TxnMsg {
25 Begin(TxnId),
26 Data(TxnId, StreamChunk),
27 End(TxnId, Option<oneshot::Sender<Epoch>>),
28 Rollback(TxnId),
29}
30
31impl TxnMsg {
32 pub fn txn_id(&self) -> TxnId {
33 match self {
34 Begin(txn_id) => *txn_id,
35 Data(txn_id, _) => *txn_id,
36 End(txn_id, _) => *txn_id,
37 Rollback(txn_id) => *txn_id,
38 }
39 }
40
41 pub fn as_stream_chunk(&self) -> Option<&StreamChunk> {
42 match self {
43 Begin(_) | End(..) | Rollback(_) => None,
44 Data(_, chunk) => Some(chunk),
45 }
46 }
47}