pgoutput-client 0.3.0 → 0.4.0

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: 9a0c63a95d0df00f5a4b8b5a0e85b01bbec1ed71688a41f853c065e2f2b01a03
4
- data.tar.gz: 3e86b0d6e62c54c03edd73a86be9dce33997a60f2d5bd097459b3a2a0d75795a
3
+ metadata.gz: a79d1b00595418c8536658073164d8c4d29ad90fe79f5ba58b04e4ee80dd90a1
4
+ data.tar.gz: 436b7bd8d0aedae584d4b5f702635cca25f96d78857fd736c3fde5d41d1be52d
5
5
  SHA512:
6
- metadata.gz: 0577c07284f05bb0daa59ae055a39cdd456e2104f936c33b8a921473fb5554cf65dfae2f9d9d69ce82900e27dfb1a0f632c960654bae7526b73b62ab664f6007
7
- data.tar.gz: e2ea5d853aee2079d280139f58f287063fc411e8ef846782c14b8f41c286bd1975027022ecfa395619f5494ce5622d640fc0a9b6bd1a0ca9a192ebbab5701d20
6
+ metadata.gz: ea61369e9d3ce153ce50b1f24e7335914feb898ca3e52cea20cdb0aa9875ad88a20342b2badc35c81a6fb95a941e8f36ebfdb3e3762c4f3ff421cd9cc4bfed3a
7
+ data.tar.gz: fb24fa3565d7d626282c5d8bdd3b5502b9cd22d168359522b741990a0d1dd10e616e921a65c3dc92beefcbcae5470484872a21a6caba6420b47d3079af62e930
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.4.0 - 2026-07-17
6
+
7
+ ### Added
8
+
9
+ - Added `SlotStatus#retained_wal_bytes`, computed by PostgreSQL from the current
10
+ WAL position and the slot's `restart_lsn`.
11
+
5
12
  ## 0.3.0 - 2026-07-17
6
13
 
7
14
  ### Added
data/README.md CHANGED
@@ -254,6 +254,7 @@ if status.nil?
254
254
  else
255
255
  puts status.restart_lsn
256
256
  puts status.confirmed_flush_lsn
257
+ puts status.retained_wal_bytes
257
258
  puts status.wal_status
258
259
  puts status.invalidation_reason
259
260
  end
@@ -278,7 +279,7 @@ WAL position, retention, and invalidation fields including:
278
279
 
279
280
  - `slot_name`, `plugin`, `slot_type`, and `database`
280
281
  - `active`, `active_pid`, and `inactive_since`
281
- - `restart_lsn` and `confirmed_flush_lsn`
282
+ - `restart_lsn`, `confirmed_flush_lsn`, and `retained_wal_bytes`
282
283
  - `wal_status`, `safe_wal_size`, and `catalog_xmin`
283
284
  - `conflicting` and `invalidation_reason`
284
285
 
@@ -111,15 +111,13 @@ module Pgoutput
111
111
 
112
112
  loop do
113
113
  current_configuration = configuration_for_resume
114
- case run_stream_cycle(current_configuration, &block)
115
- when :done
116
- break
117
- when :retry
118
- @reconnect_attempts += 1
119
- raise @last_error if @reconnect_attempts > DEFAULT_RECONNECT_ATTEMPTS
120
-
121
- sleep(reconnect_backoff_for(@reconnect_attempts))
122
- end
114
+ result = run_stream_cycle(current_configuration, &block)
115
+ break if result == :done
116
+
117
+ @reconnect_attempts += 1
118
+ raise @last_error if @reconnect_attempts > DEFAULT_RECONNECT_ATTEMPTS
119
+
120
+ sleep(reconnect_backoff_for(@reconnect_attempts))
123
121
  end
124
122
  ensure
125
123
  @running = false
@@ -18,7 +18,14 @@ module Pgoutput
18
18
  #
19
19
  # @return [String]
20
20
  QUERY = <<~SQL
21
- SELECT to_jsonb(slot) AS slot
21
+ SELECT
22
+ to_jsonb(slot) || jsonb_build_object(
23
+ 'retained_wal_bytes',
24
+ CASE
25
+ WHEN slot.restart_lsn IS NULL THEN NULL
26
+ ELSE pg_wal_lsn_diff(pg_current_wal_lsn(), slot.restart_lsn)::bigint
27
+ END
28
+ ) AS slot
22
29
  FROM pg_catalog.pg_replication_slots AS slot
