reflect review

This commit is contained in:
Felix Kunde 2021-12-10 17:33:26 +01:00
parent 3418be5cf5
commit eede7cf484
4 changed files with 11 additions and 8 deletions

View File

@ -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
}

View File

@ -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"

View File

@ -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

View File

@ -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}]}`