mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Refactor some repetitive SLRU code
Functions to bootstrap and zero pages in various SLRU callers were fairly duplicative. We can slash almost two hundred lines with a couple of simple helpers: - SimpleLruZeroAndWritePage: Does the equivalent of SimpleLruZeroPage followed by flushing the page to disk - XLogSimpleInsertInt64: Does a XLogBeginInsert followed by XLogInsert of a trivial record whose data is just an int64. Author: Evgeny Voropaev <evgeny.voropaev@tantorlabs.com> Reviewed by: Álvaro Herrera <alvherre@kurilemu.de> Reviewed by: Andrey Borodin <x4mmm@yandex-team.ru> Reviewed by: Aleksander Alekseev <aleksander@timescale.com> Discussion: https://www.postgresql.org/message-id/flat/97820ce8-a1cd-407f-a02b-47368fadb14b%40tantorlabs.com
This commit is contained in:
@@ -433,6 +433,31 @@ SimpleLruZeroLSNs(SlruCtl ctl, int slotno)
|
||||
shared->lsn_groups_per_page * sizeof(XLogRecPtr));
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a convenience wrapper for the common case of zeroing a page and
|
||||
* immediately flushing it to disk.
|
||||
*
|
||||
* Control lock is acquired and released here.
|
||||
*/
|
||||
void
|
||||
SimpleLruZeroAndWritePage(SlruCtl ctl, int64 pageno)
|
||||
{
|
||||
int slotno;
|
||||
LWLock *lock;
|
||||
|
||||
lock = SimpleLruGetBankLock(ctl, pageno);
|
||||
LWLockAcquire(lock, LW_EXCLUSIVE);
|
||||
|
||||
/* Create and zero the page */
|
||||
slotno = SimpleLruZeroPage(ctl, pageno);
|
||||
|
||||
/* Make sure it's written out */
|
||||
SimpleLruWritePage(ctl, slotno);
|
||||
Assert(!ctl->shared->page_dirty[slotno]);
|
||||
|
||||
LWLockRelease(lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for any active I/O on a page slot to finish. (This does not
|
||||
* guarantee that new I/O hasn't been started before we return, though.
|
||||
|
||||
Reference in New Issue
Block a user