pg-replication-protocol 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7eb14ee3cd0484e8160ed1bc27a841178bb5bb19a35304d46992c8d7accad5be
4
- data.tar.gz: 51e43b8bcba5ee2db08b08962418ae0ff6ab6657076ca586984c279fe6603f6e
3
+ metadata.gz: 07bd494baf2df079a175855749b79dc41460c5903a58e3cef89f7ac1304e6e9b
4
+ data.tar.gz: 28ad5dced1a6a73c84a62ce6eae434dbde34883378555c8bac7674d477928627
5
5
  SHA512:
6
- metadata.gz: 0e86a9fcaa6a3497d6b211004551219fd9080adbca09977de836c53766780088fcb6c42966e461b8517026ef310ab67134c52d20fef396adf1807c06bf004ffe
7
- data.tar.gz: 7e21681ae16444dc1a43450074a574ea81edfd554ce6362c13befad60f651c637c887416fd58befdf1bb8e5f604efd946a6e253486c584b562bb790a1e644864
6
+ metadata.gz: 7bd50c203eb711090bdbb0b16d745e46472d936191ac3c3653138bc9db42cecd6b1ed51a625eeae5194be3ca17c66e6f8a05dd4a860979a791d4fa54eee74139
7
+ data.tar.gz: 3ddaf038c9cdfab3c05c4ac2e6eac8c1799c7a0b1d334a4657b19a9251feeac835784bbdec5a94fba43260f50b932441cd49786f1f573c7a607687a742ef8eb4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg-replication-protocol (0.0.3)
4
+ pg-replication-protocol (0.0.5)
5
5
  pg (~> 1.0)
6
6
 
7
7
  GEM
@@ -2,6 +2,6 @@
2
2
 
3
3
  module PG
4
4
  module Replication
5
- VERSION = "0.0.4"
5
+ VERSION = "0.0.5"
6
6
  end
7
7
  end
@@ -10,6 +10,7 @@ module PG
10
10
  module Replication
11
11
  def start_replication_slot(slot, logical: true, auto_keep_alive: true, location: "0/0", **params)
12
12
  keep_alive_secs = wal_receiver_status_interval
13
+ @last_confirmed_lsn = confirmed_slot_lsn(slot) || 0
13
14
 
14
15
  start_query = "START_REPLICATION SLOT #{slot} #{logical ? "LOGICAL" : "PHYSICAL"} #{location}"
15
16
  unless params.empty?
@@ -21,7 +22,6 @@ module PG
21
22
  end
22
23
  query(start_query)
23
24
 
24
- @last_confirmed_lsn = 0
25
25
  last_keep_alive = Time.now
26
26
 
27
27
  Enumerator
@@ -47,10 +47,10 @@ module PG
47
47
  in data
48
48
  case (msg = Protocol.read_message(Buffer.new(StringIO.new(data))))
49
49
  in Protocol::XLogData(lsn:, data:) if auto_keep_alive
50
- standby_status_update(write_lsn: @last_confirmed_lsn)
51
- last_keep_alive = Time.now
52
50
  y << msg
51
+ standby_status_update(write_lsn: lsn)
53
52
  @last_confirmed_lsn = lsn
53
+ last_keep_alive = Time.now
54
54
 
55
55
  in Protocol::PrimaryKeepalive(server_time:, asap: true) if auto_keep_alive
56
56
  standby_status_update(write_lsn: @last_confirmed_lsn)
@@ -111,6 +111,16 @@ module PG
111
111
  SELECT setting FROM pg_catalog.pg_settings WHERE name = 'wal_receiver_status_interval'
112
112
  SQL
113
113
  end
114
+
115
+ def confirmed_slot_lsn(slot)
116
+ lsn = query(<<~SQL).getvalue(0, 0)
117
+ SELECT confirmed_flush_lsn FROM pg_replication_slots WHERE slot_name = '#{slot}'
118
+ SQL
119
+ high, low = lsn.split("/")
120
+ (high.to_i(16) << 32) + low.to_i(16)
121
+ rescue StandardError
122
+ nil
123
+ end
114
124
  end
115
125
 
116
126
  Connection.send(:include, Replication)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg-replication-protocol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Navarro