-
Notifications
You must be signed in to change notification settings - Fork 980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: no switchover candidate found with member state "streaming" (#1992) #2515
fix: no switchover candidate found with member state "streaming" (#1992) #2515
Conversation
There is another possible state of a running replica - "in archive recovery" |
bfe2830
to
efc3b1f
Compare
👍 |
continue | ||
} | ||
|
||
if slices.Contains([]string{"running", "streaming", "in archive recovery"}, member.State) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next part of the code sorts candidates by smallest amount of lag. My only concern with merging this change is that it might cause a switchover to a replica lagging behind significantly, as lag is not guaranteed to be 0.
Overall, this is still better than what we have now, though.
postgres-operator/pkg/cluster/pod.go
Lines 511 to 516 in 45489d3
if len(candidates) > 0 { | |
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 | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Patroni will prevent it if this is the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this PR and make a new release for fixing the underlying issue.
@@ -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}]}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to add test cases to capture "in archive recovery" mode, eventually.
👍 |
Fixes #1992