Class: Pgoutput::Client::XLogData
- Inherits:
-
ReplicationXLogData
- Object
- Data
- ReplicationXLogData
- Pgoutput::Client::XLogData
- Defined in:
- lib/pgoutput/client/xlog_data.rb
Overview
Immutable XLogData replication envelope.
PostgreSQL wraps logical decoding plugin output in an XLogData CopyData payload while streaming replication is active. The payload layout is:
“‘text Byte 0 : message tag `w` Bytes 1-8 : WAL start position, unsigned 64-bit big-endian Bytes 9-16 : WAL end position, unsigned 64-bit big-endian Bytes 17-24 : server clock, PostgreSQL timestamp format Bytes 25.. : logical decoding plugin payload “`
Instances are created through XLogData.parse and made shareable so they can cross Ractor boundaries with their frozen payload bytes.
Instance Attribute Summary collapse
-
#payload ⇒ String
readonly
frozen raw logical decoding plugin payload.
-
#server_clock ⇒ Integer
readonly
PostgreSQL server timestamp in microseconds since 2000-01-01 UTC.
-
#wal_end ⇒ Integer
readonly
WAL position after this message.
-
#wal_start ⇒ Integer
readonly
WAL position where this message begins.
Class Method Summary collapse
-
.parse(bytes) ⇒ XLogData
Parse an XLogData CopyData payload.
Instance Method Summary collapse
-
#wal_end_lsn ⇒ String
Ending WAL position formatted as a PostgreSQL LSN string.
-
#wal_start_lsn ⇒ String
Starting WAL position formatted as a PostgreSQL LSN string.
Instance Attribute Details
#payload ⇒ String (readonly)
frozen raw logical decoding plugin payload
28 29 30 |
# File 'lib/pgoutput/client/xlog_data.rb', line 28 def payload @payload end |
#server_clock ⇒ Integer (readonly)
PostgreSQL server timestamp in microseconds since 2000-01-01 UTC
28 29 30 |
# File 'lib/pgoutput/client/xlog_data.rb', line 28 def server_clock @server_clock end |
#wal_end ⇒ Integer (readonly)
WAL position after this message
28 29 30 |
# File 'lib/pgoutput/client/xlog_data.rb', line 28 def wal_end @wal_end end |
#wal_start ⇒ Integer (readonly)
WAL position where this message begins
28 29 30 |
# File 'lib/pgoutput/client/xlog_data.rb', line 28 def wal_start @wal_start end |
Class Method Details
.parse(bytes) ⇒ XLogData
Parse an XLogData CopyData payload.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pgoutput/client/xlog_data.rb', line 35 def self.parse(bytes) binary = bytes.b raise ProtocolError, "empty CopyData payload" if binary.empty? raise ProtocolError, "expected XLogData message" unless binary.getbyte(0) == "w".ord raise ProtocolError, "truncated XLogData message" if binary.bytesize < 25 wal_start = unpack_u64(binary, 1) wal_end = unpack_u64(binary, 9) server_clock = unpack_u64(binary, 17) payload = binary.byteslice(25..)&.freeze || "".b.freeze Ractor.make_shareable(new(wal_start, wal_end, server_clock, payload)) end |