From: | Michael Paquier <michael(at)paquier(dot)xyz> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Fix recovery of 2PC transaction during crash recovery |
Date: | 2023-07-18 04:45:25 |
Message-ID: | E1qLcaS-0003DJ-IG@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Fix recovery of 2PC transaction during crash recovery
A crash in the middle of a checkpoint with some two-phase state data
already flushed to disk by this checkpoint could cause a follow-up crash
recovery to recover twice the same transaction, once from what has been
found in pg_twophase/ at the beginning of recovery and a second time
when replaying its corresponding record.
This would lead to FATAL failures in the startup process during
recovery, where the same transaction would have a state recovered twice
instead of once:
LOG: recovering prepared transaction 731 from shared memory
LOG: recovering prepared transaction 731 from shared memory
FATAL: lock ExclusiveLock on object 731/0/0 is already held
This issue is fixed by skipping the addition of any 2PC state coming
from a record whose equivalent 2PC state file has already been loaded in
TwoPhaseState at the beginning of recovery by restoreTwoPhaseData(),
which is OK as long as the system has not reached a consistent state.
The timing to get a messed up recovery processing is very racy, and
would very unlikely happen. The thread that has reported the issue has
demonstrated the bug using injection points to force a PANIC in the
middle of a checkpoint.
Issue introduced in 728bd99, so backpatch all the way down.
Reported-by: "suyu.cmj" <mengjuan(dot)cmj(at)alibaba-inc(dot)com>
Author: "suyu.cmj" <mengjuan(dot)cmj(at)alibaba-inc(dot)com>
Author: Michael Paquier
Discussion: https://postgr.es/m/109e6994-b971-48cb-84f6-829646f18b4c.mengjuan.cmj@alibaba-inc.com
Backpatch-through: 11
Branch
------
REL_14_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/442749100d34a213f71c73d98bc7b43478832e3a
Modified Files
--------------
src/backend/access/transam/twophase.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2023-07-18 05:05:22 | pgsql: Fix indentation in twophase.c |
Previous Message | Tom Lane | 2023-07-17 20:55:02 | pgsql: Include <limits.h> in fe-auth.c, to get CHAR_BIT reliably. |