Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion api/v1/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,14 @@ func (p *Postgres) generateDatabaseName() string {
return generatedDatabaseName
}

// ToReadWriteHostsList Force Patroni to add target_session_attrs=read-write by providing a comma separated list (with the same IP...).
// This hopefully prevents cascading replicating by preventing the standby leader pod of the standby cluster to
// connect to a read-only pod in the primary cluster (which would break our sync replication to the standby cluster).
// https://patroni.readthedocs.io/en/latest/standby_cluster.html
func (p *Postgres) ToReadWriteHostsList() string {
return strings.Join([]string{p.Spec.PostgresConnection.ConnectionIP, p.Spec.PostgresConnection.ConnectionIP}, ",")
}

func (p *Postgres) ToPeripheralResourceNamespace() string {
// We only want letters and numbers
projectID := alphaNumericRegExp.ReplaceAllString(p.Spec.ProjectID, "")
Expand Down Expand Up @@ -789,8 +797,9 @@ func (p *Postgres) ToUnstructuredZalandoPostgresql(z *zalando.Postgresql, c *cor
z.Spec.StandbyCluster = nil
} else {
// overwrite connection info
standbyHosts := p.ToReadWriteHostsList()
z.Spec.StandbyCluster = &zalando.StandbyDescription{
StandbyHost: p.Spec.PostgresConnection.ConnectionIP,
StandbyHost: standbyHosts,
StandbyPort: strconv.FormatInt(int64(p.Spec.PostgresConnection.ConnectionPort), 10),
// S3WalPath: "",
}
Expand Down
11 changes: 9 additions & 2 deletions controllers/postgres_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,8 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log
log.V(debugLogLevel).Info("create_replica_methods mismatch, updating and requeing", "response", resp)
return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil)
}
if resp.StandbyCluster.Host != instance.Spec.PostgresConnection.ConnectionIP {

if resp.StandbyCluster.Host != instance.ToReadWriteHostsList() {
log.V(debugLogLevel).Info("host mismatch, updating and requeing", "updating", resp)
return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil)
}
Expand Down Expand Up @@ -1249,10 +1250,16 @@ func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Conte
request.SynchronousNodesAdditional = nil
}
} else {
// Force Patroni to add target_session_attrs=read-write by providing a comma separated list (with the same IP...).
// This hopefully prevents cascading replicating by preventing the standby leader pod of the standby cluster to
// connect to a read-only pod in the primary cluster (which would break our sync replication to the standby cluster).
// https://patroni.readthedocs.io/en/latest/standby_cluster.html
standbyHosts := instance.ToReadWriteHostsList()

request = PatroniConfig{
StandbyCluster: &PatroniStandbyCluster{
CreateReplicaMethods: []string{"basebackup_fast_xlog"},
Host: instance.Spec.PostgresConnection.ConnectionIP,
Host: standbyHosts,
Port: int(instance.Spec.PostgresConnection.ConnectionPort),
ApplicationName: instance.ToPeripheralResourceName(),
},
Expand Down
Loading