From eede7cf4841b92d348282a2066cb2239b832cc62 Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Fri, 10 Dec 2021 17:33:26 +0100 Subject: [PATCH] reflect review --- pkg/cluster/pod.go | 4 ++-- pkg/cluster/types.go | 7 +++++-- pkg/util/patroni/patroni.go | 2 +- pkg/util/patroni/patroni_test.go | 6 +++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/cluster/pod.go b/pkg/cluster/pod.go index ef026f6ad..84ae9184b 100644 --- a/pkg/cluster/pod.go +++ b/pkg/cluster/pod.go @@ -514,11 +514,11 @@ func (c *Cluster) getSwitchoverCandidate(master *v1.Pod) (spec.NamespacedName, e // pick candidate with lowest lag // if sync_standby replicas were found assume synchronous_mode is enabled and ignore other candidates list if len(syncCandidates) > 0 { - sort.Slice(syncCandidates, func(i, j int) bool { return syncCandidates[i].LagInMB < syncCandidates[j].LagInMB }) + sort.Slice(syncCandidates, func(i, j int) bool { return syncCandidates[i].Lag < syncCandidates[j].Lag }) return spec.NamespacedName{Namespace: master.Namespace, Name: syncCandidates[0].Name}, nil } if len(candidates) > 0 { - sort.Slice(candidates, func(i, j int) bool { return candidates[i].LagInMB < candidates[j].LagInMB }) + sort.Slice(candidates, func(i, j int) bool { return candidates[i].Lag < candidates[j].Lag }) return spec.NamespacedName{Namespace: master.Namespace, Name: candidates[0].Name}, nil } diff --git a/pkg/cluster/types.go b/pkg/cluster/types.go index 4c9fbb056..67b4ee395 100644 --- a/pkg/cluster/types.go +++ b/pkg/cluster/types.go @@ -14,8 +14,11 @@ import ( type PostgresRole string const ( - Master PostgresRole = "master" - Replica PostgresRole = "replica" + // spilo roles + Master PostgresRole = "master" + Replica PostgresRole = "replica" + + // roles returned by Patroni cluster endpoint Leader PostgresRole = "leader" StandbyLeader PostgresRole = "standby_leader" SyncStandby PostgresRole = "sync_standby" diff --git a/pkg/util/patroni/patroni.go b/pkg/util/patroni/patroni.go index edfaf7897..b73c543bd 100644 --- a/pkg/util/patroni/patroni.go +++ b/pkg/util/patroni/patroni.go @@ -188,7 +188,7 @@ type ClusterMember struct { Role string `json:"role"` State string `json:"state"` Timeline int `json:"timeline"` - LagInMB int `json:"lag"` + Lag int `json:"lag"` } // MemberDataPatroni child element diff --git a/pkg/util/patroni/patroni_test.go b/pkg/util/patroni/patroni_test.go index 62729c1c5..f5b42ddb9 100644 --- a/pkg/util/patroni/patroni_test.go +++ b/pkg/util/patroni/patroni_test.go @@ -95,19 +95,19 @@ func TestGetClusterMembers(t *testing.T) { Role: "leader", State: "running", Timeline: 1, - LagInMB: 0, + Lag: 0, }, { Name: "acid-test-cluster-1", Role: "sync_standby", State: "running", Timeline: 1, - LagInMB: 0, + Lag: 0, }, { Name: "acid-test-cluster-2", Role: "replica", State: "running", Timeline: 1, - LagInMB: 0, + Lag: 0, }} json := `{"members": [{"name": "acid-test-cluster-0", "role": "leader", "state": "running", "api_url": "http://192.168.100.1:8008/patroni", "host": "192.168.100.1", "port": 5432, "timeline": 1}, {"name": "acid-test-cluster-1", "role": "sync_standby", "state": "running", "api_url": "http://192.168.100.2:8008/patroni", "host": "192.168.100.2", "port": 5432, "timeline": 1, "lag": 0}, {"name": "acid-test-cluster-2", "role": "replica", "state": "running", "api_url": "http://192.168.100.3:8008/patroni", "host": "192.168.100.3", "port": 5432, "timeline": 1, "lag": 0}]}`