Class: Pgoutput::Client::Keepalive
- Inherits:
-
KeepaliveData
- Object
- Data
- KeepaliveData
- Pgoutput::Client::Keepalive
- Defined in:
- lib/pgoutput/client/keepalive.rb
Overview
Immutable primary keepalive replication message.
PostgreSQL sends keepalive CopyData payloads while a replication stream is active. The payload layout is:
“‘text Byte 0 : message tag `k` Bytes 1-8 : current server WAL end, unsigned 64-bit big-endian Bytes 9-16 : server clock, PostgreSQL timestamp format Byte 17 : reply-requested flag, 1 for immediate feedback “`
The stream layer uses this message to advance its known WAL position and to decide whether to send standby status feedback immediately.
Instance Attribute Summary collapse
-
#reply_requested ⇒ Boolean
readonly
whether PostgreSQL requested immediate feedback.
-
#server_clock ⇒ Integer
readonly
PostgreSQL server timestamp in microseconds since 2000-01-01 UTC.
-
#wal_end ⇒ Integer
readonly
latest server WAL position.
Class Method Summary collapse
-
.parse(bytes) ⇒ Keepalive
Parse a keepalive CopyData payload.
Instance Method Summary collapse
-
#wal_end_lsn ⇒ String
Latest server WAL position formatted as a PostgreSQL LSN string.
Instance Attribute Details
#reply_requested ⇒ Boolean (readonly)
whether PostgreSQL requested immediate feedback
27 28 29 |
# File 'lib/pgoutput/client/keepalive.rb', line 27 def reply_requested @reply_requested end |
#server_clock ⇒ Integer (readonly)
PostgreSQL server timestamp in microseconds since 2000-01-01 UTC
27 28 29 |
# File 'lib/pgoutput/client/keepalive.rb', line 27 def server_clock @server_clock end |
#wal_end ⇒ Integer (readonly)
latest server WAL position
27 28 29 |
# File 'lib/pgoutput/client/keepalive.rb', line 27 def wal_end @wal_end end |
Class Method Details
.parse(bytes) ⇒ Keepalive
Parse a keepalive CopyData payload.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pgoutput/client/keepalive.rb', line 34 def self.parse(bytes) binary = bytes.b raise ProtocolError, "empty CopyData payload" if binary.empty? raise ProtocolError, "expected keepalive message" unless binary.getbyte(0) == "k".ord raise ProtocolError, "truncated keepalive message" if binary.bytesize < 18 wal_end = unpack_u64(binary, 1) server_clock = unpack_u64(binary, 9) reply_requested = binary.getbyte(17) == 1 Ractor.make_shareable(new(wal_end, server_clock, reply_requested)) end |