wal 0.0.21 → 0.0.23
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/exe/wal +10 -4
- data/lib/wal/record_watcher.rb +17 -18
- data/lib/wal/replicator.rb +3 -0
- data/lib/wal/version.rb +1 -1
- 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: 3a7144e35e8bfe1df54e18fa1e4b9c94e4bb6926ed0de011e0e4006ce08c44cd
|
|
4
|
+
data.tar.gz: 21196f54b92390273288aac5fed7b5fdcd79842dda0d63cbb0cada583bca8cd3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 88be295b55c90871dc4aa8731e21c03fff1b890e59a3b9ec000276c5d0b2dad96660b1686328af6e208084fc5389f90c8925dbc27fb29de56e535063eaf20899
|
|
7
|
+
data.tar.gz: a13bd85ed047f5b7bfcfe839bb0ff8643587ae6c6ca81ef4f56809a96e4daff6a6f7423c9eff3a715cfa72f27e84b99765f003b4d40b0eacabf0d73cc7311bbc
|
data/exe/wal
CHANGED
|
@@ -91,7 +91,10 @@ elsif cli["start"]
|
|
|
91
91
|
temporary = config["temporary"] || false
|
|
92
92
|
publications = config["publications"] || []
|
|
93
93
|
replicator_class = config["replicator"].presence&.constantize || Wal::Replicator
|
|
94
|
-
|
|
94
|
+
max_retries = config["retries"]&.to_i || (2**32 - 1)
|
|
95
|
+
retries = 0
|
|
96
|
+
backoff = config["retry_backoff"]&.to_f || 1
|
|
97
|
+
backoff_expoent = config["retry_backoff_expoent"]&.to_f
|
|
95
98
|
|
|
96
99
|
Thread.new(slot, watcher, temporary, publications) do |replication_slot, watcher, use_temporary_slot, publications|
|
|
97
100
|
replication_slot = "#{replication_slot}_#{SecureRandom.alphanumeric(4)}" if use_temporary_slot
|
|
@@ -103,10 +106,13 @@ elsif cli["start"]
|
|
|
103
106
|
begin
|
|
104
107
|
replicator.replicate_forever(watcher, publications:)
|
|
105
108
|
rescue StandardError => err
|
|
106
|
-
if retries
|
|
109
|
+
if retries < max_retries
|
|
107
110
|
Wal.logger&.error("[#{replication_slot}] Error #{err}")
|
|
108
|
-
retries
|
|
109
|
-
|
|
111
|
+
retries += 1
|
|
112
|
+
backoff_time = backoff_expoent ? (backoff * retries) ** backoff_expoent : backoff
|
|
113
|
+
puts "Restarting #{replication_slot} in #{backoff_time.floor(2)}s..."
|
|
114
|
+
sleep backoff_time
|
|
115
|
+
puts "Restarting #{replication_slot}"
|
|
110
116
|
retry
|
|
111
117
|
end
|
|
112
118
|
raise
|
data/lib/wal/record_watcher.rb
CHANGED
|
@@ -41,47 +41,46 @@ module Wal
|
|
|
41
41
|
|
|
42
42
|
def self.inherited(subclass)
|
|
43
43
|
super
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
subclass.class_eval do
|
|
45
|
+
def self.change_callbacks
|
|
46
|
+
@change_callbacks ||= Hash.new { |hash, key| hash[key] = [] }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.delete_callbacks
|
|
50
|
+
@delete_callbacks ||= Hash.new { |hash, key| hash[key] = [] }
|
|
51
|
+
end
|
|
52
|
+
end
|
|
46
53
|
end
|
|
47
54
|
|
|
48
55
|
def self.on_insert(table, &block)
|
|
49
56
|
table = table.is_a?(String) ? table : table.table_name
|
|
50
|
-
|
|
57
|
+
change_callbacks[table].push(only: [:create], block: block)
|
|
51
58
|
end
|
|
52
59
|
|
|
53
60
|
def self.on_update(table, changed: nil, &block)
|
|
54
61
|
table = table.is_a?(String) ? table : table.table_name
|
|
55
|
-
|
|
62
|
+
change_callbacks[table].push(only: [:update], changed: changed&.map(&:to_s), block: block)
|
|
56
63
|
end
|
|
57
64
|
|
|
58
65
|
def self.on_save(table, changed: nil, &block)
|
|
59
66
|
table = table.is_a?(String) ? table : table.table_name
|
|
60
|
-
|
|
67
|
+
change_callbacks[table].push(only: [:create, :update], changed: changed&.map(&:to_s), block: block)
|
|
61
68
|
end
|
|
62
69
|
|
|
63
70
|
def self.on_delete(table, &block)
|
|
64
71
|
table = table.is_a?(String) ? table : table.table_name
|
|
65
|
-
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def self.change_callbacks
|
|
69
|
-
@@change_callbacks
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def self.delete_callbacks
|
|
73
|
-
@@delete_callbacks
|
|
72
|
+
delete_callbacks[table].push(block: block)
|
|
74
73
|
end
|
|
75
74
|
|
|
76
75
|
def on_record_changed(event)
|
|
77
76
|
case event
|
|
78
77
|
when InsertEvent
|
|
79
|
-
|
|
78
|
+
self.class.change_callbacks[event.full_table_name]
|
|
80
79
|
.filter { |callback| callback[:only].include? :create }
|
|
81
80
|
.each { |callback| instance_exec(event, &callback[:block]) }
|
|
82
81
|
|
|
83
82
|
when UpdateEvent
|
|
84
|
-
|
|
83
|
+
self.class.change_callbacks[event.full_table_name]
|
|
85
84
|
.filter { |callback| callback[:only].include? :update }
|
|
86
85
|
.each do |callback|
|
|
87
86
|
if (attributes = callback[:changed])
|
|
@@ -92,14 +91,14 @@ module Wal
|
|
|
92
91
|
end
|
|
93
92
|
|
|
94
93
|
when DeleteEvent
|
|
95
|
-
|
|
94
|
+
self.class.delete_callbacks[event.full_table_name].each do |callback|
|
|
96
95
|
instance_exec(event, &callback[:block])
|
|
97
96
|
end
|
|
98
97
|
end
|
|
99
98
|
end
|
|
100
99
|
|
|
101
100
|
def should_watch_table?(table)
|
|
102
|
-
(
|
|
101
|
+
(self.class.change_callbacks.keys | self.class.delete_callbacks.keys).include? table
|
|
103
102
|
end
|
|
104
103
|
|
|
105
104
|
# `RecordWatcher` supports three processing strategies:
|
data/lib/wal/replicator.rb
CHANGED
data/lib/wal/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wal
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.23
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rodrigo Navarro
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-10-
|
|
10
|
+
date: 2025-10-29 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: pg
|