improve pooler sync

This commit is contained in:
Felix Kunde 2021-08-25 11:50:09 +02:00
parent 1b3366e9f4
commit 79ab7d3216
1 changed files with 10 additions and 17 deletions

View File

@ -60,7 +60,7 @@ func needMasterConnectionPooler(spec *acidv1.PostgresSpec) bool {
} }
func needMasterConnectionPoolerWorker(spec *acidv1.PostgresSpec) bool { func needMasterConnectionPoolerWorker(spec *acidv1.PostgresSpec) bool {
return (nil != spec.EnableConnectionPooler && *spec.EnableConnectionPooler) || return (spec.EnableConnectionPooler != nil && *spec.EnableConnectionPooler) ||
(spec.ConnectionPooler != nil && spec.EnableConnectionPooler == nil) (spec.ConnectionPooler != nil && spec.EnableConnectionPooler == nil)
} }
@ -691,8 +691,7 @@ func (c *Cluster) syncConnectionPooler(oldSpec, newSpec *acidv1.Postgresql, Look
var reason SyncReason var reason SyncReason
var err error var err error
var newNeedConnectionPooler, oldNeedConnectionPooler bool var connectionPoolerNeeded bool
oldNeedConnectionPooler = false
if oldSpec == nil { if oldSpec == nil {
oldSpec = &acidv1.Postgresql{ oldSpec = &acidv1.Postgresql{
@ -731,15 +730,9 @@ func (c *Cluster) syncConnectionPooler(oldSpec, newSpec *acidv1.Postgresql, Look
for _, role := range [2]PostgresRole{Master, Replica} { for _, role := range [2]PostgresRole{Master, Replica} {
if role == Master { if role == Master {
newNeedConnectionPooler = needMasterConnectionPoolerWorker(&newSpec.Spec) connectionPoolerNeeded = needMasterConnectionPoolerWorker(&newSpec.Spec)
if oldSpec != nil {
oldNeedConnectionPooler = needMasterConnectionPoolerWorker(&oldSpec.Spec)
}
} else { } else {
newNeedConnectionPooler = needReplicaConnectionPoolerWorker(&newSpec.Spec) connectionPoolerNeeded = needReplicaConnectionPoolerWorker(&newSpec.Spec)
if oldSpec != nil {
oldNeedConnectionPooler = needReplicaConnectionPoolerWorker(&oldSpec.Spec)
}
} }
// if the call is via createConnectionPooler, then it is required to initialize // if the call is via createConnectionPooler, then it is required to initialize
@ -759,16 +752,16 @@ func (c *Cluster) syncConnectionPooler(oldSpec, newSpec *acidv1.Postgresql, Look
} }
} }
if newNeedConnectionPooler { if connectionPoolerNeeded {
// Try to sync in any case. If we didn't needed connection pooler before, // Try to sync in any case. If we didn't needed connection pooler before,
// it means we want to create it. If it was already present, still sync // it means we want to create it. If it was already present, still sync
// since it could happen that there is no difference in specs, and all // since it could happen that there is no difference in specs, and all
// the resources are remembered, but the deployment was manually deleted // the resources are remembered, but the deployment was manually deleted
// in between // in between
// in this case also do not forget to install lookup function as for // in this case also do not forget to install lookup function
// creating cluster // new databases could have been created that need the pooler schema
if !oldNeedConnectionPooler || !c.ConnectionPooler[role].LookupFunction { if !c.ConnectionPooler[role].LookupFunction {
newConnectionPooler := newSpec.Spec.ConnectionPooler newConnectionPooler := newSpec.Spec.ConnectionPooler
specSchema := "" specSchema := ""
@ -808,8 +801,8 @@ func (c *Cluster) syncConnectionPooler(oldSpec, newSpec *acidv1.Postgresql, Look
} }
} }
} }
if !needMasterConnectionPoolerWorker(&newSpec.Spec) && if (needMasterConnectionPoolerWorker(&oldSpec.Spec) || needReplicaConnectionPoolerWorker(&oldSpec.Spec)) &&
!needReplicaConnectionPoolerWorker(&newSpec.Spec) { !needMasterConnectionPoolerWorker(&newSpec.Spec) && !needReplicaConnectionPoolerWorker(&newSpec.Spec) {
if err = c.deleteConnectionPoolerSecret(); err != nil { if err = c.deleteConnectionPoolerSecret(); err != nil {
c.logger.Warningf("could not remove connection pooler secret: %v", err) c.logger.Warningf("could not remove connection pooler secret: %v", err)
} }