Skip to content

Commit

Permalink
sentinel: fix check for same reported vs spec sync standbys
Browse files Browse the repository at this point in the history
When electing a new master we are swapping the new master uid with the old
master uid in the syncstandbys slice. This could end with an unordered slice in
the spec that will make the sentinel fail the check that the reported standbys
are the same of the spec one blocking any future syncstandby update.

Since the reported order is not a problem just check that the syncstandbys are
the same regardless of their order.

We'll keep the sorting to avoid unneeded updates to synchronous_standby_names by
the keeper.
  • Loading branch information
sgotti committed May 29, 2018
1 parent 1454745 commit be61e2c
Show file tree
Hide file tree
Showing 4 changed files with 427 additions and 14 deletions.
13 changes: 8 additions & 5 deletions cmd/sentinel/cmd/sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ func (s *Sentinel) updateKeepersStatus(cd *cluster.ClusterData, keepersInfo clus
db.Status.TimelinesHistory = dbs.TimelinesHistory
db.Status.PGParameters = cluster.PGParameters(dbs.PGParameters)

// Sort synchronousStandbys so we can compare the slice regardless of its order
sort.Sort(sort.StringSlice(dbs.SynchronousStandbys))
db.Status.SynchronousStandbys = dbs.SynchronousStandbys

db.Status.OlderWalFile = dbs.OlderWalFile
Expand Down Expand Up @@ -1074,6 +1072,11 @@ func (s *Sentinel) updateCluster(cd *cluster.ClusterData, pis cluster.ProxiesInf
if len(newMasterDB.Spec.SynchronousStandbys) == 0 {
newMasterDB.Spec.ExternalSynchronousStandbys = []string{fakeStandbyName}
}

// Just sort to always have them in the same order and avoid
// unneeded updates to synchronous_standby_names by the keeper.
sort.Sort(sort.StringSlice(newMasterDB.Spec.SynchronousStandbys))
sort.Sort(sort.StringSlice(newMasterDB.Spec.ExternalSynchronousStandbys))
} else {
newMasterDB.Spec.SynchronousReplication = false
newMasterDB.Spec.SynchronousStandbys = nil
Expand Down Expand Up @@ -1189,7 +1192,7 @@ func (s *Sentinel) updateCluster(cd *cluster.ClusterData, pis cluster.ProxiesInf
// this way, when we have to choose a new master we are sure
// that there're no intermediate changes between the
// reported standbys and the required ones.
if !util.CompareStringSlice(masterDB.Status.SynchronousStandbys, masterDB.Spec.SynchronousStandbys) {
if !util.CompareStringSliceNoOrder(masterDB.Status.SynchronousStandbys, masterDB.Spec.SynchronousStandbys) {
log.Infof("won't update masterDB required synchronous standby since the latest master reported synchronous standbys are different from the db spec ones", "reported", curMasterDB.Status.SynchronousStandbys, "spec", curMasterDB.Spec.SynchronousStandbys)
} else {
addFakeStandby := false
Expand Down Expand Up @@ -1338,10 +1341,10 @@ func (s *Sentinel) updateCluster(cd *cluster.ClusterData, pis cluster.ProxiesInf
masterDB.Spec.ExternalSynchronousStandbys = append(masterDB.Spec.ExternalSynchronousStandbys, fakeStandbyName)
}

// Sort synchronousStandbys so we can compare the slice regardless of its order
// Just sort to always have them in the same order and avoid
// unneeded updates to synchronous_standby_names by the keeper.
sort.Sort(sort.StringSlice(masterDB.Spec.SynchronousStandbys))
sort.Sort(sort.StringSlice(masterDB.Spec.ExternalSynchronousStandbys))

}
} else {
masterDB.Spec.SynchronousReplication = false
Expand Down
Loading

0 comments on commit be61e2c

Please sign in to comment.