Fail clearly when the replication slot is invalidated

With max_slot_wal_keep_size set, a long producer stall invalidates the replication slot. On restart, the single-slot path of SetupReplicationSlot skipped the health check and retried START_REPLICATION on the dead slot until it was dropped.

Each retry now fails at setup, before START_REPLICATION, with an error naming the slot, the reason Postgres reports (wal_removed here) and the recovery. The producer does not drop the dead slot or snapshot anything itself; the error says changes made while the slot was lost stay missing until the tables are re-snapshotted with POST /v1/snapshot.

flowchart LR
  A["slot lost (wal_removed)"] --> B["setup: slotHealth"]
  B -->|"unusable"| C["error names slot and recovery"]
  C --> D["operator drops slot, restarts"]
  D --> E["operator POSTs /v1/snapshot for the tables"]

The single-slot path now uses the to_jsonb read, which also fixes the failover path's PG16 error: main selects invalidation_reason directly, and that column exists only on PG17+.

Tested on a self-managed test instance (Postgres 18.7): 0.0.163-beta sent 13 failing StartReplication calls to a lost slot, this build sent none. After the drop, restart and snapshot request the message names, the change made while the slot was lost reached ClickHouse. The suite passes in full on Postgres 17; on 16 the slot specs pass and only two untouched PG17-only specs fail.

Closes #385 (closed)

An AI coding assistant wrote this change. The assistant also checked each claim against the code at commit 00b1b7d9 and the test logs, and ran golangci-lint and the Go test suite on Postgres 17 and 16, and the described scenario, on a self-managed test instance on a test VM.

Merge request reports

Loading
Loading