krabka_connect_postgres/ids.rs
1//! Domain newtypes for the Postgres logical-decoding connector.
2//!
3//! Logical decoding threads several primitives of the same type, and a call
4//! site can transpose them easily. The pgoutput `Commit` message carries two
5//! adjacent [`PgLsn`] values, `commit_lsn` and `end_lsn`. Transaction ids and
6//! commit timestamps are both `i64`, and they sit next to each other on a row.
7//! `relation_id` is a bare `u32` that the relation cache and every row event
8//! share. A distinct newtype around each one turns a swapped argument into a
9//! compile error, instead of silent offset or transaction corruption. See the
10//! [newtype guidance] in the style guide.
11//!
12//! [newtype guidance]: ../../../docs/style_guides/code_style_guide.md
13
14use derive_more::{Display, From, Into};
15
16use crate::PgLsn;
17
18/// LSN at which a transaction was committed. This is the pgoutput
19/// `Commit.commit_lsn`.
20///
21/// It is distinct from [`EndLsn`], so the two adjacent LSNs in a commit message
22/// cannot be transposed when the code constructs the message.
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, Into)]
24pub struct CommitLsn(pub PgLsn);
25
26/// End-of-transaction LSN, the resume point after a commit. This is the
27/// pgoutput `Commit.end_lsn`.
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, Into)]
29pub struct EndLsn(pub PgLsn);
30
31/// Postgres transaction id (`xid`) carried by begin/commit and stamped onto
32/// each decoded row.
33///
34/// A bare `i64` sits next to `commit_timestamp_ms` on a row event. The newtype
35/// prevents a swap of the two.
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, Into)]
37pub struct TransactionId(pub i64);
38
39/// pgoutput relation identifier. It keys the relation cache and every row
40/// event.
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Display, From, Into)]
42pub struct RelationId(pub u32);