Skip to content

Commit a2b0229

Browse files
committed
Use XLogRecPtrIsValid() in various places
Now that commit 06edbed has introduced XLogRecPtrIsValid(), we can use that instead of: - XLogRecPtrIsInvalid() - direct comparisons with InvalidXLogRecPtr - direct comparisons with literal 0 This makes the code more consistent. Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/aQB7EvGqrbZXrMlg@ip-10-97-1-34.eu-west-3.compute.internal
1 parent 06edbed commit a2b0229

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+239
-238
lines changed

contrib/pg_walinspect/pg_walinspect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ GetCurrentLSN(void)
8383
else
8484
curr_lsn = GetXLogReplayRecPtr(NULL);
8585

86-
Assert(!XLogRecPtrIsInvalid(curr_lsn));
86+
Assert(XLogRecPtrIsValid(curr_lsn));
8787

8888
return curr_lsn;
8989
}
@@ -127,7 +127,7 @@ InitXLogReaderState(XLogRecPtr lsn)
127127
/* first find a valid recptr to start from */
128128
first_valid_record = XLogFindNextRecord(xlogreader, lsn);
129129

130-
if (XLogRecPtrIsInvalid(first_valid_record))
130+
if (!XLogRecPtrIsValid(first_valid_record))
131131
ereport(ERROR,
132132
errmsg("could not find a valid record after %X/%08X",
133133
LSN_FORMAT_ARGS(lsn)));

src/backend/access/gist/gist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ gistdoinsert(Relation r, IndexTuple itup, Size freespace,
682682
state.stack = stack = stack->parent;
683683
}
684684

685-
if (XLogRecPtrIsInvalid(stack->lsn))
685+
if (!XLogRecPtrIsValid(stack->lsn))
686686
stack->buffer = ReadBuffer(state.r, stack->blkno);
687687

