aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2025-01-17 13:27:43 +0900
committerMichael Paquier <michael@paquier.xyz>2025-01-17 13:27:43 +0900
commit4d72357c40ee0abfa5aa9361683aa08e257418c5 (patch)
tree03def5263b2e56964af6a2cdfc5a9a2b44e5e200 /src
parent94c02bd3345d7837bc1f240c14db2222c85aa18c (diff)
downloadpostgresql-4d72357c40ee0abfa5aa9361683aa08e257418c5.tar.gz
postgresql-4d72357c40ee0abfa5aa9361683aa08e257418c5.zip
Revert recent changes related to handling of 2PC files at recovery
This commit reverts 8f67f994e8ea (down to v13) and c3de0f9eed38 (down to v17), as these are proving to not be completely correct regarding two aspects: - In v17 and newer branches, c3de0f9eed38's check for epoch handling is incorrect, and does not correctly handle frozen epochs. A logic closer to widen_snapshot_xid() should be used. The 2PC code should try to integrate deeper with FullTransactionIds, 5a1dfde8334b being not enough. - In v13 and newer branches, 8f67f994e8ea is a workaround for the real issue, which is that we should not attempt CLOG lookups without reaching consistency. This exists since 728bd991c3c4, and this is reachable with ProcessTwoPhaseBuffer() called by restoreTwoPhaseData() at the beginning of recovery. Per discussion with Noah Misch. Discussion: https://postgr.es/m/20250116010051.f3.nmisch@google.com Backpatch-through: 13
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/transam/twophase.c16
-rw-r--r--src/test/recovery/t/009_twophase.pl23
2 files changed, 8 insertions, 31 deletions
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c
index 330d2a5c9ec..95aa8be9c53 100644
--- a/src/backend/access/transam/twophase.c
+++ b/src/backend/access/transam/twophase.c
@@ -2183,40 +2183,40 @@ ProcessTwoPhaseBuffer(TransactionId xid,
if (!fromdisk)
Assert(prepare_start_lsn != InvalidXLogRecPtr);
- /* Reject XID if too new */
- if (TransactionIdFollowsOrEquals(xid, origNextXid))
+ /* Already processed? */
+ if (TransactionIdDidCommit(xid) || TransactionIdDidAbort(xid))
{
if (fromdisk)
{
ereport(WARNING,
- (errmsg("removing future two-phase state file for transaction %u",
+ (errmsg("removing stale two-phase state file for transaction %u",
xid)));
RemoveTwoPhaseFile(xid, true);
}
else
{
ereport(WARNING,
- (errmsg("removing future two-phase state from memory for transaction %u",
+ (errmsg("removing stale two-phase state from memory for transaction %u",
xid)));
PrepareRedoRemove(xid, true);
}
return NULL;
}
- /* Already processed? */
- if (TransactionIdDidCommit(xid) || TransactionIdDidAbort(xid))
+ /* Reject XID if too new */
+ if (TransactionIdFollowsOrEquals(xid, origNextXid))
{
if (fromdisk)
{
ereport(WARNING,
- (errmsg("removing stale two-phase state file for transaction %u",
+ (errmsg("removing future two-phase state file for transaction %u",
xid)));
RemoveTwoPhaseFile(xid, true);
}
else
{
ereport(WARNING,
- (errmsg("removing stale two-phase state from memory for transaction %u",
+ (errmsg("removing future two-phase state from memory for transaction %u",
xid)));
PrepareRedoRemove(xid, true);
}
diff --git a/src/test/recovery/t/009_twophase.pl b/src/test/recovery/t/009_twophase.pl
index 7642e4f0b3c..fe7e8e79802 100644
--- a/src/test/recovery/t/009_twophase.pl
+++ b/src/test/recovery/t/009_twophase.pl
@@ -528,27 +528,4 @@ is( $psql_out,
qq{27|issued to paris},
"Check expected t_009_tbl2 data on standby");
-###############################################################################
-# Check handling of orphaned 2PC files at recovery.
-###############################################################################
-
-$cur_primary->teardown_node;
-
-# Grab location in logs of primary
-my $log_offset = -s $cur_primary->logfile;
-
-# Create a fake file with a transaction ID large enough to be in the future,
-# then check that the primary is able to start and remove this file at
-# recovery.
-
-my $future_2pc_file = $cur_primary->data_dir . '/pg_twophase/00FFFFFF';
-append_to_file $future_2pc_file, "";
-
-$cur_primary->start;
-$cur_primary->log_check(
- "future two-phase file removed at recovery",
- $log_offset,
- log_like =>
- [qr/removing future two-phase state file for transaction 16777215/]);
-
done_testing();