Add debezium-cdc module: Debezium 3.7.1 CDC from Postgres 18 to Kafka, Connect vs embedded engine vs outbox
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5uEyg58znuchZ8C8i
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
e2c42dc268
commit
95e75d0101
@@ -0,0 +1,69 @@
|
||||
### Server settings that make CDC possible
|
||||
postgres
|
||||
-----------------------------------------------------------------
|
||||
PostgreSQL 18.7 (Debian 18.7-1.pgdg12+5) on x86_64-pc-linux-gnu
|
||||
(1 row)
|
||||
|
||||
wal_level
|
||||
-----------
|
||||
logical
|
||||
(1 row)
|
||||
|
||||
max_replication_slots
|
||||
-----------------------
|
||||
4
|
||||
(1 row)
|
||||
|
||||
max_wal_senders
|
||||
-----------------
|
||||
4
|
||||
(1 row)
|
||||
|
||||
|
||||
### Before any connector: no slots, no publications
|
||||
slots
|
||||
-------
|
||||
0
|
||||
(1 row)
|
||||
|
||||
publications
|
||||
--------------
|
||||
0
|
||||
(1 row)
|
||||
|
||||
|
||||
### What logical decoding produces, read with the built-in test_decoding plugin on a throwaway slot
|
||||
data
|
||||
----------------------------------------------------------------------
|
||||
BEGIN 770
|
||||
table public.noise: INSERT: id[bigint]:1 payload[text]:'hello'
|
||||
COMMIT 770
|
||||
BEGIN 771
|
||||
table public.noise: UPDATE: id[bigint]:1 payload[text]:'hello again'
|
||||
COMMIT 771
|
||||
BEGIN 772
|
||||
table public.noise: DELETE: id[bigint]:1
|
||||
COMMIT 772
|
||||
(9 rows)
|
||||
|
||||
|
||||
### Register the Debezium connector (Kafka Connect, pgoutput) and wait for it
|
||||
register 201
|
||||
connector: RUNNING ['RUNNING']
|
||||
|
||||
### What the connector created inside Postgres
|
||||
slot_name | plugin | slot_type | active
|
||||
----------------+----------+-----------+--------
|
||||
connect_orders | pgoutput | logical | t
|
||||
(1 row)
|
||||
|
||||
pubname | puballtables | pubinsert | pubupdate | pubdelete | pubtruncate
|
||||
--------------------+--------------+-----------+-----------+-----------+-------------
|
||||
connect_orders_pub | f | t | t | t | t
|
||||
(1 row)
|
||||
|
||||
pubname | schemaname | tablename
|
||||
--------------------+------------+-----------
|
||||
connect_orders_pub | public | orders
|
||||
(1 row)
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
### Replica identity of orders (d = default, primary key only)
|
||||
relname | relreplident
|
||||
---------+--------------
|
||||
orders | d
|
||||
(1 row)
|
||||
|
||||
|
||||
### Four statements, one transaction each
|
||||
|
||||
### Topic shop.public.orders in WAL order (p = partition). The two op=r records are the initial snapshot.
|
||||
p=1 op=r key={"id":2} lsn=30425656 txId=774 snapshot=last before=null after={"id":2,"customer":"ravi","status":"NEW","amount_cents":2500}
|
||||
p=0 op=r key={"id":1} lsn=30425656 txId=774 snapshot=first before=null after={"id":1,"customer":"asha","status":"NEW","amount_cents":1500}
|
||||
p=0 op=c key={"id":3} lsn=30425880 txId=775 snapshot=false before=null after={"id":3,"customer":"meera","status":"NEW","amount_cents":999}
|
||||
p=0 op=u key={"id":3} lsn=30426168 txId=776 snapshot=false before=null after={"id":3,"customer":"meera","status":"PAID","amount_cents":999}
|
||||
p=0 op=u key={"id":3} lsn=30426312 txId=777 snapshot=false before=null after={"id":3,"customer":"meera","status":"PAID","amount_cents":1099}
|
||||
p=0 op=d key={"id":3} lsn=30426456 txId=778 snapshot=false before={"id":3,"customer":"","status":"","amount_cents":0} after=null
|
||||
p=0 key={"id":3} TOMBSTONE (null value)
|
||||
|
||||
### The raw insert envelope for id 3, exactly as Kafka stores it (value, pretty-printed with jq)
|
||||
{
|
||||
"before": null,
|
||||
"after": {
|
||||
"id": 3,
|
||||
"customer": "meera",
|
||||
"status": "NEW",
|
||||
"amount_cents": 999
|
||||
},
|
||||
"source": {
|
||||
"version": "3.7.1.Final",
|
||||
"connector": "postgresql",
|
||||
"name": "shop",
|
||||
"ts_ms": 1795939109105,
|
||||
"snapshot": "false",
|
||||
"db": "shop",
|
||||
"sequence": "[null,\"30425880\"]",
|
||||
"ts_us": 1795939109105717,
|
||||
"ts_ns": 1795939109105717000,
|
||||
"schema": "public",
|
||||
"table": "orders",
|
||||
"txId": 775,
|
||||
"lsn": 30425880,
|
||||
"xmin": null,
|
||||
"origin": null,
|
||||
"origin_lsn": null
|
||||
},
|
||||
"transaction": null,
|
||||
"op": "c",
|
||||
"ts_ms": 1795939109620,
|
||||
"ts_us": 1795939109620915,
|
||||
"ts_ns": 1795939109620915228
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
### REPLICA IDENTITY DEFAULT: update and delete of order 4
|
||||
p=2 op=c key={"id":4} lsn=30441152 txId=779 snapshot=false before=null after={"id":4,"customer":"dev","status":"NEW","amount_cents":500}
|
||||
p=2 op=u key={"id":4} lsn=30441344 txId=780 snapshot=false before=null after={"id":4,"customer":"dev","status":"PAID","amount_cents":500}
|
||||
p=2 op=d key={"id":4} lsn=30441512 txId=781 snapshot=false before={"id":4,"customer":"","status":"","amount_cents":0} after=null
|
||||
p=2 key={"id":4} TOMBSTONE (null value)
|
||||
|
||||
### Switch the table to REPLICA IDENTITY FULL
|
||||
relname | relreplident
|
||||
---------+--------------
|
||||
orders | f
|
||||
(1 row)
|
||||
|
||||
### Same three statements for order 5
|
||||
p=2 op=c key={"id":5} lsn=30442128 txId=783 snapshot=false before=null after={"id":5,"customer":"kiran","status":"NEW","amount_cents":700}
|
||||
p=2 op=u key={"id":5} lsn=30442320 txId=784 snapshot=false before={"id":5,"customer":"kiran","status":"NEW","amount_cents":700} after={"id":5,"customer":"kiran","status":"PAID","amount_cents":700}
|
||||
p=2 op=d key={"id":5} lsn=30442488 txId=785 snapshot=false before={"id":5,"customer":"kiran","status":"PAID","amount_cents":700} after=null
|
||||
p=2 key={"id":5} TOMBSTONE (null value)
|
||||
|
||||
### Add a column while the connector is running; the next event carries it, no restart needed
|
||||
p=0 op=u key={"id":1} lsn=30454520 txId=787 snapshot=false before={"id":1,"customer":"asha","status":"NEW","amount_cents":1500,"note":null} after={"id":1,"customer":"asha","status":"NEW","amount_cents":1500,"note":"gift wrap"}
|
||||
@@ -0,0 +1,21 @@
|
||||
### Topic layout
|
||||
Topic: shop.public.orders TopicId: e8p9s2PcSK6mPO3bvQRmyA PartitionCount: 3 ReplicationFactor: 1 Configs: min.insync.replicas=1
|
||||
|
||||
### Write: 6 orders (ids 10..15), then 4 rounds of single-row updates, then one transaction that updates 10, then 12, then 13
|
||||
### Which partition each key landed on, and whether its events stayed in WAL order inside that partition
|
||||
key 10: partitions=['1'] events=6 lsn strictly increasing in offset order=True
|
||||
key 11: partitions=['1'] events=5 lsn strictly increasing in offset order=True
|
||||
key 12: partitions=['2'] events=6 lsn strictly increasing in offset order=True
|
||||
key 13: partitions=['0'] events=6 lsn strictly increasing in offset order=True
|
||||
key 14: partitions=['0'] events=5 lsn strictly increasing in offset order=True
|
||||
key 15: partitions=['0'] events=5 lsn strictly increasing in offset order=True
|
||||
|
||||
### Reading partition 0, then 1, then 2 (what the broker stores): is the LSN sequence globally increasing?
|
||||
lsn sequence head: [30455336, 30455528, 30455720, 30456392, 30456552, 30456712, 30457352, 30457512]
|
||||
globally increasing across partitions: False
|
||||
events per partition: {'0': 16, '1': 11, '2': 6}
|
||||
|
||||
### The multi-statement transaction (statuses TX-A, TX-B, TX-C): one txId, increasing lsn, three different keys
|
||||
status=TX-A key=10 partition=1 lsn=30459776 txId=818
|
||||
status=TX-B key=12 partition=2 lsn=30459896 txId=818
|
||||
status=TX-C key=13 partition=0 lsn=30460016 txId=818
|
||||
@@ -0,0 +1,14 @@
|
||||
### Register the outbox connector (EventRouter single message transform)
|
||||
register 201
|
||||
|
||||
### One transaction writes the business row AND the outbox row
|
||||
|
||||
### A second transaction inserts an outbox row and deletes it before committing (the 'clean up as you go' habit)
|
||||
outbox rows left in the table: 1
|
||||
|
||||
### Topic outbox.event.Order (headers | key | value; the four __debezium.context.* headers are trimmed with sed)
|
||||
id:00000000-0000-0000-0000-000000000021,eventType:OrderCreated | 21 | {"orderId":21,"customer":"omkar","amountCents":100}
|
||||
id:00000000-0000-0000-0000-000000000020,eventType:OrderCreated | 20 | {"orderId":20,"customer":"zoya","amountCents":4200}
|
||||
|
||||
### Topics that exist for this connector
|
||||
outbox.event.Order
|
||||
@@ -0,0 +1,44 @@
|
||||
### Safety valve: the default cap on WAL a slot may pin (-1 = unlimited)
|
||||
max_slot_wal_keep_size
|
||||
------------------------
|
||||
-1
|
||||
(1 row)
|
||||
|
||||
|
||||
### Baseline: both connectors running, nothing unusual written
|
||||
slot_name | active | wal_kept_for_slot | unconfirmed
|
||||
----------------+--------+-------------------+-------------
|
||||
connect_orders | t | 2752 bytes | 2752 bytes
|
||||
connect_outbox | t | 1064 bytes | 432 bytes
|
||||
(2 rows)
|
||||
|
||||
|
||||
### Failure 1: healthy connectors, but all the writes go to a table nobody captures (100,000 rows, about 33 MB of WAL)
|
||||
slot_name | active | wal_kept_for_slot | unconfirmed
|
||||
----------------+--------+-------------------+-------------
|
||||
connect_orders | t | 33 MB | 33 MB
|
||||
connect_outbox | t | 33 MB | 33 MB
|
||||
(2 rows)
|
||||
|
||||
|
||||
### Failure 2: delete the outbox connector. Kafka Connect does not drop its slot.
|
||||
slot_name | active | wal_kept_for_slot | unconfirmed
|
||||
----------------+--------+-------------------+-------------
|
||||
connect_orders | t | 65 MB | 65 MB
|
||||
connect_outbox | f | 65 MB | 65 MB
|
||||
(2 rows)
|
||||
|
||||
|
||||
### Fix for 2: drop the orphaned slot by hand
|
||||
slot_name | active | wal_kept_for_slot | unconfirmed
|
||||
----------------+--------+-------------------+-------------
|
||||
connect_orders | t | 65 MB | 65 MB
|
||||
(1 row)
|
||||
|
||||
|
||||
### Fix for 1: heartbeat.interval.ms plus a heartbeat.action.query that writes to a captured table (public.heartbeat)
|
||||
slot_name | active | wal_kept_for_slot | unconfirmed
|
||||
----------------+--------+-------------------+-------------
|
||||
connect_orders | t | 656 bytes | 656 bytes
|
||||
(1 row)
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
### Start the Spring Boot app with the embedded engine (slot embedded_orders, topic prefix embedded)
|
||||
snapshot rows delivered by the engine: 9
|
||||
slot_name | plugin | active
|
||||
-----------------+----------+--------
|
||||
embedded_orders | pgoutput | t
|
||||
(1 row)
|
||||
|
||||
|
||||
### Insert, update and delete order 30, and the app's own view of them (EMBEDDED = engine callback, LISTENER = @KafkaListener on embedded.public.orders)
|
||||
EMBEDDED op=c key={"id":30} lsn=99363544 before=null after={"id":30,"customer":"tara","status":"NEW","amount_cents":300,"note":null}
|
||||
LISTENER partition=0 offset=5 op=c key={"id":30} lsn=99363544 before=null after={"id":30,"customer":"tara","status":"NEW","amount_cents":300,"note":null}
|
||||
EMBEDDED op=u key={"id":30} lsn=99363736 before={"id":30,"customer":"tara","status":"NEW","amount_cents":300,"note":null} after={"id":30,"customer":"tara","status":"PAID","amount_cents":300,"note":null}
|
||||
LISTENER partition=0 offset=6 op=u key={"id":30} lsn=99363736 before={"id":30,"customer":"tara","status":"NEW","amount_cents":300,"note":null} after={"id":30,"customer":"tara","status":"PAID","amount_cents":300,"note":null}
|
||||
EMBEDDED op=d key={"id":30} lsn=99363904 before={"id":30,"customer":"tara","status":"PAID","amount_cents":300,"note":null} after=null
|
||||
EMBEDDED key={"id":30} TOMBSTONE (null value)
|
||||
LISTENER partition=0 offset=7 op=d key={"id":30} lsn=99363904 before={"id":30,"customer":"tara","status":"PAID","amount_cents":300,"note":null} after=null
|
||||
LISTENER partition=0 offset=8 key={"id":30} TOMBSTONE (ignored)
|
||||
|
||||
### Same UPDATE, seen by Kafka Connect (topic shop.public.orders) and by the embedded engine (topic embedded.public.orders): what differs?
|
||||
5c5
|
||||
< "name": "shop",
|
||||
---
|
||||
> "name": "embedded",
|
||||
|
||||
### At-least-once: offsets are flushed every 60 s (Debezium's default). Wait 65 s, then three updates, then kill -9 the JVM
|
||||
killed. Events the first run delivered for key id=1 after the wait:
|
||||
lsn=99384632 status set to A0
|
||||
lsn=99385008 status set to A1
|
||||
lsn=99385192 status set to A2
|
||||
|
||||
### Restart the app (same offset file, same slot)
|
||||
EMBEDDED events in the second run (anything here is a redelivery):
|
||||
lsn=99385008 status set to A1
|
||||
lsn=99385192 status set to A2
|
||||
|
||||
### What a downstream consumer sees on embedded.public.orders: records per (key, lsn) for the three A updates
|
||||
1 status=A0 lsn=99384632
|
||||
2 status=A1 lsn=99385008
|
||||
2 status=A2 lsn=99385192
|
||||
Reference in New Issue
Block a user