Skip to content

Commit 9fe5b8c

Browse files
committed
backend: add interpreted record replication message type
This is to be used by the safekeeper -> pageserver protocol.
1 parent 20031d7 commit 9fe5b8c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

postgres-protocol/src/message/backend.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub const READY_FOR_QUERY_TAG: u8 = b'Z';
3939
// replication message tags
4040
pub const XLOG_DATA_TAG: u8 = b'w';
4141
pub const PRIMARY_KEEPALIVE_TAG: u8 = b'k';
42+
pub const INTERPRETED_WAL_RECORD_TAG: u8 = b'0';
4243

4344
// logical replication message tags
4445
const BEGIN_TAG: u8 = b'B';
@@ -325,6 +326,7 @@ impl Message {
325326
pub enum ReplicationMessage<D> {
326327
XLogData(XLogDataBody<D>),
327328
PrimaryKeepAlive(PrimaryKeepAliveBody),
329+
RawInterpretedWalRecords(RawInterpretedWalRecordsBody<D>),
328330
}
329331

330332
impl ReplicationMessage<Bytes> {
@@ -370,6 +372,15 @@ impl ReplicationMessage<Bytes> {
370372
reply,
371373
})
372374
}
375+
INTERPRETED_WAL_RECORD_TAG => {
376+
let streaming_lsn = buf.read_u64::<BigEndian>()?;
377+
let wal_end = buf.read_u64::<BigEndian>()?;
378+
ReplicationMessage::RawInterpretedWalRecords(RawInterpretedWalRecordsBody {
379+
streaming_lsn,
380+
wal_end,
381+
data: buf.read_all(),
382+
})
383+
}
373384
tag => {
374385
return Err(io::Error::new(
375386
io::ErrorKind::InvalidInput,
@@ -950,6 +961,30 @@ impl<D> XLogDataBody<D> {
950961
}
951962
}
952963

964+
#[derive(Debug)]
965+
pub struct RawInterpretedWalRecordsBody<D> {
966+
streaming_lsn: u64,
967+
wal_end: u64,
968+
data: D,
969+
}
970+
971+
impl<D> RawInterpretedWalRecordsBody<D> {
972+
#[inline]
973+
pub fn streaming_lsn(&self) -> u64 {
974+
self.streaming_lsn
975+
}
976+
977+
#[inline]
978+
pub fn wal_end(&self) -> u64 {
979+
self.wal_end
980+
}
981+
982+
#[inline]
983+
pub fn data(&self) -> &D {
984+
&self.data
985+
}
986+
}
987+
953988
#[derive(Debug)]
954989
pub struct PrimaryKeepAliveBody {
955990
wal_end: u64,

0 commit comments

Comments
 (0)