Skip to content

Commit 7ac02d9

Browse files
committed
Use correct LSN in GetPage@LSN calls when nothing has been evicted yet.
If no page has been evicted from page cache yet, use the latest flushed LSN. Commit 153dee9, "Request special lsn during bootstrap", changed this but it is not clear to me why. As far as I can see, this isn't related to bootstrapping, and using the latest flushed LSN should always work. While we're at it, rearrange the code slightly for readability, and add comments.
1 parent c240903 commit 7ac02d9

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/backend/storage/smgr/pagestore_smgr.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,21 +337,32 @@ zenith_get_request_lsn(bool nonrel)
337337
}
338338
else
339339
{
340-
lsn = GetLastWrittenPageLSN();
340+
XLogRecPtr flushlsn = GetFlushRecPtr();
341341

342+
/*
343+
* Use the latest LSN that was evicted from the buffer cache. Any
344+
* pages modified by later WAL records must still in the buffer cache,
345+
* so our request cannot concern those.
346+
*/
347+
lsn = GetLastWrittenPageLSN();
342348
elog(DEBUG1, "zenith_get_request_lsn GetLastWrittenPageLSN lsn %X/%X ",
343349
(uint32) ((lsn) >> 32), (uint32) (lsn));
344-
345-
if (lsn > GetFlushRecPtr())
346-
XLogFlush(lsn);
347350
if (lsn == InvalidXLogRecPtr)
348351
{
349-
/* we haven't evicted anything yet since the server was started */
350-
lsn = GetFlushRecPtr();
351-
elog(DEBUG1, "zenith_get_request_lsn GetFlushRecPtr lsn %X/%X request 0",
352-
(uint32) ((lsn) >> 32), (uint32) (lsn));
353-
lsn = InvalidXLogRecPtr;
352+
/*
353+
* We haven't evicted anything yet since the server was
354+
* started. Then just use the latest flushed LSN. That's always
355+
* safe, using the latest evicted LSN is really just an
356+
* optimization.
357+
*/
358+
lsn = flushlsn;
359+
elog(DEBUG1, "zenith_get_request_lsn GetFlushRecPtr lsn %X/%X",
360+
(uint32) ((lsn) >> 32), (uint32) (lsn));
354361
}
362+
363+
/* The record should've been flushed already, since it was evicted, but let's be safe */
364+
if (lsn > flushlsn)
365+
XLogFlush(lsn);
355366
}
356367
return lsn;
357368
}

0 commit comments

Comments
 (0)