Skip to content

Commit

Permalink
gh-849: To check the cluster replication type based on cluster spec i…
Browse files Browse the repository at this point in the history
…nstead of masterdb spec
  • Loading branch information
viggy1228 committed Oct 7, 2021
1 parent fc23394 commit 85a5327
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion cmd/sentinel/cmd/sentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,10 +1010,11 @@ func (s *Sentinel) updateCluster(cd *cluster.ClusterData, pis cluster.ProxiesInf
} else {
// if synchronous replication is enabled, only choose new master in the synchronous replication standbys.
var bestNewMasterDB *cluster.DB
if curMasterDB.Spec.SynchronousReplication {
if *cd.Cluster.Spec.SynchronousReplication {
commonSyncStandbys := util.CommonElements(curMasterDB.Status.SynchronousStandbys, curMasterDB.Spec.SynchronousStandbys)
if len(commonSyncStandbys) == 0 {
log.Warnw("cannot choose synchronous standby since there are no common elements between the latest master reported synchronous standbys and the db spec ones", "reported", curMasterDB.Status.SynchronousStandbys, "spec", curMasterDB.Spec.SynchronousStandbys)
bestNewMasterDB = bestNewMasters[0]
} else {
for _, nm := range bestNewMasters {
if util.StringInSlice(commonSyncStandbys, nm.UID) {
Expand Down
36 changes: 20 additions & 16 deletions cmd/sentinel/cmd/sentinel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,11 @@ func TestUpdateCluster(t *testing.T) {
UID: "cluster1",
Generation: 1,
Spec: &cluster.ClusterSpec{
ConvergenceTimeout: &cluster.Duration{Duration: cluster.DefaultConvergenceTimeout},
InitTimeout: &cluster.Duration{Duration: cluster.DefaultInitTimeout},
SyncTimeout: &cluster.Duration{Duration: cluster.DefaultSyncTimeout},
MaxStandbysPerSender: cluster.Uint16P(cluster.DefaultMaxStandbysPerSender),
ConvergenceTimeout: &cluster.Duration{Duration: cluster.DefaultConvergenceTimeout},
InitTimeout: &cluster.Duration{Duration: cluster.DefaultInitTimeout},
SyncTimeout: &cluster.Duration{Duration: cluster.DefaultSyncTimeout},
MaxStandbysPerSender: cluster.Uint16P(cluster.DefaultMaxStandbysPerSender),
SynchronousReplication: cluster.BoolP(false),
},
Status: cluster.ClusterStatus{
CurrentGeneration: 1,
Expand Down Expand Up @@ -685,10 +686,11 @@ func TestUpdateCluster(t *testing.T) {
UID: "cluster1",
Generation: 1,
Spec: &cluster.ClusterSpec{
ConvergenceTimeout: &cluster.Duration{Duration: cluster.DefaultConvergenceTimeout},
InitTimeout: &cluster.Duration{Duration: cluster.DefaultInitTimeout},
SyncTimeout: &cluster.Duration{Duration: cluster.DefaultSyncTimeout},
MaxStandbysPerSender: cluster.Uint16P(cluster.DefaultMaxStandbysPerSender),
ConvergenceTimeout: &cluster.Duration{Duration: cluster.DefaultConvergenceTimeout},
InitTimeout: &cluster.Duration{Duration: cluster.DefaultInitTimeout},
SyncTimeout: &cluster.Duration{Duration: cluster.DefaultSyncTimeout},
MaxStandbysPerSender: cluster.Uint16P(cluster.DefaultMaxStandbysPerSender),
SynchronousReplication: cluster.BoolP(false),
},
Status: cluster.ClusterStatus{
CurrentGeneration: 1,
Expand Down Expand Up @@ -1127,10 +1129,11 @@ func TestUpdateCluster(t *testing.T) {
UID: "cluster1",
Generation: 1,
Spec: &cluster.ClusterSpec{
ConvergenceTimeout: &cluster.Duration{Duration: cluster.DefaultConvergenceTimeout},
InitTimeout: &cluster.Duration{Duration: cluster.DefaultInitTimeout},
SyncTimeout: &cluster.Duration{Duration: cluster.DefaultSyncTimeout},
MaxStandbysPerSender: cluster.Uint16P(cluster.DefaultMaxStandbysPerSender),
ConvergenceTimeout: &cluster.Duration{Duration: cluster.DefaultConvergenceTimeout},
InitTimeout: &cluster.Duration{Duration: cluster.DefaultInitTimeout},
SyncTimeout: &cluster.Duration{Duration: cluster.DefaultSyncTimeout},
MaxStandbysPerSender: cluster.Uint16P(cluster.DefaultMaxStandbysPerSender),
SynchronousReplication: cluster.BoolP(false),
},
Status: cluster.ClusterStatus{
CurrentGeneration: 1,
Expand Down Expand Up @@ -1215,10 +1218,11 @@ func TestUpdateCluster(t *testing.T) {
UID: "cluster1",
Generation: 1,
Spec: &cluster.ClusterSpec{
ConvergenceTimeout: &cluster.Duration{Duration: cluster.DefaultConvergenceTimeout},
InitTimeout: &cluster.Duration{Duration: cluster.DefaultInitTimeout},
SyncTimeout: &cluster.Duration{Duration: cluster.DefaultSyncTimeout},
MaxStandbysPerSender: cluster.Uint16P(cluster.DefaultMaxStandbysPerSender),
ConvergenceTimeout: &cluster.Duration{Duration: cluster.DefaultConvergenceTimeout},
InitTimeout: &cluster.Duration{Duration: cluster.DefaultInitTimeout},
SyncTimeout: &cluster.Duration{Duration: cluster.DefaultSyncTimeout},
MaxStandbysPerSender: cluster.Uint16P(cluster.DefaultMaxStandbysPerSender),
SynchronousReplication: cluster.BoolP(false),
},
Status: cluster.ClusterStatus{
CurrentGeneration: 1,
Expand Down

0 comments on commit 85a5327

Please sign in to comment.