diff --git a/pkg/cluster/pod.go b/pkg/cluster/pod.go index 84ae9184b89cb253cc8679b5a9dc4f5bebad932d..b5415dc4ec2674042fbb252d0bc562809eff61fd 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].Lag < syncCandidates[j].Lag }) + sort.Slice(syncCandidates, func(i, j int) bool { return syncCandidates[i].LagInMb < syncCandidates[j].LagInMb }) 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].Lag < candidates[j].Lag }) + sort.Slice(candidates, func(i, j int) bool { return candidates[i].LagInMb < candidates[j].LagInMb }) return spec.NamespacedName{Namespace: master.Namespace, Name: candidates[0].Name}, nil } diff --git a/pkg/util/patroni/patroni.go b/pkg/util/patroni/patroni.go index b73c543bdb3fdb6eedf83edb58649808a9f78f94..f030659caef29e5c2d47e97a625635cc78b21cb1 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"` - Lag int `json:"lag"` + LagInMb int `json:"lag"` } // MemberDataPatroni child element diff --git a/pkg/util/patroni/patroni_test.go b/pkg/util/patroni/patroni_test.go index f5b42ddb9d00897951f1880650f44ef3854199e5..48d27c8dc11d115cb3bba7aba0e7d7e31b2eddba 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, - Lag: 0, + LagInMb: 0, }, { Name: "acid-test-cluster-1", Role: "sync_standby", State: "running", Timeline: 1, - Lag: 0, + LagInMb: 0, }, { Name: "acid-test-cluster-2", Role: "replica", State: "running", Timeline: 1, - Lag: 0, + LagInMb: 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}]}`