From 85a5327321043b662fe0381af91bc0b8291d103c Mon Sep 17 00:00:00 2001 From: "vignesh@cloudflare.com" Date: Wed, 6 Oct 2021 14:39:01 -0700 Subject: [PATCH] gh-849: To check the cluster replication type based on cluster spec instead of masterdb spec --- cmd/sentinel/cmd/sentinel.go | 3 ++- cmd/sentinel/cmd/sentinel_test.go | 36 +++++++++++++++++-------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/cmd/sentinel/cmd/sentinel.go b/cmd/sentinel/cmd/sentinel.go index 512172e6d..172f78121 100644 --- a/cmd/sentinel/cmd/sentinel.go +++ b/cmd/sentinel/cmd/sentinel.go @@ -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) { diff --git a/cmd/sentinel/cmd/sentinel_test.go b/cmd/sentinel/cmd/sentinel_test.go index 16a988cd4..ff8a458af 100644 --- a/cmd/sentinel/cmd/sentinel_test.go +++ b/cmd/sentinel/cmd/sentinel_test.go @@ -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, @@ -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, @@ -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, @@ -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,