waldit 0.0.26 → 0.0.27
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/lib/waldit/version.rb +1 -1
- data/lib/waldit/watcher.rb +25 -23
- data/rbi/waldit.rbi +3 -3
- 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: 18bbabfc0b8a6f7386c30773ebb4515f45ea2ff03b3991c28b676eed77c2d001
|
|
4
|
+
data.tar.gz: a69f4a66db8b50305a9b5386183c4626b2a13fff018d1d17d84c95f8e64a2db9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 356750f5feefe2a477ed06ac7d90d78ab55fa7e7bafd9e6fa3edb2759fa77e6813e59a15b53f94f081c3aeba94baac2e1b2e2da968d8e6e0b304d0acdb929bfc
|
|
7
|
+
data.tar.gz: d1b1115e71044bce7ad3eb2f9efe3f6e47eb23687966818a4ee8218a8add9c5fbb65a449742d6c988eb86c8d5384447d66d73a35e037122ee9cd8c1cbbb5b3ee
|
data/lib/waldit/version.rb
CHANGED
data/lib/waldit/watcher.rb
CHANGED
|
@@ -14,10 +14,13 @@ module Waldit
|
|
|
14
14
|
|
|
15
15
|
def on_transaction_events(events)
|
|
16
16
|
begin_event = events.next
|
|
17
|
+
# The commit LSN identifies the transaction. The xid from the replication stream is the raw
|
|
18
|
+
# 32-bit counter, which wraps around every ~4 billion transactions, so it cannot be used as
|
|
19
|
+
# a durable identity.
|
|
17
20
|
if begin_event.estimated_size < Waldit.large_transaction_threshold
|
|
18
|
-
process_in_memory(events)
|
|
21
|
+
process_in_memory(begin_event.final_lsn, events)
|
|
19
22
|
else
|
|
20
|
-
process_streaming(events)
|
|
23
|
+
process_streaming(begin_event.final_lsn, events)
|
|
21
24
|
end
|
|
22
25
|
rescue PG::ConnectionBad
|
|
23
26
|
raise if @retry
|
|
@@ -68,7 +71,7 @@ module Waldit
|
|
|
68
71
|
PARAMS_PER_ROW = COLUMNS.size
|
|
69
72
|
MAX_ROWS_PER_BATCH = 65535 / PARAMS_PER_ROW
|
|
70
73
|
|
|
71
|
-
def process_in_memory(events)
|
|
74
|
+
def process_in_memory(transaction_id, events)
|
|
72
75
|
records = {}
|
|
73
76
|
|
|
74
77
|
events.each do |event|
|
|
@@ -118,7 +121,7 @@ module Waldit
|
|
|
118
121
|
|
|
119
122
|
rec = {
|
|
120
123
|
committed_at: event.timestamp,
|
|
121
|
-
transaction_id
|
|
124
|
+
transaction_id:,
|
|
122
125
|
lsn: evt.lsn,
|
|
123
126
|
table_name: table,
|
|
124
127
|
primary_key: evt.primary_key.to_json,
|
|
@@ -201,7 +204,7 @@ module Waldit
|
|
|
201
204
|
SQL
|
|
202
205
|
end
|
|
203
206
|
|
|
204
|
-
def process_streaming(events)
|
|
207
|
+
def process_streaming(transaction_id, events)
|
|
205
208
|
ensure_streaming_statements_prepared
|
|
206
209
|
|
|
207
210
|
@connection.transaction do
|
|
@@ -215,46 +218,44 @@ module Waldit
|
|
|
215
218
|
.map { |diff| [diff, tables.filter { |table| store_changes(table).include? diff }] }
|
|
216
219
|
.to_h
|
|
217
220
|
|
|
218
|
-
log_new = (changes[:new] || []).map { |table| "#{table}" }
|
|
219
|
-
log_old = (changes[:old] || []).map { |table| "#{table}" }
|
|
220
|
-
log_diff = (changes[:diff] || []).map { |table| "#{table}" }
|
|
221
|
-
|
|
222
221
|
@connection.exec_prepared("waldit_finish", [
|
|
223
|
-
|
|
222
|
+
transaction_id,
|
|
224
223
|
event.timestamp,
|
|
225
|
-
"{#{
|
|
226
|
-
"{#{
|
|
227
|
-
"{#{
|
|
224
|
+
"{#{changes[:new].join(",")}}",
|
|
225
|
+
"{#{changes[:old].join(",")}}",
|
|
226
|
+
"{#{changes[:diff].join(",")}}",
|
|
227
|
+
"{#{tables.join(",")}}",
|
|
228
228
|
])
|
|
229
229
|
|
|
230
230
|
@connection.exec_prepared("waldit_cleanup", [
|
|
231
|
-
|
|
232
|
-
"{#{(
|
|
233
|
-
"{#{
|
|
231
|
+
transaction_id,
|
|
232
|
+
"{#{(changes[:new] + changes[:old]).join(",")}}",
|
|
233
|
+
"{#{changes[:diff].join(",")}}",
|
|
234
|
+
"{#{tables.join(",")}}",
|
|
234
235
|
])
|
|
235
236
|
end
|
|
236
237
|
|
|
237
238
|
@retry = false
|
|
238
239
|
|
|
239
240
|
when InsertEvent
|
|
240
|
-
tables << event.table if audit_event(event)
|
|
241
|
+
tables << event.table if audit_event(transaction_id, event)
|
|
241
242
|
|
|
242
243
|
when UpdateEvent
|
|
243
|
-
tables << event.table if audit_event(event)
|
|
244
|
+
tables << event.table if audit_event(transaction_id, event)
|
|
244
245
|
|
|
245
246
|
when DeleteEvent
|
|
246
|
-
tables << event.table if audit_event(event)
|
|
247
|
+
tables << event.table if audit_event(transaction_id, event)
|
|
247
248
|
end
|
|
248
249
|
end
|
|
249
250
|
end
|
|
250
251
|
end
|
|
251
252
|
|
|
252
|
-
def audit_event(event)
|
|
253
|
+
def audit_event(transaction_id, event)
|
|
253
254
|
return unless event.primary_key
|
|
254
255
|
primary_key = event.primary_key.to_json
|
|
255
256
|
table = event.full_table_name
|
|
256
257
|
|
|
257
|
-
audit = [
|
|
258
|
+
audit = [transaction_id, event.lsn, table, primary_key, event.context.to_json]
|
|
258
259
|
|
|
259
260
|
case event
|
|
260
261
|
when InsertEvent
|
|
@@ -271,7 +272,7 @@ module Waldit
|
|
|
271
272
|
true
|
|
272
273
|
|
|
273
274
|
when DeleteEvent
|
|
274
|
-
case @connection.exec_prepared("waldit_delete_cleanup", [
|
|
275
|
+
case @connection.exec_prepared("waldit_delete_cleanup", [transaction_id, table, primary_key]).values
|
|
275
276
|
in [["update", previous_old]]
|
|
276
277
|
@connection.exec_prepared("waldit_delete", audit + [previous_old])
|
|
277
278
|
in []
|
|
@@ -363,7 +364,7 @@ module Waldit
|
|
|
363
364
|
)
|
|
364
365
|
ELSE null
|
|
365
366
|
END
|
|
366
|
-
WHERE transaction_id = $1
|
|
367
|
+
WHERE transaction_id = $1 AND table_name = ANY ($6::varchar[])
|
|
367
368
|
SQL
|
|
368
369
|
rescue PG::DuplicatePstatement
|
|
369
370
|
end
|
|
@@ -374,6 +375,7 @@ module Waldit
|
|
|
374
375
|
WHERE
|
|
375
376
|
transaction_id = $1
|
|
376
377
|
AND action = 'update'::waldit_action
|
|
378
|
+
AND table_name = ANY ($4::varchar[])
|
|
377
379
|
AND (
|
|
378
380
|
(diff IS NULL AND table_name = ANY ($3::varchar[]))
|
|
379
381
|
OR
|
data/rbi/waldit.rbi
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
module Waldit
|
|
3
3
|
extend T::Sig
|
|
4
4
|
extend Waldit::Context
|
|
5
|
-
VERSION = "0.0.
|
|
5
|
+
VERSION = "0.0.27"
|
|
6
6
|
|
|
7
7
|
class << self
|
|
8
8
|
sig { returns(String) }
|
|
@@ -105,8 +105,8 @@ module Waldit
|
|
|
105
105
|
class Watcher < Wal::StreamingWatcher
|
|
106
106
|
extend T::Sig
|
|
107
107
|
|
|
108
|
-
sig { params(event: T.any(InsertEvent, UpdateEvent, DeleteEvent)).void }
|
|
109
|
-
def audit_event(event); end
|
|
108
|
+
sig { params(transaction_id: Integer, event: T.any(InsertEvent, UpdateEvent, DeleteEvent)).void }
|
|
109
|
+
def audit_event(transaction_id, event); end
|
|
110
110
|
|
|
111
111
|
sig { override.params(events: T::Enumerator[Event]).void }
|
|
112
112
|
def on_transaction_events(events); end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: waldit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.27
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rodrigo Navarro
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-07-31 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: wal
|