Commit Graph

7 Commits

Author SHA1 Message Date
hailin 2a725af83e fix: Debezium CDC 全面安全加固 (1.0 + 2.0)
问题背景:
  - 1.0 生产环境发现 6 个孤儿 replication slot, WAL 积压 8.6GB (已清理)
  - 1.0 使用 Debezium 2.4, 存在 DBZ-7316 (WAL 无限积压) bug
  - 1.0 和 2.0 均无 max_slot_wal_keep_size 安全阀 (已在线设置 10GB)
  - 2.0 outbox connector 使用 pg_logical_emit_message 心跳, 不经 publication
  - 2.0 outbox connector RegexRouter regex=".*" 导致 heartbeat 污染消费者

修复内容:

[docker-compose.yml - 1.0 基础设施]
  - Debezium: 2.4 → 2.5.4.Final (修复 DBZ-7316)
  - PostgreSQL: 添加 max_slot_wal_keep_size=10GB
  - Debezium REST API: 端口绑定 127.0.0.1 (防 SSRF 注入)
  - PostgreSQL: 端口绑定 127.0.0.1 (防公网直连)
  - Kafka Connect: 添加 OFFSET_FLUSH_INTERVAL_MS=10s

[docker-compose.2.0.yml - 2.0 基础设施]
  - Debezium: 2.5 → 2.5.4.Final (锁定精确版本)
  - PostgreSQL: 添加 max_slot_wal_keep_size=10GB
  - Kafka Connect: 添加 OFFSET_FLUSH_INTERVAL_MS=10s

[1.0 Connector 配置 - identity/authorization]
  - 添加 heartbeat.action.query (INSERT INTO debezium_heartbeat TABLE 方式)
  - 之前只有 heartbeat.interval.ms 无 action.query, 心跳不生效

[2.0 Outbox Connector 配置 - 5个全部更新]
  - heartbeat: pg_logical_emit_message → INSERT INTO debezium_heartbeat TABLE 方式
    (TABLE 方式经过 publication → Debezium 消费 → 推进 confirmed_flush_lsn)
  - RegexRouter: regex ".*" → ".*outbox_events" (只路由 outbox 事件, heartbeat 走默认 topic)
  - table.include.list: 添加 debezium_heartbeat (确保心跳变更生成 Kafka 消息)
  - publication.autocreate.mode: filtered → disabled (使用预创建的 publication)
  - auth/contribution: 添加 signal channel 配置 (支持增量快照数据重放)

经验总结:
  1. pg_logical_emit_message 写 WAL 但不经 publication, 无法推进 confirmed_flush_lsn
  2. RegexRouter regex=".*" 把所有变更(含 heartbeat)路由到 outbox topic, 污染消费者
  3. 删除 Kafka Connect connector 不会自动清理 PostgreSQL replication slot
  4. max_slot_wal_keep_size 是 sighup 级参数, 可在线 ALTER SYSTEM + pg_reload_conf

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 07:32:13 -08:00
hailin ea3d256647 fix(deploy): 恢复connector JSON原样,仅在load_env中export变量修复envsubst
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 06:09:53 -08:00
hailin 5728953b41 fix(deploy): connector JSON改为硬编码凭据,与outbox connector保持一致
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 06:06:47 -08:00
hailin a4f3a8d3ab fix(deploy): 修复envsubst无法解析${VAR:-default}语法导致CDC connector注册失败
问题:
  commit 5b1f4c82 在 full-reset Step 9 中用 envsubst 替换 connector JSON 中的
  数据库凭据,但 envsubst(GNU gettext)不支持 bash 的 ${VAR:-default} 语法,
  导致 "${POSTGRES_USER:-rwa_user}" 被原样发送给 Debezium,认证失败。

修复:
  1. deploy-mining.sh load_env(): 默认值赋值改为 export,确保 envsubst 能访问
  2. connector JSON 文件: ${VAR:-default} 改为 ${VAR},默认值由脚本 export 提供

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 06:03:38 -08:00
hailin 6f01892945 fix(debezium): identity connector 添加 wallet_addresses 表
Debezium identity-connector 之前只捕获 user_accounts 表,
导致 auth-service 的 WalletAddressCdcConsumer 收不到任何事件。
添加 public.wallet_addresses 到 table.include.list。

需要重新注册 connector 才能生效。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 14:06:42 -08:00
hailin 6c77828944 fix(deploy): 完善 cdc-resnapshot 自动从配置文件创建连接器
- 修复 database.hostname: postgres -> rwa-postgres
- cdc-resnapshot 现在会自动检查连接器是否存在
- 如果连接器不存在,自动从配置文件创建(使用 snapshot.mode=always)
- 修复连接器映射到配置文件的逻辑

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 07:55:19 -08:00
hailin b5ebf8a615 feat(admin-service): 实现 Debezium CDC 数据同步
- 新增 CdcConsumerService 消费 PostgreSQL WAL 变更事件
- 配置 Debezium Connect 服务和 PostgreSQL 逻辑复制
- 更新 deploy.sh 支持 Debezium 启动和连接器管理
- 新增 identity-postgres-connector 配置同步 user_accounts 表
- 保留原有 Outbox 机制用于业务领域事件

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 18:35:53 -08:00