Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move attributes from KeeperSpec to KeeperStatus #19

Merged
merged 2 commits into from
Sep 3, 2019
Merged
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
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
36 changes: 16 additions & 20 deletions cmd/sentinel/cmd/sentinel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4993,13 +4993,12 @@ func TestUpdateCluster(t *testing.T) {
},
},
"keeper2": &cluster.Keeper{
UID: "keeper2",
Spec: &cluster.KeeperSpec{
NeverSynchronousReplica: true,
},
UID: "keeper2",
Spec: &cluster.KeeperSpec{},
Status: cluster.KeeperStatus{
Healthy: true,
LastHealthyTime: now,
Healthy: true,
LastHealthyTime: now,
NeverSynchronousReplica: true,
},
},
},
Expand Down Expand Up @@ -5088,13 +5087,12 @@ func TestUpdateCluster(t *testing.T) {
},
},
"keeper2": &cluster.Keeper{
UID: "keeper2",
Spec: &cluster.KeeperSpec{
NeverSynchronousReplica: true,
},
UID: "keeper2",
Spec: &cluster.KeeperSpec{},
Status: cluster.KeeperStatus{
Healthy: true,
LastHealthyTime: now,
Healthy: true,
LastHealthyTime: now,
NeverSynchronousReplica: true,
},
},
},
Expand Down Expand Up @@ -5189,13 +5187,12 @@ func TestUpdateCluster(t *testing.T) {
},
},
"keeper2": &cluster.Keeper{
UID: "keeper2",
Spec: &cluster.KeeperSpec{
NeverMaster: true,
},
UID: "keeper2",
Spec: &cluster.KeeperSpec{},
Status: cluster.KeeperStatus{
Healthy: true,
LastHealthyTime: now,
NeverMaster: true,
},
},
},
Expand Down Expand Up @@ -5284,13 +5281,12 @@ func TestUpdateCluster(t *testing.T) {
},
},
"keeper2": &cluster.Keeper{
UID: "keeper2",
Spec: &cluster.KeeperSpec{
NeverMaster: true,
},
UID: "keeper2",
Spec: &cluster.KeeperSpec{},
Status: cluster.KeeperStatus{
Healthy: true,
LastHealthyTime: now,
NeverMaster: true,
},
},
},
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