Re: Elimination of the repetitive code at the SLRU bootstrap functions.
Evgeny Voropaev <evgeny.voropaev@tantorlabs.com>
From: Evgeny Voropaev <evgeny.voropaev@tantorlabs.com>
To: Álvaro Herrera <alvherre@alvh.no-ip.org>, x4mmm@yandex-team.ru, aleksander@timescale.com, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2025-02-18T09:02:42Z
Lists: pgsql-hackers
Attachments
- v3-0001-Elimination-of-the-repetitive-code-at-the-SLRU-bo.patch (text/x-patch) patch v3-0001
On 17.02.2025 21:00, Álvaro Herrera wrote: > On 2025-Feb-17, Andrey Borodin wrote: > >> BootStrapSlruPage() always calls zerofunc(pageno, false) with second argument false. >> In case of every possible argument (ZeroCLOGPage, ZeroCommitTsPage, >> ZeroMultiXactOffsetPage, ZeroMultiXactMemberPage, ZeroSUBTRANSPage) it >> means just a call to SimpleLruZeroPage(). >> I think we can safely replace >> >> + slotno = (*zerofunc)(pageno, false); >> >> with >> >> + slotno = SimpleLruZeroPage(pageno); >> >> Thus we will not need zerofunc argument at all. > > Good observation. This also suggests another change: because this new > function is used not only for bootstrapping but also during WAL replay, > we can call the new function SimpleLruUnloggedZeroPage() and place it > immediately after SimpleLruZeroPage, instead of at the end of the file. > Created functions BootStrapSlruPage,SimpleLruZeroAndLogPage, WriteSlruZeroPageXlogRec. Using of these functions allows to delete ZeroXYZPage functions, WriteXYZZeroPageXlogRec functions and eliminate code repetitions. The conception is: /* * BootStrapSlruPage, * SimpleLruZeroAndLogPage, * SimpleLruZeroPage * - functions nullifying SLRU pages. * * BootStrapSlruPage is the most holistic. It performs: * 1. locking, * 2. nullifying, * 3. logging (when writeXlog is true), * 4. writing out, * 5. releasing the lock. * * SimpleLruZeroAndLogPage performs: * 2. nullifying, * 3. logging (when writeXlog is true), * 4. writing out. * * If the writeXlog is true, BootStrapSlruPage and SimpleLruZeroAndLogPage * emit an XLOG record saying we did this. * If the writeXlog is false, the rmid and info parameters are unused. * * SimpleLruZeroPage performs: * 2. nullifying. */