Repository navigation
fix: Mark replicas unhealthy on stalled WAL replay error loops - #11135
ardentperf wants to merge 2 commits into
Conversation
Detect replicas stuck in repeated unrecoverable WAL replay errors and marks the instance unhealthy using existing CNPG health paths. Adds an instance `statusError` field and adds a log monitor path for CSV log records that detects unrecoverable WAL replay loops. Signed-off-by: Jeremy Schneider <[email protected]>
|
❗ By default, the pull request is configured to backport to all release branches.
|
to support multiple detectors, base this on a multirecordwriter now. this is a better direction than chaining writers. Signed-off-by: Jeremy Schneider <[email protected]>
Signed copy of cloudnative-pg#11135, used as a prerequisite for the startup-probe WAL replay progress detector. Signed-off-by: ardentperf-agent[bot] <265149240+ardentperf-agent[bot]@users.noreply.github.com>
|
The PR looks good to me, and I like the same-LSN repetition idea: from 1. I think the detector should also check where the message comes 2. Have you considered clearing 3. I'm a bit worried about the fencing interaction. The early Two smaller things:
The MultiRecordWriter change looks good to me. |
|
thanks for the review and feedback
good catch on pg_walinspect. i think responding to an explicit
i agree this makes sense. i think that resetting the state with in-place postmaster restarts will be intuitive for users.
random comment: i hadn't fully thought through the interaction with fencing after the instance gets into an unrecoverable state. this is helpful. i think the error should be left in place when an instance is fenced; i haven't traced all the code yet but i'm thinking masked errors might still be visible? but i do think it would make sense to clear the error on un-fencing, if that won't already happen. if instances can be un-fenced without any in-place postmaster restart the it might be worth an extra line of code to do this explicitly.
actually i dont think this is the right tradeoff - but i think this should be a separate PR. IMO we should think more broadly about "how should reconciliation work with pods that aren't ready"
i originally had LSN in the message, during an early draft, and removed it from the message bc that seemed a little more consistent with other messages to me :) happy to add it back in, that works for me i'll work on a new revision of this patch. thanks again for reviewing!! |
|
nb. i will also address linter feedback in the PR |
…11152) When a PostgreSQL instance has to replay a large amount of WAL before reaching consistency (for example a standby restarting after a crash, as reported in #11024), `pg_isready` reports that the server is alive but rejecting connections until recovery completes. The startup probe treated that state as a failure, so when recovery outlasted `startDelay` the kubelet killed the pod. Every restart threw away the replay progress and the instance could never catch up, looping forever. With the default `pg_isready` strategy, the startup probe now considers a server that is alive but rejecting connections as already started up: - The liveness probe will not restart it, because it returns OK unconditionally for a non-primary instance. - The readiness probe keeps failing on a server that rejects connections, so a recovering instance stays out of the ready endpoints of the services and is not eligible for promotion until it accepts connections. The `query` and `streaming` startup strategies are unchanged: they require PostgreSQL to accept connections by design, and the documentation now points out that `startDelay` must account for recovery time when using them. One trade-off worth noting: the startup probe was previously the only mechanism that restarted a pod whose PostgreSQL was permanently stuck while rejecting connections, even though in the #11024 scenario those restarts were exactly what prevented recovery from completing. With this change such an instance is reported as started and left to continue attempting recovery, with no automatic restart if it never completes. A specific form of this, repeated WAL-replay error loops, is proposed in #11135, which does not cover a replica silently stalled with no matching errors. This was verified on a kind cluster by reproducing the scenario from the issue: a two-instance cluster with `startDelay: 10`, one-second probe periods, and `checkpoint_timeout: 5h` so that the standby takes no restartpoints. After writing about 4.7GiB of WAL and deleting the standby pod, the instance came back in `shut down in recovery`, the first startup probe reported it as started, the pod stayed not ready while replaying (readiness failing with HTTP 500), and it became ready about 40 seconds later with zero container restarts. The same configuration on the previous build restarted the pod every 10 seconds. Unit tests cover the new startup checker and the probe runner selection, which previously had no coverage. Thanks to Jeremy Schneider for reporting this issue and providing a detailed analysis of the failure. Closes #11024 Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> Co-authored-by: Jeremy Schneider <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]>
…11152) When a PostgreSQL instance has to replay a large amount of WAL before reaching consistency (for example a standby restarting after a crash, as reported in #11024), `pg_isready` reports that the server is alive but rejecting connections until recovery completes. The startup probe treated that state as a failure, so when recovery outlasted `startDelay` the kubelet killed the pod. Every restart threw away the replay progress and the instance could never catch up, looping forever. With the default `pg_isready` strategy, the startup probe now considers a server that is alive but rejecting connections as already started up: - The liveness probe will not restart it, because it returns OK unconditionally for a non-primary instance. - The readiness probe keeps failing on a server that rejects connections, so a recovering instance stays out of the ready endpoints of the services and is not eligible for promotion until it accepts connections. The `query` and `streaming` startup strategies are unchanged: they require PostgreSQL to accept connections by design, and the documentation now points out that `startDelay` must account for recovery time when using them. One trade-off worth noting: the startup probe was previously the only mechanism that restarted a pod whose PostgreSQL was permanently stuck while rejecting connections, even though in the #11024 scenario those restarts were exactly what prevented recovery from completing. With this change such an instance is reported as started and left to continue attempting recovery, with no automatic restart if it never completes. A specific form of this, repeated WAL-replay error loops, is proposed in #11135, which does not cover a replica silently stalled with no matching errors. This was verified on a kind cluster by reproducing the scenario from the issue: a two-instance cluster with `startDelay: 10`, one-second probe periods, and `checkpoint_timeout: 5h` so that the standby takes no restartpoints. After writing about 4.7GiB of WAL and deleting the standby pod, the instance came back in `shut down in recovery`, the first startup probe reported it as started, the pod stayed not ready while replaying (readiness failing with HTTP 500), and it became ready about 40 seconds later with zero container restarts. The same configuration on the previous build restarted the pod every 10 seconds. Unit tests cover the new startup checker and the probe runner selection, which previously had no coverage. Thanks to Jeremy Schneider for reporting this issue and providing a detailed analysis of the failure. Closes #11024 Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> Co-authored-by: Jeremy Schneider <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]> (cherry picked from commit 268dcfd)
…11152) When a PostgreSQL instance has to replay a large amount of WAL before reaching consistency (for example a standby restarting after a crash, as reported in #11024), `pg_isready` reports that the server is alive but rejecting connections until recovery completes. The startup probe treated that state as a failure, so when recovery outlasted `startDelay` the kubelet killed the pod. Every restart threw away the replay progress and the instance could never catch up, looping forever. With the default `pg_isready` strategy, the startup probe now considers a server that is alive but rejecting connections as already started up: - The liveness probe will not restart it, because it returns OK unconditionally for a non-primary instance. - The readiness probe keeps failing on a server that rejects connections, so a recovering instance stays out of the ready endpoints of the services and is not eligible for promotion until it accepts connections. The `query` and `streaming` startup strategies are unchanged: they require PostgreSQL to accept connections by design, and the documentation now points out that `startDelay` must account for recovery time when using them. One trade-off worth noting: the startup probe was previously the only mechanism that restarted a pod whose PostgreSQL was permanently stuck while rejecting connections, even though in the #11024 scenario those restarts were exactly what prevented recovery from completing. With this change such an instance is reported as started and left to continue attempting recovery, with no automatic restart if it never completes. A specific form of this, repeated WAL-replay error loops, is proposed in #11135, which does not cover a replica silently stalled with no matching errors. This was verified on a kind cluster by reproducing the scenario from the issue: a two-instance cluster with `startDelay: 10`, one-second probe periods, and `checkpoint_timeout: 5h` so that the standby takes no restartpoints. After writing about 4.7GiB of WAL and deleting the standby pod, the instance came back in `shut down in recovery`, the first startup probe reported it as started, the pod stayed not ready while replaying (readiness failing with HTTP 500), and it became ready about 40 seconds later with zero container restarts. The same configuration on the previous build restarted the pod every 10 seconds. Unit tests cover the new startup checker and the probe runner selection, which previously had no coverage. Thanks to Jeremy Schneider for reporting this issue and providing a detailed analysis of the failure. Closes #11024 Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> Co-authored-by: Jeremy Schneider <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]> (cherry picked from commit 268dcfd)
…11152) When a PostgreSQL instance has to replay a large amount of WAL before reaching consistency (for example a standby restarting after a crash, as reported in #11024), `pg_isready` reports that the server is alive but rejecting connections until recovery completes. The startup probe treated that state as a failure, so when recovery outlasted `startDelay` the kubelet killed the pod. Every restart threw away the replay progress and the instance could never catch up, looping forever. With the default `pg_isready` strategy, the startup probe now considers a server that is alive but rejecting connections as already started up: - The liveness probe will not restart it, because it returns OK unconditionally for a non-primary instance. - The readiness probe keeps failing on a server that rejects connections, so a recovering instance stays out of the ready endpoints of the services and is not eligible for promotion until it accepts connections. The `query` and `streaming` startup strategies are unchanged: they require PostgreSQL to accept connections by design, and the documentation now points out that `startDelay` must account for recovery time when using them. One trade-off worth noting: the startup probe was previously the only mechanism that restarted a pod whose PostgreSQL was permanently stuck while rejecting connections, even though in the #11024 scenario those restarts were exactly what prevented recovery from completing. With this change such an instance is reported as started and left to continue attempting recovery, with no automatic restart if it never completes. A specific form of this, repeated WAL-replay error loops, is proposed in #11135, which does not cover a replica silently stalled with no matching errors. This was verified on a kind cluster by reproducing the scenario from the issue: a two-instance cluster with `startDelay: 10`, one-second probe periods, and `checkpoint_timeout: 5h` so that the standby takes no restartpoints. After writing about 4.7GiB of WAL and deleting the standby pod, the instance came back in `shut down in recovery`, the first startup probe reported it as started, the pod stayed not ready while replaying (readiness failing with HTTP 500), and it became ready about 40 seconds later with zero container restarts. The same configuration on the previous build restarted the pod every 10 seconds. Unit tests cover the new startup checker and the probe runner selection, which previously had no coverage. Thanks to Jeremy Schneider for reporting this issue and providing a detailed analysis of the failure. Closes #11024 Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> Co-authored-by: Jeremy Schneider <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]> (cherry picked from commit 268dcfd)
This change detects replicas stuck in repeated unrecoverable WAL replay errors and marks the instance unhealthy using existing CNPG health paths.
Reproducer: https://github.com/ardentperf/bug-repro-wal-restore
important: if someone went into a pod and manually executed pg_rewind to recover, current PR design would still require a pod restart to clear the flag allowing CNPG to mark it healthy
The patch intentionally avoids automatic remediation. It does not delete pods, recreate PVCs, fence instances, or mark the Cluster unrecoverable. It only makes the broken replica stop looking healthy.
Main changes:
statusErrorfield.GetStatus()and therefore/pg/statusto fail./pg/statuscall as a status collection error.LogPipenow accepts aRecordWriter, and a newMultiRecordWriterfans each parsed log record out to every configuredRecordWriter.MultiRecordWriterholding the WAL replay detector alongside the normal log writer, so multiple independent detectors can observe records without chaining.MultiRecordWriter).canCheckReadiness=falseand sets the instance status error.Behavior after detection:
/pg/statusfails with a clear messageThis PR deliberately does not add Cluster phase reporting for this condition. A follow-up feature could add a generic mechanism for instance-manager detected faults that require user action to be surfaced in Cluster status, but that is kept out of this minimal fix.
Tests run:
go test ./internal/cmd/manager/instance/run ./pkg/management/postgres ./pkg/management/postgres/logpipe ./pkg/postgres ./internal/controllerFixes #11134