Introduce 'bbsink' abstraction to modularize base backup code.
authorRobert Haas <rhaas@postgresql.org>
Fri, 5 Nov 2021 14:08:30 +0000 (10:08 -0400)
committerRobert Haas <rhaas@postgresql.org>
Fri, 5 Nov 2021 14:08:30 +0000 (10:08 -0400)
commitbef47ff85df18bf4a3a9b13bd2a54820e27f3614
tree9b0ff2c1fa76a38a425172a66d9afb2c3550743c
parentbd807be6935929bdefe74d1258ca08048f0aafa3
Introduce 'bbsink' abstraction to modularize base backup code.

The base backup code has accumulated a healthy number of new
features over the years, but it's becoming increasingly difficult
to maintain and further enhance that code because there's no
real separation of concerns. For example, the code that
understands knows the details of how we send data to the client
using the libpq protocol is scattered throughout basebackup.c,
rather than being centralized in one place.

To try to improve this situation, introduce a new 'bbsink' object
which acts as a recipient for archives generated during the base
backup progress and also for the backup manifest. This commit
introduces three types of bbsink: a 'copytblspc' bbsink forwards the
backup to the client using one COPY OUT operation per tablespace and
another for the manifest, a 'progress' bbsink performs command
progress reporting, and a 'throttle' bbsink performs rate-limiting.
The 'progress' and 'throttle' bbsink types also forward the data to a
successor bbsink; at present, the last bbsink in the chain will
always be of type 'copytblspc'. There are plans to add more types
of 'bbsink' in future commits.

This abstraction is a bit leaky in the case of progress reporting,
but this still seems cleaner than what we had before.

Patch by me, reviewed and tested by Andres Freund, Sumanta Mukherjee,
Dilip Kumar, Suraj Kharage, Dipesh Pandit, Tushar Ahuja, Mark Dilger,
and Jeevan Ladhe.

Discussion: https://postgr.es/m/CA+TgmoZGwR=ZVWFeecncubEyPdwghnvfkkdBe9BLccLSiqdf9Q@mail.gmail.com
Discussion: https://postgr.es/m/CA+TgmoZvqk7UuzxsX1xjJRmMGkqoUGYTZLDCH8SmU1xTPr1Xig@mail.gmail.com
src/backend/replication/Makefile
src/backend/replication/backup_manifest.c
src/backend/replication/basebackup.c
src/backend/replication/basebackup_copy.c [new file with mode: 0644]
src/backend/replication/basebackup_progress.c [new file with mode: 0644]
src/backend/replication/basebackup_sink.c [new file with mode: 0644]
src/backend/replication/basebackup_throttle.c [new file with mode: 0644]
src/include/replication/backup_manifest.h
src/include/replication/basebackup_sink.h [new file with mode: 0644]