688688
/*
@@ -698,7 +698,7 @@ gistdoinsert(Relation r, IndexTuple itup, Size freespace,
698698
stack->page = BufferGetPage(stack->buffer);
699699
stack->lsn = xlocked ?
700700
PageGetLSN(stack->page) : BufferGetLSNAtomic(stack->buffer);
701-
Assert(!RelationNeedsWAL(state.r) || !XLogRecPtrIsInvalid(stack->lsn));
701+
Assert(!RelationNeedsWAL(state.r) || XLogRecPtrIsValid(stack->lsn));
702702

703703
/*
704704
* If this page was split but the downlink was never inserted to the

src/backend/access/gist/gistget.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ gistkillitems(IndexScanDesc scan)
4646
bool killedsomething = false;
4747

4848
Assert(so->curBlkno != InvalidBlockNumber);
49-
Assert(!XLogRecPtrIsInvalid(so->curPageLSN));
49+
Assert(XLogRecPtrIsValid(so->curPageLSN));
5050
Assert(so->killedItems != NULL);
5151

5252
buffer = ReadBuffer(scan->indexRelation, so->curBlkno);
@@ -353,7 +353,7 @@ gistScanPage(IndexScanDesc scan, GISTSearchItem *pageItem,
353353
* parentlsn < nsn), or if the system crashed after a page split but
354354
* before the downlink was inserted into the parent.
355355
*/
356-
if (!XLogRecPtrIsInvalid(pageItem->data.parentlsn) &&
356+
if (XLogRecPtrIsValid(pageItem->data.parentlsn) &&
357357
(GistFollowRight(page) ||
358358
pageItem->data.parentlsn < GistPageGetNSN(page)) &&
359359
opaque->rightlink != InvalidBlockNumber /* sanity check */ )

src/backend/access/gist/gistutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ gistGetFakeLSN(Relation rel)
10401040
Assert(!RelationNeedsWAL(rel));
10411041

10421042
/* No need for an actual record if we already have a distinct LSN */
1043-
if (!XLogRecPtrIsInvalid(lastlsn) && lastlsn == currlsn)
1043+
if (XLogRecPtrIsValid(lastlsn) && lastlsn == currlsn)
10441044
currlsn = gistXLogAssignLSN();
10451045

10461046
lastlsn = currlsn;

src/backend/access/heap/rewriteheap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ CheckPointLogicalRewriteHeap(void)
11691169
cutoff = ReplicationSlotsComputeLogicalRestartLSN();
11701170

11711171
/* don't start earlier than the restart lsn */
1172-
if (cutoff != InvalidXLogRecPtr && redo < cutoff)
1172+
if (XLogRecPtrIsValid(cutoff) && redo < cutoff)
11731173
cutoff = redo;
11741174

11751175
mappings_dir = AllocateDir(PG_LOGICAL_MAPPINGS_DIR);
@@ -1204,7 +1204,7 @@ CheckPointLogicalRewriteHeap(void)
12041204

12051205
lsn = ((uint64) hi) << 32 | lo;
12061206

1207-
if (lsn < cutoff || cutoff == InvalidXLogRecPtr)
1207+
if (lsn < cutoff || !XLogRecPtrIsValid(cutoff))
12081208
{
12091209
elog(DEBUG1, "removing logical rewrite file \"%s\"", path);
12101210
if (unlink(path) < 0)

src/backend/access/heap/vacuumlazy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ lazy_scan_new_or_empty(LVRelState *vacrel, Buffer buf, BlockNumber blkno,
19011901
* WAL-logged, and if not, do that now.
19021902
*/
19031903
if (RelationNeedsWAL(vacrel->rel) &&
1904-
PageGetLSN(page) == InvalidXLogRecPtr)
1904+
!XLogRecPtrIsValid(PageGetLSN(page)))
19051905
log_newpage_buffer(buf, true);
19061906

19071907
PageSetAllVisible(page);

src/backend/access/heap/visibilitymap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
260260
flags, RelationGetRelationName(rel), heapBlk);
261261
#endif
262262

263-
Assert(InRecovery || XLogRecPtrIsInvalid(recptr));
263+
Assert(InRecovery || !XLogRecPtrIsValid(recptr));
264264
Assert(InRecovery || PageIsAllVisible(BufferGetPage(heapBuf)));
265265
Assert((flags & VISIBILITYMAP_VALID_BITS) == flags);
266266

@@ -292,7 +292,7 @@ visibilitymap_set(Relation rel, BlockNumber heapBlk, Buffer heapBuf,
292292

293293
if (RelationNeedsWAL(rel))
294294
{
295-
if (XLogRecPtrIsInvalid(recptr))
295+
if (!XLogRecPtrIsValid(recptr))
296296
{
297297
Assert(!InRecovery);
298298
recptr = log_heap_visible(rel, heapBuf, vmBuf, cutoff_xid, flags);

src/backend/access/transam/clog.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ TransactionIdSetPageStatusInternal(TransactionId xid, int nsubxids,
381381
* write-busy, since we don't care if the update reaches disk sooner than
382382
* we think.
383383
*/
384-
slotno = SimpleLruReadPage(XactCtl, pageno, XLogRecPtrIsInvalid(lsn), xid);
384+
slotno = SimpleLruReadPage(XactCtl, pageno, !XLogRecPtrIsValid(lsn),
385+
xid);
385386

386387
/*
387388
* Set the main transaction id, if any.
@@ -705,7 +706,7 @@ TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, i
705706
* recovery. After recovery completes the next clog change will set the
706707
* LSN correctly.
707708
*/
708-
if (!XLogRecPtrIsInvalid(lsn))
709+
if (XLogRecPtrIsValid(lsn))
709710
{
710711
int lsnindex = GetLSNIndex(slotno, xid);
711712

src/backend/access/transam/slru.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int64 pageno, int slotno, SlruWriteAll fdata)
937937
max_lsn = this_lsn;
938938
}
939939

940-
if (!XLogRecPtrIsInvalid(max_lsn))
940+
if (XLogRecPtrIsValid(max_lsn))
941941
{
942942
/*
943943
* As noted above, elog(ERROR) is not acceptable here, so if

src/backend/access/transam/timeline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ tliOfPointInHistory(XLogRecPtr ptr, List *history)
549549
{
550550
TimeLineHistoryEntry *tle = (TimeLineHistoryEntry *) lfirst(cell);
551551

552-
if ((XLogRecPtrIsInvalid(tle->begin) || tle->begin <= ptr) &&
553-
(XLogRecPtrIsInvalid(tle->end) || ptr < tle->end))
552+
if ((!XLogRecPtrIsValid(tle->begin) || tle->begin <= ptr) &&
553+
(!XLogRecPtrIsValid(tle->end) || ptr < tle->end))
554554
{
555555
/* found it */
556556
return tle->tli;

0 commit comments

Comments
 (0)