Skip to content

fix(cdc): resolve 6 CDC operational gaps - #3

Merged
aupv9 merged 1 commit into
mainfrom
claude/analyze-features-roadmap-1XrMV
Apr 5, 2026
Merged

aupv9 merged 1 commit into
mainfrom
claude/analyze-features-roadmap-1XrMV

Conversation

@aupv9

@aupv9 aupv9 commented Apr 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • 🔴 Critical — Debezium replication slot leak: Enforced slot.drop.on.stop=true via applyDefaults(); fixed destroy() sequence to call engine.close() first (triggers WAL slot drop), then awaitTermination(30s), then shutdownNow(). Previous impl killed the engine thread before the slot drop completed, leaving leaked replication slots that fill the PostgreSQL WAL disk.
  • 🟡 ShardChangeEvent missing before/after images: Split single payload map into separate afterImage + beforeImage fields with correct semantics per operation. Added insert(), update(), delete() factory methods. Kept payload() convenience accessor.
  • 🟡 Kafka auto-commit: enable.auto.commit=false is now hardcoded in applyDefaults() and cannot be overridden. commitSync() is called after each full batch — at-least-once delivery guarantee. Best-effort commit on graceful shutdown.
  • 🟡 Kafka partition ordering: Documented required Debezium message.key.columns config in javadoc so same shard key always routes to the same Kafka partition, preserving per-shard-key event order.
  • 🟡 Multi-shard CDC wiring: New CdcProducerRegistry — register N shards via addShard() before start; one @Bean manages all producers' full lifecycle (start/stop) via InitializingBean/DisposableBean.
  • 🟠 No Dead Letter Queue: New ShardCdcDeadLetterQueue @FunctionalInterface with logging() (discard + warn) and throwing() (halt consumer) built-ins. DLQ fires only when all listeners fail — partial success does not trigger DLQ.

Test plan

  • Verify DebeziumShardChangeProducer.destroy() drops the replication slot: start app, kill it cleanly, confirm SELECT * FROM pg_replication_slots returns no rows for sharding_cdc_* slots
  • Simulate crash (kill -9): confirm slot eventually dropped or runnable manual cleanup via SELECT pg_drop_replication_slot('sharding_cdc_shard_0')
  • Verify ShardChangeEvent.afterImage / beforeImage populated correctly for INSERT, UPDATE, DELETE via Debezium JSON envelope parsing
  • Verify Kafka consumer does NOT commit offsets before all listeners process a batch; simulate listener failure and confirm re-delivery on restart
  • Verify DLQ logging() fires when all listeners throw; verify throwing() halts the poll loop
  • Wire CdcProducerRegistry with 3 shards; verify all 3 producers start/stop together and events reach shared listeners

https://claude.ai/code/session_01PDnu78vAKJV5L32Ae3qGno

Critical and medium-severity issues identified in the CDC module:

1. Debezium replication slot leak (CRITICAL)
   - Enforce slot.drop.on.stop=true via applyDefaults()
   - Fix destroy() sequence: engine.close() FIRST (triggers slot drop),
     then executor.awaitTermination(30s), then force shutdownNow()
   - Previous impl called executor.shutdownNow() before engine.close(),
     killing the engine thread before the slot drop could complete

2. ShardChangeEvent missing before/after images
   - Split single payload map into separate afterImage + beforeImage fields
   - Add operation-specific factory methods: insert(), update(), delete()
   - Keep payload() convenience method returning relevant image per op type
   - Consistent with Debezium envelope semantics (op=c/u/d)

3. Dead Letter Queue (DLQ) pattern
   - New ShardCdcDeadLetterQueue @FunctionalInterface
   - send() called only when ALL listeners fail (partial success = no DLQ)
   - Built-in: logging() discards with WARNING log; throwing() halts consumer
   - Both DebeziumShardChangeProducer and KafkaShardChangeProducer support DLQ

4. Kafka: manual offset commit strategy
   - Force enable.auto.commit=false in applyDefaults() (cannot be overridden)
   - commitSync() called AFTER full batch dispatch for at-least-once delivery
   - Best-effort commitSync() on graceful shutdown before consumer.close()
   - Documented: listeners MUST be idempotent due to at-least-once semantics

5. Kafka partition ordering per shard key
   - Document Debezium message.key.columns config for partition-key routing
   - Before/after image extraction consistent with DebeziumShardChangeProducer

6. Multi-shard CDC wiring
   - New CdcProducerRegistry manages N DebeziumShardChangeProducers as one bean
   - addShard() registers a shard before start; lifecycle via Spring InitializingBean
   - Global listeners registered once, broadcast to all shards automatically
   - Prevents N-bean boilerplate in application @configuration classes

https://claude.ai/code/session_01PDnu78vAKJV5L32Ae3qGno
@aupv9
aupv9 merged commit 49b5e46 into main Apr 5, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants