Split xlog.c

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Split xlog.c
Date: 2021-06-16 13:30:45
Message-ID: b3b71061-4919-e882-4857-27e370ab134a@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

xlog.c is very large. We've split off some functions from it over the
years, but it's still large and it keeps growing.

Attached is a proposal to split functions related to WAL replay, standby
mode, fetching files from archive, computing the recovery target and so
on, to new source file called xlogrecovery.c. That's a fairly clean
split. StartupXLOG() stays in xlog.c, but much of the code from it has
been moved to new functions InitWalRecovery(), PerformWalRecovery() and
EndWalRecovery(). The general idea is that xlog.c is still responsible
for orchestrating the servers startup, but xlogrecovery.c is responsible
for figuring out whether WAL recovery is needed, performing it, and
deciding when it can stop.

There's surely more refactoring we could do. xlog.c has a lot of global
variables, with similar names but slightly different meanings for
example. (Quick: what's the difference between InRedo, InRecovery,
InArchiveRecovery, and RecoveryInProgress()? I have to go check the code
every time to remind myself). But this patch tries to just move source
code around for clarity.

There are small changes in the order that some of things are done in
StartupXLOG(), for readability. I tried to be careful and check that the
changes are safe, but a second pair of eyes would be appreciated on that.

- Heikki

Attachment Content-Type Size
0001-Remove-unnecessary-restoredFromArchive-global-variab.patch text/x-patch 1.7 KB
0002-Split-xlog.c-into-xlog.c-and-xlogrecovery.c.patch text/x-patch 588.9 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2021-06-16 13:31:42 Re: Support for NSS as a libpq TLS backend
Previous Message Stephen Frost 2021-06-16 13:19:51 Re: Duplicate history file?