Skip to content

Commit b236b1d

Browse files
committed
Add comma-separated list to dynamic config as well
1 parent fcdb208 commit b236b1d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

controllers/postgres_controller.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,14 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log
11371137
log.V(debugLogLevel).Info("create_replica_methods mismatch, updating and requeing", "response", resp)
11381138
return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil)
11391139
}
1140-
if resp.StandbyCluster.Host != instance.Spec.PostgresConnection.ConnectionIP {
1140+
1141+
// Force Patroni to add target_session_attrs=read-write by providing a comma separated list (with the same IP...).
1142+
// This hopefully prevents cascading replicating by preventing the standby leader pod of the standby cluster to
1143+
// connect to a read-only pod in the primary cluster (which would break our sync replication to the standby cluster).
1144+
// https://patroni.readthedocs.io/en/latest/standby_cluster.html
1145+
standbyHosts := strings.Join([]string{instance.Spec.PostgresConnection.ConnectionIP, instance.Spec.PostgresConnection.ConnectionIP}, ",")
1146+
1147+
if resp.StandbyCluster.Host != standbyHosts {
11411148
log.V(debugLogLevel).Info("host mismatch, updating and requeing", "updating", resp)
11421149
return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil)
11431150
}
@@ -1249,10 +1256,16 @@ func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Conte
12491256
request.SynchronousNodesAdditional = nil
12501257
}
12511258
} else {
1259+
// Force Patroni to add target_session_attrs=read-write by providing a comma separated list (with the same IP...).
1260+
// This hopefully prevents cascading replicating by preventing the standby leader pod of the standby cluster to
1261+
// connect to a read-only pod in the primary cluster (which would break our sync replication to the standby cluster).
1262+
// https://patroni.readthedocs.io/en/latest/standby_cluster.html
1263+
standbyHosts := strings.Join([]string{instance.Spec.PostgresConnection.ConnectionIP, instance.Spec.PostgresConnection.ConnectionIP}, ",")
1264+
12521265
request = PatroniConfig{
12531266
StandbyCluster: &PatroniStandbyCluster{
12541267
CreateReplicaMethods: []string{"basebackup_fast_xlog"},
1255-
Host: instance.Spec.PostgresConnection.ConnectionIP,
1268+
Host: standbyHosts,
12561269
Port: int(instance.Spec.PostgresConnection.ConnectionPort),
12571270
ApplicationName: instance.ToPeripheralResourceName(),
12581271
},

0 commit comments

Comments
 (0)