aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/clog.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/access/transam/clog.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/access/transam/clog.c')
-rw-r--r--src/backend/access/transam/clog.c116
1 files changed, 58 insertions, 58 deletions
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index f8e7670f8da..23bc1f8d4c1 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -83,9 +83,9 @@
/*
* Link to shared-memory data structures for CLOG control
*/
-static SlruCtlData ClogCtlData;
+static SlruCtlData XactCtlData;
-#define ClogCtl (&ClogCtlData)
+#define XactCtl (&XactCtlData)
static int ZeroCLOGPage(int pageno, bool writeXlog);
@@ -280,10 +280,10 @@ TransactionIdSetPageStatus(TransactionId xid, int nsubxids,
"group clog threshold less than PGPROC cached subxids");
/*
- * When there is contention on CLogControlLock, we try to group multiple
+ * When there is contention on XactSLRULock, we try to group multiple
* updates; a single leader process will perform transaction status
- * updates for multiple backends so that the number of times
- * CLogControlLock needs to be acquired is reduced.
+ * updates for multiple backends so that the number of times XactSLRULock
+ * needs to be acquired is reduced.
*
* For this optimization to be safe, the XID in MyPgXact and the subxids
* in MyProc must be the same as the ones for which we're setting the
@@ -300,17 +300,17 @@ TransactionIdSetPageStatus(TransactionId xid, int nsubxids,
nsubxids * sizeof(TransactionId)) == 0)
{
/*
- * If we can immediately acquire CLogControlLock, we update the status
- * of our own XID and release the lock. If not, try use group XID
+ * If we can immediately acquire XactSLRULock, we update the status of
+ * our own XID and release the lock. If not, try use group XID
* update. If that doesn't work out, fall back to waiting for the
* lock to perform an update for this transaction only.
*/
- if (LWLockConditionalAcquire(CLogControlLock, LW_EXCLUSIVE))
+ if (LWLockConditionalAcquire(XactSLRULock, LW_EXCLUSIVE))
{
/* Got the lock without waiting! Do the update. */
TransactionIdSetPageStatusInternal(xid, nsubxids, subxids, status,
lsn, pageno);
- LWLockRelease(CLogControlLock);
+ LWLockRelease(XactSLRULock);
return;
}
else if (TransactionGroupUpdateXidStatus(xid, status, lsn, pageno))
@@ -323,10 +323,10 @@ TransactionIdSetPageStatus(TransactionId xid, int nsubxids,
}
/* Group update not applicable, or couldn't accept this page number. */
- LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
+ LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
TransactionIdSetPageStatusInternal(xid, nsubxids, subxids, status,
lsn, pageno);
- LWLockRelease(CLogControlLock);
+ LWLockRelease(XactSLRULock);
}
/*
@@ -345,7 +345,7 @@ TransactionIdSetPageStatusInternal(TransactionId xid, int nsubxids,
Assert(status == TRANSACTION_STATUS_COMMITTED ||
status == TRANSACTION_STATUS_ABORTED ||
(status == TRANSACTION_STATUS_SUB_COMMITTED && !TransactionIdIsValid(xid)));
- Assert(LWLockHeldByMeInMode(CLogControlLock, LW_EXCLUSIVE));
+ Assert(LWLockHeldByMeInMode(XactSLRULock, LW_EXCLUSIVE));
/*
* If we're doing an async commit (ie, lsn is valid), then we must wait
@@ -356,7 +356,7 @@ TransactionIdSetPageStatusInternal(TransactionId xid, int nsubxids,
* write-busy, since we don't care if the update reaches disk sooner than
* we think.
*/
- slotno = SimpleLruReadPage(ClogCtl, pageno, XLogRecPtrIsInvalid(lsn), xid);
+ slotno = SimpleLruReadPage(XactCtl, pageno, XLogRecPtrIsInvalid(lsn), xid);
/*
* Set the main transaction id, if any.
@@ -374,7 +374,7 @@ TransactionIdSetPageStatusInternal(TransactionId xid, int nsubxids,
{
for (i = 0; i < nsubxids; i++)
{
- Assert(ClogCtl->shared->page_number[slotno] == TransactionIdToPage(subxids[i]));
+ Assert(XactCtl->shared->page_number[slotno] == TransactionIdToPage(subxids[i]));
TransactionIdSetStatusBit(subxids[i],
TRANSACTION_STATUS_SUB_COMMITTED,
lsn, slotno);
@@ -388,20 +388,20 @@ TransactionIdSetPageStatusInternal(TransactionId xid, int nsubxids,
/* Set the subtransactions */
for (i = 0; i < nsubxids; i++)
{
- Assert(ClogCtl->shared->page_number[slotno] == TransactionIdToPage(subxids[i]));
+ Assert(XactCtl->shared->page_number[slotno] == TransactionIdToPage(subxids[i]));
TransactionIdSetStatusBit(subxids[i], status, lsn, slotno);
}
- ClogCtl->shared->page_dirty[slotno] = true;
+ XactCtl->shared->page_dirty[slotno] = true;
}
/*
- * When we cannot immediately acquire CLogControlLock in exclusive mode at
+ * When we cannot immediately acquire XactSLRULock in exclusive mode at
* commit time, add ourselves to a list of processes that need their XIDs
* status update. The first process to add itself to the list will acquire
- * CLogControlLock in exclusive mode and set transaction status as required
+ * XactSLRULock in exclusive mode and set transaction status as required
* on behalf of all group members. This avoids a great deal of contention
- * around CLogControlLock when many processes are trying to commit at once,
+ * around XactSLRULock when many processes are trying to commit at once,
* since the lock need not be repeatedly handed off from one committing
* process to the next.
*
@@ -493,7 +493,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
}
/* We are the leader. Acquire the lock on behalf of everyone. */
- LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
+ LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
/*
* Now that we've got the lock, clear the list of processes waiting for
@@ -530,7 +530,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
}
/* We're done with the lock now. */
- LWLockRelease(CLogControlLock);
+ LWLockRelease(XactSLRULock);
/*
* Now that we've released the lock, go back and wake everybody up. We
@@ -559,7 +559,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
/*
* Sets the commit status of a single transaction.
*
- * Must be called with CLogControlLock held
+ * Must be called with XactSLRULock held
*/
static void
TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, int slotno)
@@ -570,7 +570,7 @@ TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, i
char byteval;
char curval;
- byteptr = ClogCtl->shared->page_buffer[slotno] + byteno;
+ byteptr = XactCtl->shared->page_buffer[slotno] + byteno;
curval = (*byteptr >> bshift) & CLOG_XACT_BITMASK;
/*
@@ -610,8 +610,8 @@ TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, i
{
int lsnindex = GetLSNIndex(slotno, xid);
- if (ClogCtl->shared->group_lsn[lsnindex] < lsn)
- ClogCtl->shared->group_lsn[lsnindex] = lsn;
+ if (XactCtl->shared->group_lsn[lsnindex] < lsn)
+ XactCtl->shared->group_lsn[lsnindex] = lsn;
}
}
@@ -643,15 +643,15 @@ TransactionIdGetStatus(TransactionId xid, XLogRecPtr *lsn)
/* lock is acquired by SimpleLruReadPage_ReadOnly */
- slotno = SimpleLruReadPage_ReadOnly(ClogCtl, pageno, xid);
- byteptr = ClogCtl->shared->page_buffer[slotno] + byteno;
+ slotno = SimpleLruReadPage_ReadOnly(XactCtl, pageno, xid);
+ byteptr = XactCtl->shared->page_buffer[slotno] + byteno;
status = (*byteptr >> bshift) & CLOG_XACT_BITMASK;
lsnindex = GetLSNIndex(slotno, xid);
- *lsn = ClogCtl->shared->group_lsn[lsnindex];
+ *lsn = XactCtl->shared->group_lsn[lsnindex];
- LWLockRelease(CLogControlLock);
+ LWLockRelease(XactSLRULock);
return status;
}
@@ -690,9 +690,9 @@ CLOGShmemSize(void)
void
CLOGShmemInit(void)
{
- ClogCtl->PagePrecedes = CLOGPagePrecedes;
- SimpleLruInit(ClogCtl, "clog", CLOGShmemBuffers(), CLOG_LSNS_PER_PAGE,
- CLogControlLock, "pg_xact", LWTRANCHE_CLOG_BUFFERS);
+ XactCtl->PagePrecedes = CLOGPagePrecedes;
+ SimpleLruInit(XactCtl, "Xact", CLOGShmemBuffers(), CLOG_LSNS_PER_PAGE,
+ XactSLRULock, "pg_xact", LWTRANCHE_XACT_BUFFER);
}
/*
@@ -706,16 +706,16 @@ BootStrapCLOG(void)
{
int slotno;
- LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
+ LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
/* Create and zero the first page of the commit log */
slotno = ZeroCLOGPage(0, false);
/* Make sure it's written out */
- SimpleLruWritePage(ClogCtl, slotno);
- Assert(!ClogCtl->shared->page_dirty[slotno]);
+ SimpleLruWritePage(XactCtl, slotno);
+ Assert(!XactCtl->shared->page_dirty[slotno]);
- LWLockRelease(CLogControlLock);
+ LWLockRelease(XactSLRULock);
}
/*
@@ -732,7 +732,7 @@ ZeroCLOGPage(int pageno, bool writeXlog)
{
int slotno;
- slotno = SimpleLruZeroPage(ClogCtl, pageno);
+ slotno = SimpleLruZeroPage(XactCtl, pageno);
if (writeXlog)
WriteZeroPageXlogRec(pageno);
@@ -750,14 +750,14 @@ StartupCLOG(void)
TransactionId xid = XidFromFullTransactionId(ShmemVariableCache->nextFullXid);
int pageno = TransactionIdToPage(xid);
- LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
+ LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
/*
* Initialize our idea of the latest page number.
*/
- ClogCtl->shared->latest_page_number = pageno;
+ XactCtl->shared->latest_page_number = pageno;
- LWLockRelease(CLogControlLock);
+ LWLockRelease(XactSLRULock);
}
/*
@@ -769,12 +769,12 @@ TrimCLOG(void)
TransactionId xid = XidFromFullTransactionId(ShmemVariableCache->nextFullXid);
int pageno = TransactionIdToPage(xid);
- LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
+ LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
/*
* Re-Initialize our idea of the latest page number.
*/
- ClogCtl->shared->latest_page_number = pageno;
+ XactCtl->shared->latest_page_number = pageno;
/*
* Zero out the remainder of the current clog page. Under normal
@@ -795,18 +795,18 @@ TrimCLOG(void)
int slotno;
char *byteptr;
- slotno = SimpleLruReadPage(ClogCtl, pageno, false, xid);
- byteptr = ClogCtl->shared->page_buffer[slotno] + byteno;
+ slotno = SimpleLruReadPage(XactCtl, pageno, false, xid);
+ byteptr = XactCtl->shared->page_buffer[slotno] + byteno;
/* Zero so-far-unused positions in the current byte */
*byteptr &= (1 << bshift) - 1;
/* Zero the rest of the page */
MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1);
- ClogCtl->shared->page_dirty[slotno] = true;
+ XactCtl->shared->page_dirty[slotno] = true;
}
- LWLockRelease(CLogControlLock);
+ LWLockRelease(XactSLRULock);
}
/*
@@ -817,7 +817,7 @@ ShutdownCLOG(void)
{
/* Flush dirty CLOG pages to disk */
TRACE_POSTGRESQL_CLOG_CHECKPOINT_START(false);
- SimpleLruFlush(ClogCtl, false);
+ SimpleLruFlush(XactCtl, false);
/*
* fsync pg_xact to ensure that any files flushed previously are durably
@@ -836,7 +836,7 @@ CheckPointCLOG(void)
{
/* Flush dirty CLOG pages to disk */
TRACE_POSTGRESQL_CLOG_CHECKPOINT_START(true);
- SimpleLruFlush(ClogCtl, true);
+ SimpleLruFlush(XactCtl, true);
/*
* fsync pg_xact to ensure that any files flushed previously are durably
@@ -871,12 +871,12 @@ ExtendCLOG(TransactionId newestXact)
pageno = TransactionIdToPage(newestXact);
- LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
+ LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
/* Zero the page and make an XLOG entry about it */
ZeroCLOGPage(pageno, true);
- LWLockRelease(CLogControlLock);
+ LWLockRelease(XactSLRULock);
}
@@ -907,7 +907,7 @@ TruncateCLOG(TransactionId oldestXact, Oid oldestxid_datoid)
cutoffPage = TransactionIdToPage(oldestXact);
/* Check to see if there's any files that could be removed */
- if (!SlruScanDirectory(ClogCtl, SlruScanDirCbReportPresence, &cutoffPage))
+ if (!SlruScanDirectory(XactCtl, SlruScanDirCbReportPresence, &cutoffPage))
return; /* nothing to remove */
/*
@@ -928,7 +928,7 @@ TruncateCLOG(TransactionId oldestXact, Oid oldestxid_datoid)
WriteTruncateXlogRec(cutoffPage, oldestXact, oldestxid_datoid);
/* Now we can remove the old CLOG segment(s) */
- SimpleLruTruncate(ClogCtl, cutoffPage);
+ SimpleLruTruncate(XactCtl, cutoffPage);
}
@@ -1007,13 +1007,13 @@ clog_redo(XLogReaderState *record)
memcpy(&pageno, XLogRecGetData(record), sizeof(int));
- LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
+ LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
slotno = ZeroCLOGPage(pageno, false);
- SimpleLruWritePage(ClogCtl, slotno);
- Assert(!ClogCtl->shared->page_dirty[slotno]);
+ SimpleLruWritePage(XactCtl, slotno);
+ Assert(!XactCtl->shared->page_dirty[slotno]);
- LWLockRelease(CLogControlLock);
+ LWLockRelease(XactSLRULock);
}
else if (info == CLOG_TRUNCATE)
{
@@ -1025,11 +1025,11 @@ clog_redo(XLogReaderState *record)
* During XLOG replay, latest_page_number isn't set up yet; insert a
* suitable value to bypass the sanity test in SimpleLruTruncate.
*/
- ClogCtl->shared->latest_page_number = xlrec.pageno;
+ XactCtl->shared->latest_page_number = xlrec.pageno;
AdvanceOldestClogXid(xlrec.oldestXact);
- SimpleLruTruncate(ClogCtl, xlrec.pageno);
+ SimpleLruTruncate(XactCtl, xlrec.pageno);
}
else
elog(PANIC, "clog_redo: unknown op code %u", info);