aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/lmgr/predicate.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-05-15 14:28:19 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-05-15 14:28:25 -0400
commit5da14938f7bfb96b648ee3c47e7ea2afca5bcc4a (patch)
treea637e548f3a39f0ebaef513f870964eb5dcecec9 /src/backend/storage/lmgr/predicate.c
parent756abe2bc7608b38c579c510eb66f2bd80d10785 (diff)
downloadpostgresql-5da14938f7bfb96b648ee3c47e7ea2afca5bcc4a.tar.gz
postgresql-5da14938f7bfb96b648ee3c47e7ea2afca5bcc4a.zip
Rename SLRU structures and associated LWLocks.
Originally, the names assigned to SLRUs had no purpose other than being shmem lookup keys, so not a lot of thought went into them. As of v13, though, we're exposing them in the pg_stat_slru view and the pg_stat_reset_slru function, so it seems advisable to take a bit more care. Rename them to names based on the associated on-disk storage directories (which fortunately we *did* think about, to some extent; since those are also visible to DBAs, consistency seems like a good thing). Also rename the associated LWLocks, since those names are likewise user-exposed now as wait event names. For the most part I only touched symbols used in the respective modules' SimpleLruInit() calls, not the names of other related objects. This renaming could have been taken further, and maybe someday we will do so. But for now it seems undesirable to change the names of any globally visible functions or structs, so some inconsistency is unavoidable. (But I *did* terminate "oldserxid" with prejudice, as I found that name both unreadable and not descriptive of the SLRU's contents.) Table 27.12 needs re-alphabetization now, but I'll leave that till after the other LWLock renamings I have in mind. Discussion: https://postgr.es/m/28683.1589405363@sss.pgh.pa.us
Diffstat (limited to 'src/backend/storage/lmgr/predicate.c')
-rw-r--r--src/backend/storage/lmgr/predicate.c214
1 files changed, 107 insertions, 107 deletions
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c
index 654584b77af..02415ff01e3 100644
--- a/src/backend/storage/lmgr/predicate.c
+++ b/src/backend/storage/lmgr/predicate.c
@@ -211,7 +211,7 @@
#include "utils/snapmgr.h"
/* Uncomment the next line to test the graceful degradation code. */
-/* #define TEST_OLDSERXID */
+/* #define TEST_SUMMARIZE_SERIAL */
/*
* Test the most selective fields first, for performance.
@@ -316,37 +316,37 @@
/*
* The SLRU buffer area through which we access the old xids.
*/
-static SlruCtlData OldSerXidSlruCtlData;
+static SlruCtlData SerialSlruCtlData;
-#define OldSerXidSlruCtl (&OldSerXidSlruCtlData)
+#define SerialSlruCtl (&SerialSlruCtlData)
-#define OLDSERXID_PAGESIZE BLCKSZ
-#define OLDSERXID_ENTRYSIZE sizeof(SerCommitSeqNo)
-#define OLDSERXID_ENTRIESPERPAGE (OLDSERXID_PAGESIZE / OLDSERXID_ENTRYSIZE)
+#define SERIAL_PAGESIZE BLCKSZ
+#define SERIAL_ENTRYSIZE sizeof(SerCommitSeqNo)
+#define SERIAL_ENTRIESPERPAGE (SERIAL_PAGESIZE / SERIAL_ENTRYSIZE)
/*
* Set maximum pages based on the number needed to track all transactions.
*/
-#define OLDSERXID_MAX_PAGE (MaxTransactionId / OLDSERXID_ENTRIESPERPAGE)
+#define SERIAL_MAX_PAGE (MaxTransactionId / SERIAL_ENTRIESPERPAGE)
-#define OldSerXidNextPage(page) (((page) >= OLDSERXID_MAX_PAGE) ? 0 : (page) + 1)
+#define SerialNextPage(page) (((page) >= SERIAL_MAX_PAGE) ? 0 : (page) + 1)
-#define OldSerXidValue(slotno, xid) (*((SerCommitSeqNo *) \
- (OldSerXidSlruCtl->shared->page_buffer[slotno] + \
- ((((uint32) (xid)) % OLDSERXID_ENTRIESPERPAGE) * OLDSERXID_ENTRYSIZE))))
+#define SerialValue(slotno, xid) (*((SerCommitSeqNo *) \
+ (SerialSlruCtl->shared->page_buffer[slotno] + \
+ ((((uint32) (xid)) % SERIAL_ENTRIESPERPAGE) * SERIAL_ENTRYSIZE))))
-#define OldSerXidPage(xid) (((uint32) (xid)) / OLDSERXID_ENTRIESPERPAGE)
+#define SerialPage(xid) (((uint32) (xid)) / SERIAL_ENTRIESPERPAGE)
-typedef struct OldSerXidControlData
+typedef struct SerialControlData
{
int headPage; /* newest initialized page */
TransactionId headXid; /* newest valid Xid in the SLRU */
TransactionId tailXid; /* oldest xmin we might be interested in */
-} OldSerXidControlData;
+} SerialControlData;
-typedef struct OldSerXidControlData *OldSerXidControl;
+typedef struct SerialControlData *SerialControl;
-static OldSerXidControl oldSerXidControl;
+static SerialControl serialControl;
/*
* When the oldest committed transaction on the "finished" list is moved to
@@ -438,11 +438,11 @@ static void SetPossibleUnsafeConflict(SERIALIZABLEXACT *roXact, SERIALIZABLEXACT
static void ReleaseRWConflict(RWConflict conflict);
static void FlagSxactUnsafe(SERIALIZABLEXACT *sxact);
-static bool OldSerXidPagePrecedesLogically(int p, int q);
-static void OldSerXidInit(void);
-static void OldSerXidAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo);
-static SerCommitSeqNo OldSerXidGetMinConflictCommitSeqNo(TransactionId xid);
-static void OldSerXidSetActiveSerXmin(TransactionId xid);
+static bool SerialPagePrecedesLogically(int p, int q);
+static void SerialInit(void);
+static void SerialAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo);
+static SerCommitSeqNo SerialGetMinConflictCommitSeqNo(TransactionId xid);
+static void SerialSetActiveSerXmin(TransactionId xid);
static uint32 predicatelock_hash(const void *key, Size keysize);
static void SummarizeOldestCommittedSxact(void);
@@ -784,26 +784,26 @@ FlagSxactUnsafe(SERIALIZABLEXACT *sxact)
/*------------------------------------------------------------------------*/
/*
- * We will work on the page range of 0..OLDSERXID_MAX_PAGE.
+ * We will work on the page range of 0..SERIAL_MAX_PAGE.
* Compares using wraparound logic, as is required by slru.c.
*/
static bool
-OldSerXidPagePrecedesLogically(int p, int q)
+SerialPagePrecedesLogically(int p, int q)
{
int diff;
/*
- * We have to compare modulo (OLDSERXID_MAX_PAGE+1)/2. Both inputs should
- * be in the range 0..OLDSERXID_MAX_PAGE.
+ * We have to compare modulo (SERIAL_MAX_PAGE+1)/2. Both inputs should be
+ * in the range 0..SERIAL_MAX_PAGE.
*/
- Assert(p >= 0 && p <= OLDSERXID_MAX_PAGE);
- Assert(q >= 0 && q <= OLDSERXID_MAX_PAGE);
+ Assert(p >= 0 && p <= SERIAL_MAX_PAGE);
+ Assert(q >= 0 && q <= SERIAL_MAX_PAGE);
diff = p - q;
- if (diff >= ((OLDSERXID_MAX_PAGE + 1) / 2))
- diff -= OLDSERXID_MAX_PAGE + 1;
- else if (diff < -((int) (OLDSERXID_MAX_PAGE + 1) / 2))
- diff += OLDSERXID_MAX_PAGE + 1;
+ if (diff >= ((SERIAL_MAX_PAGE + 1) / 2))
+ diff -= SERIAL_MAX_PAGE + 1;
+ else if (diff < -((int) (SERIAL_MAX_PAGE + 1) / 2))
+ diff += SERIAL_MAX_PAGE + 1;
return diff < 0;
}
@@ -811,25 +811,25 @@ OldSerXidPagePrecedesLogically(int p, int q)
* Initialize for the tracking of old serializable committed xids.
*/
static void
-OldSerXidInit(void)
+SerialInit(void)
{
bool found;
/*
* Set up SLRU management of the pg_serial data.
*/
- OldSerXidSlruCtl->PagePrecedes = OldSerXidPagePrecedesLogically;
- SimpleLruInit(OldSerXidSlruCtl, "oldserxid",
- NUM_OLDSERXID_BUFFERS, 0, OldSerXidLock, "pg_serial",
- LWTRANCHE_OLDSERXID_BUFFERS);
+ SerialSlruCtl->PagePrecedes = SerialPagePrecedesLogically;
+ SimpleLruInit(SerialSlruCtl, "Serial",
+ NUM_SERIAL_BUFFERS, 0, SerialSLRULock, "pg_serial",
+ LWTRANCHE_SERIAL_BUFFER);
/* Override default assumption that writes should be fsync'd */
- OldSerXidSlruCtl->do_fsync = false;
+ SerialSlruCtl->do_fsync = false;
/*
- * Create or attach to the OldSerXidControl structure.
+ * Create or attach to the SerialControl structure.
*/
- oldSerXidControl = (OldSerXidControl)
- ShmemInitStruct("OldSerXidControlData", sizeof(OldSerXidControlData), &found);
+ serialControl = (SerialControl)
+ ShmemInitStruct("SerialControlData", sizeof(SerialControlData), &found);
Assert(found == IsUnderPostmaster);
if (!found)
@@ -837,9 +837,9 @@ OldSerXidInit(void)
/*
* Set control information to reflect empty SLRU.
*/
- oldSerXidControl->headPage = -1;
- oldSerXidControl->headXid = InvalidTransactionId;
- oldSerXidControl->tailXid = InvalidTransactionId;
+ serialControl->headPage = -1;
+ serialControl->headXid = InvalidTransactionId;
+ serialControl->tailXid = InvalidTransactionId;
}
}
@@ -849,7 +849,7 @@ OldSerXidInit(void)
* An invalid commitSeqNo means that there were no conflicts out from xid.
*/
static void
-OldSerXidAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo)
+SerialAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo)
{
TransactionId tailXid;
int targetPage;
@@ -859,16 +859,16 @@ OldSerXidAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo)
Assert(TransactionIdIsValid(xid));
- targetPage = OldSerXidPage(xid);
+ targetPage = SerialPage(xid);
- LWLockAcquire(OldSerXidLock, LW_EXCLUSIVE);
+ LWLockAcquire(SerialSLRULock, LW_EXCLUSIVE);
/*
* If no serializable transactions are active, there shouldn't be anything
* to push out to the SLRU. Hitting this assert would mean there's
* something wrong with the earlier cleanup logic.
*/
- tailXid = oldSerXidControl->tailXid;
+ tailXid = serialControl->tailXid;
Assert(TransactionIdIsValid(tailXid));
/*
@@ -877,41 +877,41 @@ OldSerXidAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo)
* any new pages that enter the tailXid-headXid range as we advance
* headXid.
*/
- if (oldSerXidControl->headPage < 0)
+ if (serialControl->headPage < 0)
{
- firstZeroPage = OldSerXidPage(tailXid);
+ firstZeroPage = SerialPage(tailXid);
isNewPage = true;
}
else
{
- firstZeroPage = OldSerXidNextPage(oldSerXidControl->headPage);
- isNewPage = OldSerXidPagePrecedesLogically(oldSerXidControl->headPage,
- targetPage);
+ firstZeroPage = SerialNextPage(serialControl->headPage);
+ isNewPage = SerialPagePrecedesLogically(serialControl->headPage,
+ targetPage);
}
- if (!TransactionIdIsValid(oldSerXidControl->headXid)
- || TransactionIdFollows(xid, oldSerXidControl->headXid))
- oldSerXidControl->headXid = xid;
+ if (!TransactionIdIsValid(serialControl->headXid)
+ || TransactionIdFollows(xid, serialControl->headXid))
+ serialControl->headXid = xid;
if (isNewPage)
- oldSerXidControl->headPage = targetPage;
+ serialControl->headPage = targetPage;
if (isNewPage)
{
/* Initialize intervening pages. */
while (firstZeroPage != targetPage)
{
- (void) SimpleLruZeroPage(OldSerXidSlruCtl, firstZeroPage);
- firstZeroPage = OldSerXidNextPage(firstZeroPage);
+ (void) SimpleLruZeroPage(SerialSlruCtl, firstZeroPage);
+ firstZeroPage = SerialNextPage(firstZeroPage);
}
- slotno = SimpleLruZeroPage(OldSerXidSlruCtl, targetPage);
+ slotno = SimpleLruZeroPage(SerialSlruCtl, targetPage);
}
else
- slotno = SimpleLruReadPage(OldSerXidSlruCtl, targetPage, true, xid);
+ slotno = SimpleLruReadPage(SerialSlruCtl, targetPage, true, xid);
- OldSerXidValue(slotno, xid) = minConflictCommitSeqNo;
- OldSerXidSlruCtl->shared->page_dirty[slotno] = true;
+ SerialValue(slotno, xid) = minConflictCommitSeqNo;
+ SerialSlruCtl->shared->page_dirty[slotno] = true;
- LWLockRelease(OldSerXidLock);
+ LWLockRelease(SerialSLRULock);
}
/*
@@ -920,7 +920,7 @@ OldSerXidAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo)
* will be returned.
*/
static SerCommitSeqNo
-OldSerXidGetMinConflictCommitSeqNo(TransactionId xid)
+SerialGetMinConflictCommitSeqNo(TransactionId xid)
{
TransactionId headXid;
TransactionId tailXid;
@@ -929,10 +929,10 @@ OldSerXidGetMinConflictCommitSeqNo(TransactionId xid)
Assert(TransactionIdIsValid(xid));
- LWLockAcquire(OldSerXidLock, LW_SHARED);
- headXid = oldSerXidControl->headXid;
- tailXid = oldSerXidControl->tailXid;
- LWLockRelease(OldSerXidLock);
+ LWLockAcquire(SerialSLRULock, LW_SHARED);
+ headXid = serialControl->headXid;
+ tailXid = serialControl->tailXid;
+ LWLockRelease(SerialSLRULock);
if (!TransactionIdIsValid(headXid))
return 0;
@@ -944,13 +944,13 @@ OldSerXidGetMinConflictCommitSeqNo(TransactionId xid)
return 0;
/*
- * The following function must be called without holding OldSerXidLock,
+ * The following function must be called without holding SerialSLRULock,
* but will return with that lock held, which must then be released.
*/
- slotno = SimpleLruReadPage_ReadOnly(OldSerXidSlruCtl,
- OldSerXidPage(xid), xid);
- val = OldSerXidValue(slotno, xid);
- LWLockRelease(OldSerXidLock);
+ slotno = SimpleLruReadPage_ReadOnly(SerialSlruCtl,
+ SerialPage(xid), xid);
+ val = SerialValue(slotno, xid);
+ LWLockRelease(SerialSLRULock);
return val;
}
@@ -961,9 +961,9 @@ OldSerXidGetMinConflictCommitSeqNo(TransactionId xid)
* the SLRU can be discarded.
*/
static void
-OldSerXidSetActiveSerXmin(TransactionId xid)
+SerialSetActiveSerXmin(TransactionId xid)
{
- LWLockAcquire(OldSerXidLock, LW_EXCLUSIVE);
+ LWLockAcquire(SerialSLRULock, LW_EXCLUSIVE);
/*
* When no sxacts are active, nothing overlaps, set the xid values to
@@ -973,9 +973,9 @@ OldSerXidSetActiveSerXmin(TransactionId xid)
*/
if (!TransactionIdIsValid(xid))
{
- oldSerXidControl->tailXid = InvalidTransactionId;
- oldSerXidControl->headXid = InvalidTransactionId;
- LWLockRelease(OldSerXidLock);
+ serialControl->tailXid = InvalidTransactionId;
+ serialControl->headXid = InvalidTransactionId;
+ LWLockRelease(SerialSLRULock);
return;
}
@@ -987,22 +987,22 @@ OldSerXidSetActiveSerXmin(TransactionId xid)
*/
if (RecoveryInProgress())
{
- Assert(oldSerXidControl->headPage < 0);
- if (!TransactionIdIsValid(oldSerXidControl->tailXid)
- || TransactionIdPrecedes(xid, oldSerXidControl->tailXid))
+ Assert(serialControl->headPage < 0);
+ if (!TransactionIdIsValid(serialControl->tailXid)
+ || TransactionIdPrecedes(xid, serialControl->tailXid))
{
- oldSerXidControl->tailXid = xid;
+ serialControl->tailXid = xid;
}
- LWLockRelease(OldSerXidLock);
+ LWLockRelease(SerialSLRULock);
return;
}
- Assert(!TransactionIdIsValid(oldSerXidControl->tailXid)
- || TransactionIdFollows(xid, oldSerXidControl->tailXid));
+ Assert(!TransactionIdIsValid(serialControl->tailXid)
+ || TransactionIdFollows(xid, serialControl->tailXid));
- oldSerXidControl->tailXid = xid;
+ serialControl->tailXid = xid;
- LWLockRelease(OldSerXidLock);
+ LWLockRelease(SerialSLRULock);
}
/*
@@ -1016,19 +1016,19 @@ CheckPointPredicate(void)
{
int tailPage;
- LWLockAcquire(OldSerXidLock, LW_EXCLUSIVE);
+ LWLockAcquire(SerialSLRULock, LW_EXCLUSIVE);
/* Exit quickly if the SLRU is currently not in use. */
- if (oldSerXidControl->headPage < 0)
+ if (serialControl->headPage < 0)
{
- LWLockRelease(OldSerXidLock);
+ LWLockRelease(SerialSLRULock);
return;
}
- if (TransactionIdIsValid(oldSerXidControl->tailXid))
+ if (TransactionIdIsValid(serialControl->tailXid))
{
/* We can truncate the SLRU up to the page containing tailXid */
- tailPage = OldSerXidPage(oldSerXidControl->tailXid);
+ tailPage = SerialPage(serialControl->tailXid);
}
else
{
@@ -1042,14 +1042,14 @@ CheckPointPredicate(void)
* won't be removed until XID horizon advances enough to make it
* current again.
*/
- tailPage = oldSerXidControl->headPage;
- oldSerXidControl->headPage = -1;
+ tailPage = serialControl->headPage;
+ serialControl->headPage = -1;
}
- LWLockRelease(OldSerXidLock);
+ LWLockRelease(SerialSLRULock);
/* Truncate away pages that are no longer required */
- SimpleLruTruncate(OldSerXidSlruCtl, tailPage);
+ SimpleLruTruncate(SerialSlruCtl, tailPage);
/*
* Flush dirty SLRU pages to disk
@@ -1061,7 +1061,7 @@ CheckPointPredicate(void)
* before deleting the file in which they sit, which would be completely
* pointless.
*/
- SimpleLruFlush(OldSerXidSlruCtl, true);
+ SimpleLruFlush(SerialSlruCtl, true);
}
/*------------------------------------------------------------------------*/
@@ -1275,7 +1275,7 @@ InitPredicateLocks(void)
* Initialize the SLRU storage for old committed serializable
* transactions.
*/
- OldSerXidInit();
+ SerialInit();
}
/*
@@ -1324,8 +1324,8 @@ PredicateLockShmemSize(void)
size = add_size(size, sizeof(SHM_QUEUE));
/* Shared memory structures for SLRU tracking of old committed xids. */
- size = add_size(size, sizeof(OldSerXidControlData));
- size = add_size(size, SimpleLruShmemSize(NUM_OLDSERXID_BUFFERS, 0));
+ size = add_size(size, sizeof(SerialControlData));
+ size = add_size(size, SimpleLruShmemSize(NUM_SERIAL_BUFFERS, 0));
return size;
}
@@ -1462,8 +1462,8 @@ SummarizeOldestCommittedSxact(void)
/* Add to SLRU summary information. */
if (TransactionIdIsValid(sxact->topXid) && !SxactIsReadOnly(sxact))
- OldSerXidAdd(sxact->topXid, SxactHasConflictOut(sxact)
- ? sxact->SeqNo.earliestOutConflictCommit : InvalidSerCommitSeqNo);
+ SerialAdd(sxact->topXid, SxactHasConflictOut(sxact)
+ ? sxact->SeqNo.earliestOutConflictCommit : InvalidSerCommitSeqNo);
/* Summarize and release the detail. */
ReleaseOneSerializableXact(sxact, false, true);
@@ -1727,7 +1727,7 @@ GetSerializableTransactionSnapshotInt(Snapshot snapshot,
* (in particular, an elog(ERROR) in procarray.c would cause us to leak
* the sxact). Consider refactoring to avoid this.
*/
-#ifdef TEST_OLDSERXID
+#ifdef TEST_SUMMARIZE_SERIAL
SummarizeOldestCommittedSxact();
#endif
LWLockAcquire(SerializableXactHashLock, LW_EXCLUSIVE);
@@ -1782,7 +1782,7 @@ GetSerializableTransactionSnapshotInt(Snapshot snapshot,
Assert(PredXact->SxactGlobalXminCount == 0);
PredXact->SxactGlobalXmin = snapshot->xmin;
PredXact->SxactGlobalXminCount = 1;
- OldSerXidSetActiveSerXmin(snapshot->xmin);
+ SerialSetActiveSerXmin(snapshot->xmin);
}
else if (TransactionIdEquals(snapshot->xmin, PredXact->SxactGlobalXmin))
{
@@ -3231,7 +3231,7 @@ SetNewSxactGlobalXmin(void)
}
}
- OldSerXidSetActiveSerXmin(PredXact->SxactGlobalXmin);
+ SerialSetActiveSerXmin(PredXact->SxactGlobalXmin);
}
/*
@@ -4084,7 +4084,7 @@ CheckForSerializableConflictOut(Relation relation, TransactionId xid, Snapshot s
*/
SerCommitSeqNo conflictCommitSeqNo;
- conflictCommitSeqNo = OldSerXidGetMinConflictCommitSeqNo(xid);
+ conflictCommitSeqNo = SerialGetMinConflictCommitSeqNo(xid);
if (conflictCommitSeqNo != 0)
{
if (conflictCommitSeqNo != InvalidSerCommitSeqNo
@@ -5069,7 +5069,7 @@ predicatelock_twophase_recover(TransactionId xid, uint16 info,
{
PredXact->SxactGlobalXmin = sxact->xmin;
PredXact->SxactGlobalXminCount = 1;
- OldSerXidSetActiveSerXmin(sxact->xmin);
+ SerialSetActiveSerXmin(sxact->xmin);
}
else if (TransactionIdEquals(sxact->xmin, PredXact->SxactGlobalXmin))
{