aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/clog.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-08-26 16:56:03 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-08-26 16:56:03 +0000
commitbc7d37a525c02f4a0e983854c4222e9d063eeae2 (patch)
tree46d1ff8c74eb0a6cec5c183732410a1b846fc5ba /src/backend/access/transam/clog.c
parentd1ee78f2962f09f0fe7c6c8ee16ad513ac113ba4 (diff)
downloadpostgresql-bc7d37a525c02f4a0e983854c4222e9d063eeae2.tar.gz
postgresql-bc7d37a525c02f4a0e983854c4222e9d063eeae2.zip
Transaction IDs wrap around, per my proposal of 13-Aug-01. More
documentation to come, but the code is all here. initdb forced.
Diffstat (limited to 'src/backend/access/transam/clog.c')
-rw-r--r--src/backend/access/transam/clog.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index 07581e4444a..a403838bd79 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.2 2001/08/25 23:24:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.3 2001/08/26 16:55:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -762,8 +762,12 @@ ExtendCLOG(TransactionId newestXact)
{
int pageno;
- /* No work except at first XID of a page */
- if (TransactionIdToPgIndex(newestXact) != 0)
+ /*
+ * No work except at first XID of a page. But beware: just after
+ * wraparound, the first XID of page zero is FirstNormalTransactionId.
+ */
+ if (TransactionIdToPgIndex(newestXact) != 0 &&
+ !TransactionIdEquals(newestXact, FirstNormalTransactionId))
return;
pageno = TransactionIdToPage(newestXact);
@@ -818,6 +822,18 @@ TruncateCLOG(TransactionId oldestXact)
S_LOCK(&(ClogCtl->control_lck));
restart:;
+ /*
+ * While we are holding the lock, make an important safety check:
+ * the planned cutoff point must be <= the current CLOG endpoint page.
+ * Otherwise we have already wrapped around, and proceeding with the
+ * truncation would risk removing the current CLOG segment.
+ */
+ if (CLOGPagePrecedes(ClogCtl->latest_page_number, cutoffPage))
+ {
+ S_UNLOCK(&(ClogCtl->control_lck));
+ elog(LOG, "unable to truncate commit log: apparent wraparound");
+ return;
+ }
for (slotno = 0; slotno < NUM_CLOG_BUFFERS; slotno++)
{