Skip to content

Commit

Permalink
Move attributes from KeeperSpec to KeeperStatus
Browse files Browse the repository at this point in the history
KeeperStatus is the up-to-date information about the keeper state.
Since inside the keeper (using a per keeper cli option) we're
specifying a specific keeper "property" and reporting this via the
KeeperInfo.

Then update KeeperStatus so the sentinel will use this new fields to
compute the final cluster state.
  • Loading branch information
rnaveiras committed Sep 3, 2019
1 parent 4a59460 commit 1416835
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion cmd/keeper/cmd/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,10 @@ func (p *PostgresKeeper) updateKeeperInfo() error {
Min: min,
},

PostgresState: p.getLastPGState(),

NeverMaster: p.neverMaster,
NeverSynchronousReplica: p.neverSynchronousReplica,
PostgresState: p.getLastPGState(),
}

// The time to live is just to automatically remove old entries, it's
Expand Down
14 changes: 7 additions & 7 deletions cmd/sentinel/cmd/sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ func (s *Sentinel) updateKeepersStatus(cd *cluster.ClusterData, keepersInfo clus
}
}

// Keepers support several command line arguments that should be populated in the
// KeeperSpec by the sentinel. This allows us to make decisions about how to arrange
// the cluster that take into consideration the configuration of each keeper.
// Keepers support several command line arguments that should be populated in the
// KeeperStatus by the sentinel. This allows us to make decisions about how to arrange
// the cluster that take into consideration the configuration of each keeper.
for keeperUID, k := range cd.Keepers {
if ki, ok := keepersInfo[keeperUID]; ok {
k.Spec.NeverMaster = ki.NeverMaster
k.Spec.NeverSynchronousReplica = ki.NeverSynchronousReplica
k.Status.NeverMaster = ki.NeverMaster
k.Status.NeverSynchronousReplica = ki.NeverSynchronousReplica
}
}

Expand Down Expand Up @@ -741,7 +741,7 @@ func (s *Sentinel) findBestStandbys(cd *cluster.ClusterData, masterDB *cluster.D
func (s *Sentinel) findBestNewMasters(cd *cluster.ClusterData, masterDB *cluster.DB) []*cluster.DB {
bestNewMasters := []*cluster.DB{}
for _, db := range s.findBestStandbys(cd, masterDB) {
if k, ok := cd.Keepers[db.Spec.KeeperUID]; ok && k.Spec.NeverMaster {
if k, ok := cd.Keepers[db.Spec.KeeperUID]; ok && k.Status.NeverMaster {
log.Infow("ignoring keeper since it cannot be master (--never-master)", "db", db.UID, "keeper", db.Spec.KeeperUID)
continue
}
Expand Down Expand Up @@ -1344,7 +1344,7 @@ func (s *Sentinel) updateCluster(cd *cluster.ClusterData, pis cluster.ProxiesInf

// ignore standbys that cannot be synchronous standbys
if db, ok := newcd.DBs[bestStandby.UID]; ok {
if keeper, ok := newcd.Keepers[db.Spec.KeeperUID]; ok && keeper.Spec.NeverSynchronousReplica {
if keeper, ok := newcd.Keepers[db.Spec.KeeperUID]; ok && keeper.Status.NeverSynchronousReplica {
log.Infow("cannot choose standby as synchronous (--never-synchronous-replica)", "db", db.UID, "keeper", keeper.UID)
continue
}
Expand Down
8 changes: 4 additions & 4 deletions internal/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,7 @@ func NewCluster(uid string, cs *ClusterSpec) *Cluster {
return c
}

type KeeperSpec struct {
NeverMaster bool `json:"neverMaster,omitempty"`
NeverSynchronousReplica bool `json:"neverSynchronousReplica,omitempty"`
}
type KeeperSpec struct{}

type KeeperStatus struct {
Healthy bool `json:"healthy,omitempty"`
Expand All @@ -563,6 +560,9 @@ type KeeperStatus struct {
PostgresBinaryVersion PostgresBinaryVersion `json:"postgresBinaryVersion,omitempty"`

ForceFail bool `json:"forceFail,omitempty"`

NeverMaster bool `json:"neverMaster,omitempty"`
NeverSynchronousReplica bool `json:"neverSynchronousReplica,omitempty"`
}

type Keeper struct {
Expand Down

0 comments on commit 1416835

Please sign in to comment.