23
30
  WHERE slot.slot_name = $1
24
31
  SQL
@@ -20,6 +20,7 @@ module Pgoutput
20
20
  :catalog_xmin,
21
21
  :restart_lsn,
22
22
  :confirmed_flush_lsn,
23
+ :retained_wal_bytes,
23
24
  :wal_status,
24
25
  :safe_wal_size,
25
26
  :inactive_since,
@@ -36,27 +37,18 @@ module Pgoutput
36
37
  # @param attributes [Hash{String, Symbol=>Object}] catalog attributes
37
38
  # @return [SlotStatus]
38
39
  def self.from_catalog(attributes)
39
- fetch = lambda do |key|
40
- next attributes[key] if attributes.key?(key)
41
-
42
- attributes[key.to_sym]
43
- end
40
+ value = ->(key) { attributes.fetch(key) { attributes[key.to_sym] } }
44
41
 
45
42
  new(
46
- slot_name: fetch.call("slot_name"),
47
- plugin: fetch.call("plugin"),
48
- slot_type: fetch.call("slot_type"),
49
- database: fetch.call("database"),
50
- active: fetch.call("active") == true,
51
- active_pid: fetch.call("active_pid"),
52
- catalog_xmin: fetch.call("catalog_xmin"),
53
- restart_lsn: fetch.call("restart_lsn"),
54
- confirmed_flush_lsn: fetch.call("confirmed_flush_lsn"),
55
- wal_status: fetch.call("wal_status"),
56
- safe_wal_size: fetch.call("safe_wal_size"),
57
- inactive_since: fetch.call("inactive_since"),
58
- conflicting: fetch.call("conflicting"),
59
- invalidation_reason: fetch.call("invalidation_reason")
43
+ slot_name: value.call("slot_name"), plugin: value.call("plugin"),
44
+ slot_type: value.call("slot_type"), database: value.call("database"),
45
+ active: value.call("active") == true, active_pid: value.call("active_pid"),
46
+ catalog_xmin: value.call("catalog_xmin"), restart_lsn: value.call("restart_lsn"),
47
+ confirmed_flush_lsn: value.call("confirmed_flush_lsn"),
48
+ retained_wal_bytes: value.call("retained_wal_bytes"),
49
+ wal_status: value.call("wal_status"), safe_wal_size: value.call("safe_wal_size"),
50
+ inactive_since: value.call("inactive_since"), conflicting: value.call("conflicting"),
51
+ invalidation_reason: value.call("invalidation_reason")
60
52
  )
61
53
  end
62
54
  end
@@ -5,6 +5,6 @@ module Pgoutput
5
5
  # Current pgoutput-client gem version.
6
6
  #
7
7
  # @return [String]
8
- VERSION = "0.3.0"
8
+ VERSION = "0.4.0"
9
9
  end
10
10
  end
@@ -44,7 +44,7 @@ module Pgoutput
44
44
  wal_start = unpack_u64(binary, 1)
45
45
  wal_end = unpack_u64(binary, 9)
46
46
  server_clock = unpack_u64(binary, 17)
47
- payload = binary.byteslice(25..)&.freeze || "".b.freeze
47
+ payload = binary.unpack1("@25a*").freeze
48
48
 
49
49
  Ractor.make_shareable(new(wal_start, wal_end, server_clock, payload))
50
50
  end
@@ -10,6 +10,7 @@ module Pgoutput
10
10
  attr_reader catalog_xmin: String?
11
11
  attr_reader restart_lsn: String?
12
12
  attr_reader confirmed_flush_lsn: String?
13
+ attr_reader retained_wal_bytes: Integer?
13
14
  attr_reader wal_status: String?
14
15
  attr_reader safe_wal_size: Integer?
15
16
  attr_reader inactive_since: String?
@@ -26,6 +27,7 @@ module Pgoutput
26
27
  catalog_xmin: String?,
27
28
  restart_lsn: String?,
28
29
  confirmed_flush_lsn: String?,
30
+ retained_wal_bytes: Integer?,
29
31
  wal_status: String?,
30
32
  safe_wal_size: Integer?,
31
33
  inactive_since: String?,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgoutput-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken C. Demanawa