Class: Pgoutput::Client::Feedback
- Inherits:
-
FeedbackData
- Object
- Data
- FeedbackData
- Pgoutput::Client::Feedback
- Defined in:
- lib/pgoutput/client/feedback.rb
Overview
Standby status feedback message builder.
Logical replication clients periodically send standby status updates to tell PostgreSQL which WAL location has been received, flushed, and applied. ‘Feedback` models that update and can serialize itself into the CopyData payload expected by the replication protocol.
Instance Attribute Summary collapse
-
#applied_lsn ⇒ Integer
readonly
latest WAL location applied by the client.
-
#client_clock ⇒ Integer
readonly
PostgreSQL timestamp in microseconds since 2000-01-01 UTC.
-
#flushed_lsn ⇒ Integer
readonly
latest WAL location flushed by the client.
-
#received_lsn ⇒ Integer
readonly
latest WAL location received by the client.
-
#reply_requested ⇒ Boolean
readonly
whether this feedback is responding to an immediate-reply request.
Class Method Summary collapse
-
.current_pg_time ⇒ Integer
Current PostgreSQL protocol timestamp.
-
.now(received_lsn:, flushed_lsn: received_lsn, applied_lsn: flushed_lsn, reply_requested: false) ⇒ Feedback
Build feedback using the current wall-clock time.
Instance Method Summary collapse
-
#to_copy_data ⇒ String
Build a protocol CopyData payload for standby status update.
Instance Attribute Details
#applied_lsn ⇒ Integer (readonly)
latest WAL location applied by the client
19 20 21 |
# File 'lib/pgoutput/client/feedback.rb', line 19 def applied_lsn @applied_lsn end |
#client_clock ⇒ Integer (readonly)
PostgreSQL timestamp in microseconds since 2000-01-01 UTC
19 20 21 |
# File 'lib/pgoutput/client/feedback.rb', line 19 def client_clock @client_clock end |
#flushed_lsn ⇒ Integer (readonly)
latest WAL location flushed by the client
19 20 21 |
# File 'lib/pgoutput/client/feedback.rb', line 19 def flushed_lsn @flushed_lsn end |
#received_lsn ⇒ Integer (readonly)
latest WAL location received by the client
19 20 21 |
# File 'lib/pgoutput/client/feedback.rb', line 19 def received_lsn @received_lsn end |
#reply_requested ⇒ Boolean (readonly)
whether this feedback is responding to an immediate-reply request
19 20 21 |
# File 'lib/pgoutput/client/feedback.rb', line 19 def reply_requested @reply_requested end |
Class Method Details
.current_pg_time ⇒ Integer
Current PostgreSQL protocol timestamp.
PostgreSQL timestamps in replication messages are expressed as microseconds since 2000-01-01 00:00:00 UTC, not Unix epoch microseconds.
57 58 59 |
# File 'lib/pgoutput/client/feedback.rb', line 57 def self.current_pg_time ((Time.now.utc - Time.utc(2000, 1, 1)) * 1_000_000).to_i end |
.now(received_lsn:, flushed_lsn: received_lsn, applied_lsn: flushed_lsn, reply_requested: false) ⇒ Feedback
Build feedback using the current wall-clock time.
By default, flushed and applied LSNs follow the received LSN. Callers can pass lower values if they need to distinguish receipt from durable flush or application progress.
31 32 33 |
# File 'lib/pgoutput/client/feedback.rb', line 31 def self.now(received_lsn:, flushed_lsn: received_lsn, applied_lsn: flushed_lsn, reply_requested: false) new(received_lsn, flushed_lsn, applied_lsn, current_pg_time, reply_requested) end |
Instance Method Details
#to_copy_data ⇒ String
Build a protocol CopyData payload for standby status update.
The payload begins with the standby status update tag ‘r`, followed by three unsigned 64-bit LSN fields, the PostgreSQL timestamp, and a one-byte reply-requested flag.
42 43 44 45 46 47 48 |
# File 'lib/pgoutput/client/feedback.rb', line 42 def to_copy_data ( "r".b + [received_lsn, flushed_lsn, applied_lsn, client_clock].pack("Q>Q>Q>Q>") + [reply_requested ? 1 : 0].pack("C") ).freeze end |