Skip to content

Commit

Permalink
Rename ShmemVariableCache to TransamVariables
Browse files Browse the repository at this point in the history
The old name was misleading: It's not a cache, the values kept in the
struct are the authoritative source.

Reviewed-by: Tristan Partin, Richard Guo
Discussion: https://www.postgresql.org/message-id/6537d63d-4bb5-46f8-9b5d-73a8ba4720ab@iki.fi
  • Loading branch information
hlinnaka committed Dec 8, 2023
1 parent 15916ff commit b31ba53
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 175 deletions.
14 changes: 7 additions & 7 deletions contrib/amcheck/verify_heapam.c
Expand Up @@ -81,12 +81,12 @@ typedef struct ToastedAttribute
typedef struct HeapCheckContext
{
/*
* Cached copies of values from ShmemVariableCache and computed values
* from them.
* Cached copies of values from TransamVariables and computed values from
* them.
*/
FullTransactionId next_fxid; /* ShmemVariableCache->nextXid */
FullTransactionId next_fxid; /* TransamVariables->nextXid */
TransactionId next_xid; /* 32-bit version of next_fxid */
TransactionId oldest_xid; /* ShmemVariableCache->oldestXid */
TransactionId oldest_xid; /* TransamVariables->oldestXid */
FullTransactionId oldest_fxid; /* 64-bit version of oldest_xid, computed
* relative to next_fxid */
TransactionId safe_xmin; /* this XID and newer ones can't become
Expand Down Expand Up @@ -1924,8 +1924,8 @@ update_cached_xid_range(HeapCheckContext *ctx)
{
/* Make cached copies */
LWLockAcquire(XidGenLock, LW_SHARED);
ctx->next_fxid = ShmemVariableCache->nextXid;
ctx->oldest_xid = ShmemVariableCache->oldestXid;
ctx->next_fxid = TransamVariables->nextXid;
ctx->oldest_xid = TransamVariables->oldestXid;
LWLockRelease(XidGenLock);

/* And compute alternate versions of the same */
Expand Down Expand Up @@ -2062,7 +2062,7 @@ get_xid_status(TransactionId xid, HeapCheckContext *ctx,
*status = XID_COMMITTED;
LWLockAcquire(XactTruncationLock, LW_SHARED);
clog_horizon =
FullTransactionIdFromXidAndCtx(ShmemVariableCache->oldestClogXid,
FullTransactionIdFromXidAndCtx(TransamVariables->oldestClogXid,
ctx);
if (FullTransactionIdPrecedesOrEquals(clog_horizon, fxid))
{
Expand Down
6 changes: 3 additions & 3 deletions src/backend/access/transam/clog.c
Expand Up @@ -758,12 +758,12 @@ ZeroCLOGPage(int64 pageno, bool writeXlog)

/*
* This must be called ONCE during postmaster or standalone-backend startup,
* after StartupXLOG has initialized ShmemVariableCache->nextXid.
* after StartupXLOG has initialized TransamVariables->nextXid.
*/
void
StartupCLOG(void)
{
TransactionId xid = XidFromFullTransactionId(ShmemVariableCache->nextXid);
TransactionId xid = XidFromFullTransactionId(TransamVariables->nextXid);
int64 pageno = TransactionIdToPage(xid);

LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
Expand All @@ -782,7 +782,7 @@ StartupCLOG(void)
void
TrimCLOG(void)
{
TransactionId xid = XidFromFullTransactionId(ShmemVariableCache->nextXid);
TransactionId xid = XidFromFullTransactionId(TransamVariables->nextXid);
int64 pageno = TransactionIdToPage(xid);

LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
Expand Down
44 changes: 22 additions & 22 deletions src/backend/access/transam/commit_ts.c
Expand Up @@ -211,8 +211,8 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids,
commitTsShared->dataLastCommit.nodeid = nodeid;

/* and move forwards our endpoint, if needed */
if (TransactionIdPrecedes(ShmemVariableCache->newestCommitTsXid, newestXact))
ShmemVariableCache->newestCommitTsXid = newestXact;
if (TransactionIdPrecedes(TransamVariables->newestCommitTsXid, newestXact))
TransamVariables->newestCommitTsXid = newestXact;
LWLockRelease(CommitTsLock);
}

Expand Down Expand Up @@ -315,8 +315,8 @@ TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts,
return *ts != 0;
}

oldestCommitTsXid = ShmemVariableCache->oldestCommitTsXid;
newestCommitTsXid = ShmemVariableCache->newestCommitTsXid;
oldestCommitTsXid = TransamVariables->oldestCommitTsXid;
newestCommitTsXid = TransamVariables->newestCommitTsXid;
/* neither is invalid, or both are */
Assert(TransactionIdIsValid(oldestCommitTsXid) == TransactionIdIsValid(newestCommitTsXid));
LWLockRelease(CommitTsLock);
Expand Down Expand Up @@ -593,7 +593,7 @@ ZeroCommitTsPage(int64 pageno, bool writeXlog)

/*
* This must be called ONCE during postmaster or standalone-backend startup,
* after StartupXLOG has initialized ShmemVariableCache->nextXid.
* after StartupXLOG has initialized TransamVariables->nextXid.
*/
void
StartupCommitTs(void)
Expand Down Expand Up @@ -683,7 +683,7 @@ ActivateCommitTs(void)
}
LWLockRelease(CommitTsLock);

xid = XidFromFullTransactionId(ShmemVariableCache->nextXid);
xid = XidFromFullTransactionId(TransamVariables->nextXid);
pageno = TransactionIdToCTsPage(xid);

/*
Expand All @@ -707,10 +707,10 @@ ActivateCommitTs(void)
* Invalid temporarily.
*/
LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
if (ShmemVariableCache->oldestCommitTsXid == InvalidTransactionId)
if (TransamVariables->oldestCommitTsXid == InvalidTransactionId)
{
ShmemVariableCache->oldestCommitTsXid =
ShmemVariableCache->newestCommitTsXid = ReadNextTransactionId();
TransamVariables->oldestCommitTsXid =
TransamVariables->newestCommitTsXid = ReadNextTransactionId();
}
LWLockRelease(CommitTsLock);

Expand Down Expand Up @@ -759,8 +759,8 @@ DeactivateCommitTs(void)
TIMESTAMP_NOBEGIN(commitTsShared->dataLastCommit.time);
commitTsShared->dataLastCommit.nodeid = InvalidRepOriginId;

ShmemVariableCache->oldestCommitTsXid = InvalidTransactionId;
ShmemVariableCache->newestCommitTsXid = InvalidTransactionId;
TransamVariables->oldestCommitTsXid = InvalidTransactionId;
TransamVariables->newestCommitTsXid = InvalidTransactionId;

LWLockRelease(CommitTsLock);

Expand Down Expand Up @@ -874,18 +874,18 @@ SetCommitTsLimit(TransactionId oldestXact, TransactionId newestXact)
* "future" or signal a disabled committs.
*/
LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
if (ShmemVariableCache->oldestCommitTsXid != InvalidTransactionId)
if (TransamVariables->oldestCommitTsXid != InvalidTransactionId)
{
if (TransactionIdPrecedes(ShmemVariableCache->oldestCommitTsXid, oldestXact))
ShmemVariableCache->oldestCommitTsXid = oldestXact;
if (TransactionIdPrecedes(newestXact, ShmemVariableCache->newestCommitTsXid))
ShmemVariableCache->newestCommitTsXid = newestXact;
if (TransactionIdPrecedes(TransamVariables->oldestCommitTsXid, oldestXact))
TransamVariables->oldestCommitTsXid = oldestXact;
if (TransactionIdPrecedes(newestXact, TransamVariables->newestCommitTsXid))
TransamVariables->newestCommitTsXid = newestXact;
}
else
{
Assert(ShmemVariableCache->newestCommitTsXid == InvalidTransactionId);
ShmemVariableCache->oldestCommitTsXid = oldestXact;
ShmemVariableCache->newestCommitTsXid = newestXact;
Assert(TransamVariables->newestCommitTsXid == InvalidTransactionId);
TransamVariables->oldestCommitTsXid = oldestXact;
TransamVariables->newestCommitTsXid = newestXact;
}
LWLockRelease(CommitTsLock);
}
Expand All @@ -897,9 +897,9 @@ void
AdvanceOldestCommitTsXid(TransactionId oldestXact)
{
LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
if (ShmemVariableCache->oldestCommitTsXid != InvalidTransactionId &&
TransactionIdPrecedes(ShmemVariableCache->oldestCommitTsXid, oldestXact))
ShmemVariableCache->oldestCommitTsXid = oldestXact;
if (TransamVariables->oldestCommitTsXid != InvalidTransactionId &&
TransactionIdPrecedes(TransamVariables->oldestCommitTsXid, oldestXact))
TransamVariables->oldestCommitTsXid = oldestXact;
LWLockRelease(CommitTsLock);
}

Expand Down
4 changes: 2 additions & 2 deletions src/backend/access/transam/subtrans.c
Expand Up @@ -250,7 +250,7 @@ ZeroSUBTRANSPage(int64 pageno)

/*
* This must be called ONCE during postmaster or standalone-backend startup,
* after StartupXLOG has initialized ShmemVariableCache->nextXid.
* after StartupXLOG has initialized TransamVariables->nextXid.
*
* oldestActiveXID is the oldest XID of any prepared transaction, or nextXid
* if there are none.
Expand All @@ -271,7 +271,7 @@ StartupSUBTRANS(TransactionId oldestActiveXID)
LWLockAcquire(SubtransSLRULock, LW_EXCLUSIVE);

startPage = TransactionIdToPage(oldestActiveXID);
nextXid = ShmemVariableCache->nextXid;
nextXid = TransamVariables->nextXid;
endPage = TransactionIdToPage(XidFromFullTransactionId(nextXid));

while (startPage != endPage)
Expand Down
12 changes: 6 additions & 6 deletions src/backend/access/transam/twophase.c
Expand Up @@ -958,7 +958,7 @@ AdjustToFullTransactionId(TransactionId xid)
Assert(TransactionIdIsValid(xid));

LWLockAcquire(XidGenLock, LW_SHARED);
nextFullXid = ShmemVariableCache->nextXid;
nextFullXid = TransamVariables->nextXid;
LWLockRelease(XidGenLock);

nextXid = XidFromFullTransactionId(nextFullXid);
Expand Down Expand Up @@ -1948,7 +1948,7 @@ restoreTwoPhaseData(void)
*
* Scan the shared memory entries of TwoPhaseState and determine the range
* of valid XIDs present. This is run during database startup, after we
* have completed reading WAL. ShmemVariableCache->nextXid has been set to
* have completed reading WAL. TransamVariables->nextXid has been set to
* one more than the highest XID for which evidence exists in WAL.
*
* We throw away any prepared xacts with main XID beyond nextXid --- if any
Expand All @@ -1967,7 +1967,7 @@ restoreTwoPhaseData(void)
* backup should be rolled in.
*
* Our other responsibility is to determine and return the oldest valid XID
* among the prepared xacts (if none, return ShmemVariableCache->nextXid).
* among the prepared xacts (if none, return TransamVariables->nextXid).
* This is needed to synchronize pg_subtrans startup properly.
*
* If xids_p and nxids_p are not NULL, pointer to a palloc'd array of all
Expand All @@ -1977,7 +1977,7 @@ restoreTwoPhaseData(void)
TransactionId
PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
{
FullTransactionId nextXid = ShmemVariableCache->nextXid;
FullTransactionId nextXid = TransamVariables->nextXid;
TransactionId origNextXid = XidFromFullTransactionId(nextXid);
TransactionId result = origNextXid;
TransactionId *xids = NULL;
Expand Down Expand Up @@ -2196,7 +2196,7 @@ RecoverPreparedTransactions(void)
*
* If setParent is true, set up subtransaction parent linkages.
*
* If setNextXid is true, set ShmemVariableCache->nextXid to the newest
* If setNextXid is true, set TransamVariables->nextXid to the newest
* value scanned.
*/
static char *
Expand All @@ -2205,7 +2205,7 @@ ProcessTwoPhaseBuffer(TransactionId xid,
bool fromdisk,
bool setParent, bool setNextXid)
{
FullTransactionId nextXid = ShmemVariableCache->nextXid;
FullTransactionId nextXid = TransamVariables->nextXid;
TransactionId origNextXid = XidFromFullTransactionId(nextXid);
TransactionId *subxids;
char *buf;
Expand Down

0 comments on commit b31ba53

Please sign in to comment.