Commit 18691d8e authored by Tom Lane's avatar Tom Lane

Clean up representation of SLRU page state. This is the cleaner fix

for the SLRU race condition that I posted a few days ago, but we decided
not to use in 8.1 and older branches.
parent 667ba8cc
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.33 2005/10/15 02:49:09 momjian Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.34 2005/11/05 21:19:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -107,7 +107,7 @@ TransactionIdSetStatus(TransactionId xid, XidStatus status) ...@@ -107,7 +107,7 @@ TransactionIdSetStatus(TransactionId xid, XidStatus status)
byteval |= (status << bshift); byteval |= (status << bshift);
*byteptr = byteval; *byteptr = byteval;
ClogCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY; ClogCtl->shared->page_dirty[slotno] = true;
LWLockRelease(CLogControlLock); LWLockRelease(CLogControlLock);
} }
...@@ -175,7 +175,7 @@ BootStrapCLOG(void) ...@@ -175,7 +175,7 @@ BootStrapCLOG(void)
/* Make sure it's written out */ /* Make sure it's written out */
SimpleLruWritePage(ClogCtl, slotno, NULL); SimpleLruWritePage(ClogCtl, slotno, NULL);
Assert(ClogCtl->shared->page_status[slotno] == SLRU_PAGE_CLEAN); Assert(!ClogCtl->shared->page_dirty[slotno]);
LWLockRelease(CLogControlLock); LWLockRelease(CLogControlLock);
} }
...@@ -246,7 +246,7 @@ StartupCLOG(void) ...@@ -246,7 +246,7 @@ StartupCLOG(void)
/* Zero the rest of the page */ /* Zero the rest of the page */
MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1); MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1);
ClogCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY; ClogCtl->shared->page_dirty[slotno] = true;
} }
LWLockRelease(CLogControlLock); LWLockRelease(CLogControlLock);
...@@ -404,7 +404,7 @@ clog_redo(XLogRecPtr lsn, XLogRecord *record) ...@@ -404,7 +404,7 @@ clog_redo(XLogRecPtr lsn, XLogRecord *record)
slotno = ZeroCLOGPage(pageno, false); slotno = ZeroCLOGPage(pageno, false);
SimpleLruWritePage(ClogCtl, slotno, NULL); SimpleLruWritePage(ClogCtl, slotno, NULL);
Assert(ClogCtl->shared->page_status[slotno] == SLRU_PAGE_CLEAN); Assert(!ClogCtl->shared->page_dirty[slotno]);
LWLockRelease(CLogControlLock); LWLockRelease(CLogControlLock);
} }
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/multixact.c,v 1.11 2005/10/28 19:00:19 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/multixact.c,v 1.12 2005/11/05 21:19:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -714,7 +714,7 @@ RecordNewMultiXact(MultiXactId multi, MultiXactOffset offset, ...@@ -714,7 +714,7 @@ RecordNewMultiXact(MultiXactId multi, MultiXactOffset offset,
*offptr = offset; *offptr = offset;
MultiXactOffsetCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY; MultiXactOffsetCtl->shared->page_dirty[slotno] = true;
/* Exchange our lock */ /* Exchange our lock */
LWLockRelease(MultiXactOffsetControlLock); LWLockRelease(MultiXactOffsetControlLock);
...@@ -742,7 +742,7 @@ RecordNewMultiXact(MultiXactId multi, MultiXactOffset offset, ...@@ -742,7 +742,7 @@ RecordNewMultiXact(MultiXactId multi, MultiXactOffset offset,
*memberptr = xids[i]; *memberptr = xids[i];
MultiXactMemberCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY; MultiXactMemberCtl->shared->page_dirty[slotno] = true;
} }
LWLockRelease(MultiXactMemberControlLock); LWLockRelease(MultiXactMemberControlLock);
...@@ -1308,7 +1308,7 @@ BootStrapMultiXact(void) ...@@ -1308,7 +1308,7 @@ BootStrapMultiXact(void)
/* Make sure it's written out */ /* Make sure it's written out */
SimpleLruWritePage(MultiXactOffsetCtl, slotno, NULL); SimpleLruWritePage(MultiXactOffsetCtl, slotno, NULL);
Assert(MultiXactOffsetCtl->shared->page_status[slotno] == SLRU_PAGE_CLEAN); Assert(!MultiXactOffsetCtl->shared->page_dirty[slotno]);
LWLockRelease(MultiXactOffsetControlLock); LWLockRelease(MultiXactOffsetControlLock);
...@@ -1319,7 +1319,7 @@ BootStrapMultiXact(void) ...@@ -1319,7 +1319,7 @@ BootStrapMultiXact(void)
/* Make sure it's written out */ /* Make sure it's written out */
SimpleLruWritePage(MultiXactMemberCtl, slotno, NULL); SimpleLruWritePage(MultiXactMemberCtl, slotno, NULL);
Assert(MultiXactMemberCtl->shared->page_status[slotno] == SLRU_PAGE_CLEAN); Assert(!MultiXactMemberCtl->shared->page_dirty[slotno]);
LWLockRelease(MultiXactMemberControlLock); LWLockRelease(MultiXactMemberControlLock);
} }
...@@ -1405,7 +1405,7 @@ StartupMultiXact(void) ...@@ -1405,7 +1405,7 @@ StartupMultiXact(void)
MemSet(offptr, 0, BLCKSZ - (entryno * sizeof(MultiXactOffset))); MemSet(offptr, 0, BLCKSZ - (entryno * sizeof(MultiXactOffset)));
MultiXactOffsetCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY; MultiXactOffsetCtl->shared->page_dirty[slotno] = true;
} }
LWLockRelease(MultiXactOffsetControlLock); LWLockRelease(MultiXactOffsetControlLock);
...@@ -1435,7 +1435,7 @@ StartupMultiXact(void) ...@@ -1435,7 +1435,7 @@ StartupMultiXact(void)
MemSet(xidptr, 0, BLCKSZ - (entryno * sizeof(TransactionId))); MemSet(xidptr, 0, BLCKSZ - (entryno * sizeof(TransactionId)));
MultiXactMemberCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY; MultiXactMemberCtl->shared->page_dirty[slotno] = true;
} }
LWLockRelease(MultiXactMemberControlLock); LWLockRelease(MultiXactMemberControlLock);
...@@ -1829,7 +1829,7 @@ multixact_redo(XLogRecPtr lsn, XLogRecord *record) ...@@ -1829,7 +1829,7 @@ multixact_redo(XLogRecPtr lsn, XLogRecord *record)
slotno = ZeroMultiXactOffsetPage(pageno, false); slotno = ZeroMultiXactOffsetPage(pageno, false);
SimpleLruWritePage(MultiXactOffsetCtl, slotno, NULL); SimpleLruWritePage(MultiXactOffsetCtl, slotno, NULL);
Assert(MultiXactOffsetCtl->shared->page_status[slotno] == SLRU_PAGE_CLEAN); Assert(!MultiXactOffsetCtl->shared->page_dirty[slotno]);
LWLockRelease(MultiXactOffsetControlLock); LWLockRelease(MultiXactOffsetControlLock);
} }
...@@ -1844,7 +1844,7 @@ multixact_redo(XLogRecPtr lsn, XLogRecord *record) ...@@ -1844,7 +1844,7 @@ multixact_redo(XLogRecPtr lsn, XLogRecord *record)
slotno = ZeroMultiXactMemberPage(pageno, false); slotno = ZeroMultiXactMemberPage(pageno, false);
SimpleLruWritePage(MultiXactMemberCtl, slotno, NULL); SimpleLruWritePage(MultiXactMemberCtl, slotno, NULL);
Assert(MultiXactMemberCtl->shared->page_status[slotno] == SLRU_PAGE_CLEAN); Assert(!MultiXactMemberCtl->shared->page_dirty[slotno]);
LWLockRelease(MultiXactMemberControlLock); LWLockRelease(MultiXactMemberControlLock);
} }
......
This diff is collapsed.
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/subtrans.c,v 1.11 2005/10/15 02:49:09 momjian Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/subtrans.c,v 1.12 2005/11/05 21:19:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -86,7 +86,7 @@ SubTransSetParent(TransactionId xid, TransactionId parent) ...@@ -86,7 +86,7 @@ SubTransSetParent(TransactionId xid, TransactionId parent)
*ptr = parent; *ptr = parent;
SubTransCtl->shared->page_status[slotno] = SLRU_PAGE_DIRTY; SubTransCtl->shared->page_dirty[slotno] = true;
LWLockRelease(SubtransControlLock); LWLockRelease(SubtransControlLock);
} }
...@@ -199,7 +199,7 @@ BootStrapSUBTRANS(void) ...@@ -199,7 +199,7 @@ BootStrapSUBTRANS(void)
/* Make sure it's written out */ /* Make sure it's written out */
SimpleLruWritePage(SubTransCtl, slotno, NULL); SimpleLruWritePage(SubTransCtl, slotno, NULL);
Assert(SubTransCtl->shared->page_status[slotno] == SLRU_PAGE_CLEAN); Assert(!SubTransCtl->shared->page_dirty[slotno]);
LWLockRelease(SubtransControlLock); LWLockRelease(SubtransControlLock);
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/slru.h,v 1.14 2005/10/15 02:49:42 momjian Exp $ * $PostgreSQL: pgsql/src/include/access/slru.h,v 1.15 2005/11/05 21:19:47 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -23,13 +23,17 @@ ...@@ -23,13 +23,17 @@
*/ */
#define NUM_SLRU_BUFFERS 8 #define NUM_SLRU_BUFFERS 8
/* Page status codes */ /*
* Page status codes. Note that these do not include the "dirty" bit.
* page_dirty can be TRUE only in the VALID or WRITE_IN_PROGRESS states;
* in the latter case it implies that the page has been re-dirtied since
* the write started.
*/
typedef enum typedef enum
{ {
SLRU_PAGE_EMPTY, /* buffer is not in use */ SLRU_PAGE_EMPTY, /* buffer is not in use */
SLRU_PAGE_READ_IN_PROGRESS, /* page is being read in */ SLRU_PAGE_READ_IN_PROGRESS, /* page is being read in */
SLRU_PAGE_CLEAN, /* page is valid and not dirty */ SLRU_PAGE_VALID, /* page is valid and not being written */
SLRU_PAGE_DIRTY, /* page is valid but needs write */
SLRU_PAGE_WRITE_IN_PROGRESS /* page is being written out */ SLRU_PAGE_WRITE_IN_PROGRESS /* page is being written out */
} SlruPageStatus; } SlruPageStatus;
...@@ -48,6 +52,7 @@ typedef struct SlruSharedData ...@@ -48,6 +52,7 @@ typedef struct SlruSharedData
*/ */
char *page_buffer[NUM_SLRU_BUFFERS]; char *page_buffer[NUM_SLRU_BUFFERS];
SlruPageStatus page_status[NUM_SLRU_BUFFERS]; SlruPageStatus page_status[NUM_SLRU_BUFFERS];
bool page_dirty[NUM_SLRU_BUFFERS];
int page_number[NUM_SLRU_BUFFERS]; int page_number[NUM_SLRU_BUFFERS];
unsigned int page_lru_count[NUM_SLRU_BUFFERS]; unsigned int page_lru_count[NUM_SLRU_BUFFERS];
LWLockId buffer_locks[NUM_SLRU_BUFFERS]; LWLockId buffer_locks[NUM_SLRU_BUFFERS];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment