mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-04 04:57:13 +02:00
* fix: no switchover candidate found with member state "streaming" (#1992) * Add test * Also handle "in archive recovery" state
This commit is contained in:
+7
-1
@@ -7,6 +7,8 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -503,7 +505,11 @@ func (c *Cluster) getSwitchoverCandidate(master *v1.Pod) (spec.NamespacedName, e
|
||||
} else {
|
||||
// in asynchronous mode find running replicas
|
||||
for _, member := range members {
|
||||
if PostgresRole(member.Role) != Leader && PostgresRole(member.Role) != StandbyLeader && member.State == "running" {
|
||||
if PostgresRole(member.Role) == Leader || PostgresRole(member.Role) == StandbyLeader {
|
||||
continue
|
||||
}
|
||||
|
||||
if slices.Contains([]string{"running", "streaming", "in archive recovery"}, member.State) {
|
||||
candidates = append(candidates, member)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,13 @@ func TestGetSwitchoverCandidate(t *testing.T) {
|
||||
expectedCandidate: spec.NamespacedName{},
|
||||
expectedError: fmt.Errorf("no switchover candidate found"),
|
||||
},
|
||||
{
|
||||
subtest: "replicas with streaming state",
|
||||
clusterJson: `{"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": "replica", "state": "streaming", "api_url": "http://192.168.100.2:8008/patroni", "host": "192.168.100.2", "port": 5432, "timeline": 1, "lag": 5}, {"name": "acid-test-cluster-2", "role": "replica", "state": "streaming", "api_url": "http://192.168.100.3:8008/patroni", "host": "192.168.100.3", "port": 5432, "timeline": 1, "lag": 2}]}`,
|
||||
syncModeEnabled: false,
|
||||
expectedCandidate: spec.NamespacedName{Namespace: namespace, Name: "acid-test-cluster-2"},
|
||||
expectedError: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user