Skip to content

Commit d698bf8

Browse files
committed
Fix TransactionIdSetStatusBit so that it doesn't try to change a transaction
from COMMITTED to SUBCOMMITTED during recovery. This wasn't previously possible, but it is now due to the recent changes on clog commit protocol for subtransactions. Simon Riggs
1 parent 13fc2e4 commit d698bf8

File tree

1 file changed

+21
-5
lines changed
  • src/backend/access/transam

1 file changed

+21
-5
lines changed

src/backend/access/transam/clog.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
2727
* Portions Copyright (c) 1994, Regents of the University of California
2828
*
29-
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.48 2008/10/20 19:18:18 alvherre Exp $
29+
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.49 2008/11/03 19:24:03 alvherre Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -321,13 +321,29 @@ TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, i
321321
int bshift = TransactionIdToBIndex(xid) * CLOG_BITS_PER_XACT;
322322
char *byteptr;
323323
char byteval;
324+
char curval;
324325

325326
byteptr = ClogCtl->shared->page_buffer[slotno] + byteno;
327+
curval = (*byteptr >> shift) & CLOG_XACT_BITMASK;
326328

327-
/* Current state should be 0, subcommitted or target state */
328-
Assert(((*byteptr >> bshift) & CLOG_XACT_BITMASK) == 0 ||
329-
((*byteptr >> bshift) & CLOG_XACT_BITMASK) == TRANSACTION_STATUS_SUB_COMMITTED ||
330-
((*byteptr >> bshift) & CLOG_XACT_BITMASK) == status);
329+
/*
330+
* When replaying transactions during recovery we still need to perform
331+
* the two phases of subcommit and then commit. However, some transactions
332+
* are already correctly marked, so we just treat those as a no-op which
333+
* allows us to keep the following Assert as restrictive as possible.
334+
*/
335+
if (InRecovery && status == TRANSACTION_STATUS_SUB_COMMITTED &&
336+
curval == TRANSACTION_STATUS_COMMITTED)
337+
return;
338+
339+
/*
340+
* Current state change should be from 0 or subcommitted to target state
341+
* or we should already be there when replaying changes during recovery.
342+
*/
343+
Assert(curval == 0 ||
344+
(curval == TRANSACTION_STATUS_SUB_COMMITTED &&
345+
status != TRANSACTION_STATUS_IN_PROGRESS) ||
346+
curval == status);
331347

332348
/* note this assumes exclusive access to the clog page */
333349
byteval = *byteptr;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy