diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2020-11-04 11:21:18 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2020-11-04 11:21:18 +0200 |
commit | 37d2ff38031262a1778bc76a9c55fff7afbcf275 (patch) | |
tree | 309e1c231f9acfbd012c139b816cf5384b00d52a /src/bin/pg_rewind/fetch.c | |
parent | f81e97d0475cd4bc597adc23b665bd84fbf79a0d (diff) | |
download | postgresql-37d2ff38031262a1778bc76a9c55fff7afbcf275.tar.gz postgresql-37d2ff38031262a1778bc76a9c55fff7afbcf275.zip |
pg_rewind: Refactor the abstraction to fetch from local/libpq source.
This makes the abstraction of a "source" server more clear, by introducing
a common abstract class, borrowing the object-oriented programming term,
that represents all the operations that can be done on the source server.
There are two implementations of it, one for fetching via libpq, and
another to fetch from a local directory. This adds some code, but makes it
easier to understand what's going on.
The copy_executeFileMap() and libpq_executeFileMap() functions contained
basically the same logic, just calling different functions to fetch the
source files. Refactor so that the common logic is in one place, in a new
function called perform_rewind().
Reviewed-by: Kyotaro Horiguchi, Soumyadeep Chakraborty
Discussion: https://www.postgresql.org/message-id/0c5b3783-af52-3ee5-f8fa-6e794061f70d%40iki.fi
Diffstat (limited to 'src/bin/pg_rewind/fetch.c')
-rw-r--r-- | src/bin/pg_rewind/fetch.c | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/src/bin/pg_rewind/fetch.c b/src/bin/pg_rewind/fetch.c deleted file mode 100644 index f41d0f295ea..00000000000 --- a/src/bin/pg_rewind/fetch.c +++ /dev/null @@ -1,60 +0,0 @@ -/*------------------------------------------------------------------------- - * - * fetch.c - * Functions for fetching files from a local or remote data dir - * - * This file forms an abstraction of getting files from the "source". - * There are two implementations of this interface: one for copying files - * from a data directory via normal filesystem operations (copy_fetch.c), - * and another for fetching files from a remote server via a libpq - * connection (libpq_fetch.c) - * - * - * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group - * - *------------------------------------------------------------------------- - */ -#include "postgres_fe.h" - -#include <sys/stat.h> -#include <unistd.h> - -#include "fetch.h" -#include "file_ops.h" -#include "filemap.h" -#include "pg_rewind.h" - -void -fetchSourceFileList(void) -{ - if (datadir_source) - traverse_datadir(datadir_source, &process_source_file); - else - libpqProcessFileList(); -} - -/* - * Fetch all relation data files that are marked in the given data page map. - */ -void -execute_file_actions(filemap_t *filemap) -{ - if (datadir_source) - copy_executeFileMap(filemap); - else - libpq_executeFileMap(filemap); -} - -/* - * Fetch a single file into a malloc'd buffer. The file size is returned - * in *filesize. The returned buffer is always zero-terminated, which is - * handy for text files. - */ -char * -fetchFile(const char *filename, size_t *filesize) -{ - if (datadir_source) - return slurpFile(datadir_source, filename, filesize); - else - return libpqGetFile(filename, filesize); -} |