Skip to content

Commit 060f9f5

Browse files
committed
Revert recent changes related to handling of 2PC files at recovery
This commit reverts 8f67f99 (down to v13) and c3de0f9 (down to v17), as these are proving to not be completely correct regarding two aspects: - In v17 and newer branches, c3de0f9'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, 5a1dfde being not enough. - In v13 and newer branches, 8f67f99 is a workaround for the real issue, which is that we should not attempt CLOG lookups without reaching consistency. This exists since 728bd99, 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
1 parent 5f72564 commit 060f9f5

File tree

2 files changed

+9
-32
lines changed

2 files changed

+9
-32
lines changed

src/backend/access/transam/twophase.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -2156,40 +2156,40 @@ ProcessTwoPhaseBuffer(TransactionId xid,
21562156
if (!fromdisk)
21572157
Assert(prepare_start_lsn != InvalidXLogRecPtr);
21582158

2159-
/* Reject XID if too new */
2160-
if (TransactionIdFollowsOrEquals(xid, origNextXid))
2159+
/* Already processed? */
2160+
if (TransactionIdDidCommit(xid) || TransactionIdDidAbort(xid))
21612161
{
21622162
if (fromdisk)
21632163
{
21642164
ereport(WARNING,
2165-
(errmsg("removing future two-phase state file for transaction %u",
2165+
(errmsg("removing stale two-phase state file for transaction %u",
21662166
xid)));
21672167
RemoveTwoPhaseFile(xid, true);
21682168
}
21692169
else
21702170
{
21712171
ereport(WARNING,
2172-
(errmsg("removing future two-phase state from memory for transaction %u",
2172+
(errmsg("removing stale two-phase state from memory for transaction %u",
21732173
xid)));
21742174
PrepareRedoRemove(xid, true);
21752175
}
21762176
return NULL;
21772177
}
21782178

2179-
/* Already processed? */
2180-
if (TransactionIdDidCommit(xid) || TransactionIdDidAbort(xid))
2179+
/* Reject XID if too new */
2180+
if (TransactionIdFollowsOrEquals(xid, origNextXid))
21812181
{
21822182
if (fromdisk)
21832183
{
21842184
ereport(WARNING,
2185-
(errmsg("removing stale two-phase state file for transaction %u",
2185+
(errmsg("removing future two-phase state file for transaction %u",
21862186
xid)));
21872187
RemoveTwoPhaseFile(xid, true);
21882188
}
21892189
else
21902190
{
21912191
ereport(WARNING,
2192-
(errmsg("removing stale two-phase state from memory for transaction %u",
2192+
(errmsg("removing future two-phase state from memory for transaction %u",
21932193
xid)));
21942194
PrepareRedoRemove(xid, true);
21952195
}

src/test/recovery/t/009_twophase.pl

+1-24
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use PostgresNode;
99
use TestLib;
10-
use Test::More tests => 28;
10+
use Test::More tests => 27;
1111

1212
my $psql_out = '';
1313
my $psql_rc = '';
@@ -527,26 +527,3 @@ sub configure_and_reload
527527
is( $psql_out,
528528
qq{27|issued to paris},
529529
"Check expected t_009_tbl2 data on standby");
530-
531-
###############################################################################
532-
# Check handling of orphaned 2PC files at recovery.
533-
###############################################################################
534-
535-
$cur_primary->teardown_node;
536-
537-
# Grab location in logs of primary
538-
my $log_offset = -s $cur_primary->logfile;
539-
540-
# Create a fake file with a transaction ID large enough to be in the future,
541-
# then check that the primary is able to start and remove this file at
542-
# recovery.
543-
544-
my $future_2pc_file = $cur_primary->data_dir . '/pg_twophase/00FFFFFF';
545-
append_to_file $future_2pc_file, "";
546-
547-
$cur_primary->start;
548-
$cur_primary->log_check(
549-
"future two-phase file removed at recovery",
550-
$log_offset,
551-
log_like =>
552-
[qr/removing future two-phase state file for transaction 16777215/]);

0 commit comments

Comments
 (0)