pg-replication-protocol 0.0.4 → 0.0.6
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pg/replication/buffer.rb +12 -4
- data/lib/pg/replication/pg_output.rb +17 -3
- data/lib/pg/replication/version.rb +1 -1
- data/lib/pg/replication.rb +19 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72bf40ef6c6c482636553033a8747eec8239f4b10602486376806fd6bff59a91
|
4
|
+
data.tar.gz: 4df39c13ee3b16f7e77114c7ef061e75b33b1f112e6341ce4aeb28898096d703
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b3a4cd7627a4d8229f88ba7d086a95a6fac1ae76fe7d856970ce1dd745272696046f18e55bb551345fa8b431691ac351d3cffcdc809f07ecba5fa78d6f4b67a
|
7
|
+
data.tar.gz: da57dba3124e0c3e8c5832d570f471b2a15ee68c2afc0fd71e0f5c5410ec61585f99dcfb1499059106cf1cb06073552335897035388b45aa884dfc0d757155e0
|
data/Gemfile.lock
CHANGED
@@ -19,19 +19,19 @@ module PG
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def read_int8
|
22
|
-
|
22
|
+
readbyte
|
23
23
|
end
|
24
24
|
|
25
25
|
def read_int16
|
26
|
-
|
26
|
+
read_bytes(2).unpack("n").first
|
27
27
|
end
|
28
28
|
|
29
29
|
def read_int32
|
30
|
-
|
30
|
+
read_bytes(4).unpack("N").first
|
31
31
|
end
|
32
32
|
|
33
33
|
def read_int64
|
34
|
-
|
34
|
+
read_bytes(8).unpack("Q>").first
|
35
35
|
end
|
36
36
|
|
37
37
|
def read_timestamp
|
@@ -50,6 +50,14 @@ module PG
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def read_bytes(n)
|
57
|
+
bytes = read(n)
|
58
|
+
raise EOFError if bytes.nil? || bytes.size < n
|
59
|
+
bytes
|
60
|
+
end
|
53
61
|
end
|
54
62
|
end
|
55
63
|
end
|
@@ -13,7 +13,19 @@ module PG
|
|
13
13
|
Update = Data.define(:oid, :key, :old, :new)
|
14
14
|
Delete = Data.define(:oid, :key, :old)
|
15
15
|
Truncate = Data.define(:oid)
|
16
|
-
Tuple = Data.define(:type, :data)
|
16
|
+
Tuple = Data.define(:type, :data) do
|
17
|
+
def text?
|
18
|
+
type == "t"
|
19
|
+
end
|
20
|
+
|
21
|
+
def binary?
|
22
|
+
type == "b"
|
23
|
+
end
|
24
|
+
|
25
|
+
def toast?
|
26
|
+
type == "u"
|
27
|
+
end
|
28
|
+
end
|
17
29
|
Column = Data.define(:flags, :name, :oid, :modifier) do
|
18
30
|
def key?
|
19
31
|
flags == 1
|
@@ -150,8 +162,10 @@ module PG
|
|
150
162
|
end
|
151
163
|
|
152
164
|
def self.read_tuple(buffer)
|
153
|
-
case buffer.read_char
|
154
|
-
in
|
165
|
+
case (type = buffer.read_char)
|
166
|
+
in "n"
|
167
|
+
Tuple.new(type:, data: nil)
|
168
|
+
in "u"
|
155
169
|
Tuple.new(type:, data: nil)
|
156
170
|
in type
|
157
171
|
size = buffer.read_int32
|
data/lib/pg/replication.rb
CHANGED
@@ -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,16 +47,19 @@ 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
|
53
|
-
|
51
|
+
standby_status_update(write_lsn: lsn) if lsn > 0
|
52
|
+
last_keep_alive = Time.now
|
54
53
|
|
55
|
-
in Protocol::PrimaryKeepalive(server_time:, asap: true) if auto_keep_alive
|
56
|
-
standby_status_update(write_lsn:
|
54
|
+
in Protocol::PrimaryKeepalive(current_lsn:, server_time:, asap: true) if auto_keep_alive
|
55
|
+
standby_status_update(write_lsn: current_lsn)
|
57
56
|
last_keep_alive = Time.now
|
58
57
|
y << msg
|
59
58
|
|
59
|
+
in Protocol::PrimaryKeepalive(current_lsn:)
|
60
|
+
y << msg
|
61
|
+
@last_confirmed_lsn = [@last_confirmed_lsn, current_lsn].compact.max
|
62
|
+
|
60
63
|
else
|
61
64
|
y << msg
|
62
65
|
end
|
@@ -111,6 +114,16 @@ module PG
|
|
111
114
|
SELECT setting FROM pg_catalog.pg_settings WHERE name = 'wal_receiver_status_interval'
|
112
115
|
SQL
|
113
116
|
end
|
117
|
+
|
118
|
+
def confirmed_slot_lsn(slot)
|
119
|
+
lsn = query(<<~SQL).getvalue(0, 0)
|
120
|
+
SELECT confirmed_flush_lsn FROM pg_replication_slots WHERE slot_name = '#{slot}'
|
121
|
+
SQL
|
122
|
+
high, low = lsn.split("/")
|
123
|
+
(high.to_i(16) << 32) + low.to_i(16)
|
124
|
+
rescue StandardError
|
125
|
+
nil
|
126
|
+
end
|
114
127
|
end
|
115
128
|
|
116
129
|
Connection.send(:include, Replication)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg-replication-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Navarro
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-06-
|
10
|
+
date: 2025-06-20 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: pg
|