reflect review
This commit is contained in:
		
							parent
							
								
									3418be5cf5
								
							
						
					
					
						commit
						eede7cf484
					
				| 
						 | 
					@ -514,11 +514,11 @@ func (c *Cluster) getSwitchoverCandidate(master *v1.Pod) (spec.NamespacedName, e
 | 
				
			||||||
	// pick candidate with lowest lag
 | 
						// pick candidate with lowest lag
 | 
				
			||||||
	// if sync_standby replicas were found assume synchronous_mode is enabled and ignore other candidates list
 | 
						// if sync_standby replicas were found assume synchronous_mode is enabled and ignore other candidates list
 | 
				
			||||||
	if len(syncCandidates) > 0 {
 | 
						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
 | 
							return spec.NamespacedName{Namespace: master.Namespace, Name: syncCandidates[0].Name}, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if len(candidates) > 0 {
 | 
						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
 | 
							return spec.NamespacedName{Namespace: master.Namespace, Name: candidates[0].Name}, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,8 +14,11 @@ import (
 | 
				
			||||||
type PostgresRole string
 | 
					type PostgresRole string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
 | 
						// spilo roles
 | 
				
			||||||
	Master  PostgresRole = "master"
 | 
						Master  PostgresRole = "master"
 | 
				
			||||||
	Replica PostgresRole = "replica"
 | 
						Replica PostgresRole = "replica"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// roles returned by Patroni cluster endpoint
 | 
				
			||||||
	Leader        PostgresRole = "leader"
 | 
						Leader        PostgresRole = "leader"
 | 
				
			||||||
	StandbyLeader PostgresRole = "standby_leader"
 | 
						StandbyLeader PostgresRole = "standby_leader"
 | 
				
			||||||
	SyncStandby   PostgresRole = "sync_standby"
 | 
						SyncStandby   PostgresRole = "sync_standby"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -188,7 +188,7 @@ type ClusterMember struct {
 | 
				
			||||||
	Role     string `json:"role"`
 | 
						Role     string `json:"role"`
 | 
				
			||||||
	State    string `json:"state"`
 | 
						State    string `json:"state"`
 | 
				
			||||||
	Timeline int    `json:"timeline"`
 | 
						Timeline int    `json:"timeline"`
 | 
				
			||||||
	LagInMB  int    `json:"lag"`
 | 
						Lag      int    `json:"lag"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// MemberDataPatroni child element
 | 
					// MemberDataPatroni child element
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -95,19 +95,19 @@ func TestGetClusterMembers(t *testing.T) {
 | 
				
			||||||
			Role:     "leader",
 | 
								Role:     "leader",
 | 
				
			||||||
			State:    "running",
 | 
								State:    "running",
 | 
				
			||||||
			Timeline: 1,
 | 
								Timeline: 1,
 | 
				
			||||||
			LagInMB:  0,
 | 
								Lag:      0,
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			Name:     "acid-test-cluster-1",
 | 
								Name:     "acid-test-cluster-1",
 | 
				
			||||||
			Role:     "sync_standby",
 | 
								Role:     "sync_standby",
 | 
				
			||||||
			State:    "running",
 | 
								State:    "running",
 | 
				
			||||||
			Timeline: 1,
 | 
								Timeline: 1,
 | 
				
			||||||
			LagInMB:  0,
 | 
								Lag:      0,
 | 
				
			||||||
		}, {
 | 
							}, {
 | 
				
			||||||
			Name:     "acid-test-cluster-2",
 | 
								Name:     "acid-test-cluster-2",
 | 
				
			||||||
			Role:     "replica",
 | 
								Role:     "replica",
 | 
				
			||||||
			State:    "running",
 | 
								State:    "running",
 | 
				
			||||||
			Timeline: 1,
 | 
								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}]}`
 | 
						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}]}`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue