Repository navigation
Description
Summary
Rapid back-to-back failovers between members of a multi-cloud DocumentDB resource leave the demoted primary in a state where its WAL receiver cannot reconnect to the new primary, because the two clusters end up on incompatible PostgreSQL timelines. The demoted primary is unrecoverable via log replay and requires a full pg_basebackup rebuild to re-attach as a replica.
The DocumentDB operator does not appear to:
pg_rewindthe demoted primary before re-attaching it as a replica, or- Refuse / serialize a second promotion until cross-cloud replication is confirmed streaming again, or
- Auto-bootstrap a replica via
pg_basebackupwhen its WAL receiver fails with a timeline-mismatch FATAL.
The result is a manual recovery path (delete the CNPG Cluster resource so the operator re-creates it) that is easy to get wrong, especially in a demo / live-failover scenario.
Repro
Multi-cloud setup from https://github.com/markjbrown/documentdb-local-to-multicloud:
- Hub cluster + 2 member clusters (Azure AKS + AWS EKS),
instancesPerNode: 3on both DocumentDBresource withclusterReplication.primary: azure-documentdbandcrossCloudNetworkingStrategy: serviceLoadBalancer- DocumentDB operator preview build
Steps:
- Promote AWS:
kubectl --context hub -n documentdb-preview-ns patch documentdb documentdb-preview --type=merge -p '{"spec":{"clusterReplication":{"primary":"aws-documentdb"}}}' - Wait until both clusters report Healthy in their CNPG status (~30-60s).
- Promote back to Azure with the same patch (target=
azure-documentdb). - Within 30s of the second promotion completing, observe the replica.
Observed
On the new replica (AWS in this repro):
$ kubectl --context aws-documentdb -n documentdb-preview-ns logs <pod>-1 -c postgres | tail
FATAL: requested starting point 3/88000000 on timeline 8 is not in this server's history
DETAIL: This server's history forked from timeline 8 at 3/8704C8C0
$ kubectl --context aws-documentdb -n documentdb-preview-ns exec <pod>-1 -c postgres -- \
psql -U postgres -tA -c "select status, sender_host from pg_stat_wal_receiver"
(0 rows)
The WAL receiver process keeps exiting with the FATAL above, so pg_stat_wal_receiver is empty. The cluster appears Healthy from CNPG's perspective (the pods are Running) but is silently not replicating.
pg_stat_replication on the new primary correspondingly shows zero connected standbys from the cross-cloud peer.
Expected
One of the following:
- The operator detects the timeline mismatch and runs
pg_rewindon the demoted primary against the new primary before starting the WAL receiver, OR - The operator refuses (or serializes) the second promotion until cross-cloud replication health is confirmed (
pg_stat_wal_receiver.status = 'streaming'on the current replica), OR - The operator detects the persistent WAL-receiver failure and re-bootstraps the replica via
pg_basebackupfrom the new primary (the same path used for initial replica setup viaexternalCluster).
Recovery (manual workaround)
Deleting the CNPG Cluster resource on the broken replica triggers the DocumentDB operator to re-create it from scratch, which uses pg_basebackup from the current primary via the existing externalCluster definition:
kubectl --context <broken-replica-context> -n documentdb-preview-ns \
delete cluster.postgresql.cnpg.io <cnpg-cluster-name> --wait=falseAfter ~2-3 min the cluster is back at 3/3 Healthy and pg_stat_wal_receiver shows status: streaming.
This is destructive (wipes all PVCs) but functions as a workable rebuild-replica primitive. It would be useful if the operator exposed this as a first-class action — e.g. an annotation like documentdb.io/rebuild-replica: "true" or a sub-resource — instead of requiring users to delete the underlying CNPG cluster directly.
Two related issues observed during the same repro
These showed up in the same investigation; happy to split them out into separate issues if preferred:
-
Stale
promotionTokenafter every successful failover. After a successful primary swap, the new primary's CNPG cluster keepsspec.replica.promotionTokenpopulated. CNPG then reportsCluster is unrecoverable / Promotion token content is not correctuntil you manuallykubectl patch ... --type=json -p '[{"op":"remove","path":"/spec/replica/promotionToken"}]'. The operator should remove the token once promotion has succeeded. -
instancesPerNodehonored only on the primary side. Settingspec.instancesPerNode: 3on the hubDocumentDBresource creates 3 instances on the primary's CNPG cluster but only 1 on the replica's. Direct-patchingspec.instances: 3on the replica's CNPG cluster works, but the operator does not reconcile this back, and the patch is silently lost on the next failover.
Workarounds we baked into our demo monitor app
/api/promoteis now gated on areplicationHealthyprobe (pg_stat_wal_receiver.status = 'streaming'on the replica + no stale tokens on either side). Returns HTTP 409 with reason if not healthy./api/promoteruns an auto-reconcile loop (4 retries over ~22s) after every successful promotion to clear the re-stampedpromotionTokenand re-apply a fast-write sync profile./api/rebuild-replicaexposes the cluster-delete recovery path as a single button on the replica card.
Happy to share the code if useful — it's all in the markjbrown/documentdb-local-to-multicloud demo repo under app/monitor-app/.
Environment
- DocumentDB operator: preview build (hub context: 1 master node, AKS 1.31)
- Member clusters: Azure AKS 1.31 + AWS EKS 1.31, both with CNPG 1.24
- Cross-cloud networking strategy:
serviceLoadBalancer instancesPerNode: 3on both members- DocumentDB CR namespace/name:
documentdb-preview-ns/documentdb-preview
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(monitor-app): cross-cloud monitor with failover gating + rebuild
documentdb-triage-tool commentedon May 9, 2026
🤖 Auto-triaged by documentdb-triage-tool.
Applied:
go,bugProject fields suggested: Component
controllers· PriorityP1· EffortXL· StatusTriageConfidence: 0.82 (llm)
Reasoning
LLM: Rapid multi-cloud failover leaves replicas silently unrecoverable due to WAL timeline divergence with no automated remediation (pg_rewind, serialized promotions, or pg_basebackup re-bootstrap), requiring manual cluster deletion to recover.
If a label is wrong, remove it manually and ping
@patty-chowso the rules can be tuned. The bot will not re-label items that already have component labels.monitor-app: add force-promote-with-local-token recovery action
markjbrown commentedon May 9, 2026
Reproduced in the opposite direction (AWS primary -> Azure replica -> AWS dead)
Just hit this same bug again, mirrored. Posting the second occurrence in case it helps confirm it isn't a one-off.
What happened
demotionToken.unrecoverable(same phaseReason as the original report - "Promotion token content is not correct for current instance" type stuck state).demotionTokenset in status, was waiting for the new primary's WAL on a timeline it could not follow. Both sides therefore stuck. No writes accepted from anywhere.So the failure mode is symmetric: whichever side the operator tries to land as the new primary after a divergence event can end up with a token that does not match its own data, and there is no auto-recovery.
Manual recovery sequence that worked
documentdbCRclusterReplication.primaryto the side that still has the most recent data.spec.replica.promotionTokenwith the value from the localpromotion-tokenConfigMap (data["index.html"]) - i.e. force CNPG to use the cluster's own current checkpoint.Clusteron the other side and let the DocumentDB operator re-bootstrap viapg_basebackup.After step 4, replication is streaming again with sub-100 ms cross-cloud lag and the Fleet/operator stack is consistent.
Suggested operator behavior
The "Promotion token content is not correct for current instance" condition is currently terminal - it requires manual intervention (and quite specific knowledge of the underlying CNPG / Fleet model). It would be very useful if the operator either:
clusterReplication.primary).I have implemented option (a) in the demo monitor app I am building on top of the operator (one button, posts a patch that sets
replica.primary = selfandreplica.promotionToken = <local CM value>); happy to share the code if that helps shape the upstream design.Same repo as before: https://github.com/markjbrown/documentdb-local-to-multicloud (see
app/monitor-app/server.js->/api/force-promote-local-token).monitor-app: auto-heal stale promotion token after promote (workaroun…
[-]Multi-cloud failover: WAL timeline divergence after rapid back-to-back promotions leaves replica unrecoverable[/-][+]Multi-cloud failover: WAL timeline divergence after promotion leaves replica unrecoverable[/+]test: add e2e tests to reproduce issue documentdb#375 (WAL timeline d…
test: disable issue documentdb#375 timeline divergence tests until bu…
fix: clear stale promotionToken after successful failover
test: add e2e tests to reproduce issue documentdb#375 (WAL timeline d…
test: disable issue documentdb#375 timeline divergence tests until bu…
fix: clear stale promotionToken after successful failover