Repository navigation
fix(cdc): resolve 6 CDC operational gaps - #3
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
slot.drop.on.stop=trueviaapplyDefaults(); fixeddestroy()sequence to callengine.close()first (triggers WAL slot drop), thenawaitTermination(30s), thenshutdownNow(). Previous impl killed the engine thread before the slot drop completed, leaving leaked replication slots that fill the PostgreSQL WAL disk.payloadmap into separateafterImage+beforeImagefields with correct semantics per operation. Addedinsert(),update(),delete()factory methods. Keptpayload()convenience accessor.enable.auto.commit=falseis now hardcoded inapplyDefaults()and cannot be overridden.commitSync()is called after each full batch — at-least-once delivery guarantee. Best-effort commit on graceful shutdown.message.key.columnsconfig in javadoc so same shard key always routes to the same Kafka partition, preserving per-shard-key event order.CdcProducerRegistry— register N shards viaaddShard()before start; one@Beanmanages all producers' full lifecycle (start/stop) viaInitializingBean/DisposableBean.ShardCdcDeadLetterQueue@FunctionalInterfacewithlogging()(discard + warn) andthrowing()(halt consumer) built-ins. DLQ fires only when all listeners fail — partial success does not trigger DLQ.Test plan
DebeziumShardChangeProducer.destroy()drops the replication slot: start app, kill it cleanly, confirmSELECT * FROM pg_replication_slotsreturns no rows forsharding_cdc_*slotsSELECT pg_drop_replication_slot('sharding_cdc_shard_0')ShardChangeEvent.afterImage/beforeImagepopulated correctly for INSERT, UPDATE, DELETE via Debezium JSON envelope parsinglogging()fires when all listeners throw; verifythrowing()halts the poll loopCdcProducerRegistrywith 3 shards; verify all 3 producers start/stop together and events reach shared listenershttps://claude.ai/code/session_01PDnu78vAKJV5L32Ae3qGno