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/rewind_source.h | |
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/rewind_source.h')
-rw-r--r-- | src/bin/pg_rewind/rewind_source.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/bin/pg_rewind/rewind_source.h b/src/bin/pg_rewind/rewind_source.h new file mode 100644 index 00000000000..e87f239a47a --- /dev/null +++ b/src/bin/pg_rewind/rewind_source.h @@ -0,0 +1,73 @@ +/*------------------------------------------------------------------------- + * + * rewind_source.h + * Abstraction for fetching from source server. + * + * The source server can be either a libpq connection to a live system, + * or a local data directory. The 'rewind_source' struct abstracts the + * operations to fetch data from the source system, so that the rest of + * the code doesn't need to care what kind of a source its dealing with. + * + * Copyright (c) 2013-2020, PostgreSQL Global Development Group + * + *------------------------------------------------------------------------- + */ +#ifndef REWIND_SOURCE_H +#define REWIND_SOURCE_H + +#include "access/xlogdefs.h" +#include "file_ops.h" +#include "filemap.h" +#include "libpq-fe.h" + +typedef struct rewind_source +{ + /* + * Traverse all files in the source data directory, and call 'callback' on + * each file. + */ + void (*traverse_files) (struct rewind_source *, + process_file_callback_t callback); + + /* + * 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 *(*fetch_file) (struct rewind_source *, const char *path, + size_t *filesize); + + /* + * Request to fetch (part of) a file in the source system, specified by an + * offset and length, and write it to the same offset in the corresponding + * target file. The source implementation may queue up the request and + * execute it later when convenient. Call finish_fetch() to flush the + * queue and execute all requests. + */ + void (*queue_fetch_range) (struct rewind_source *, const char *path, + off_t offset, size_t len); + + /* + * Execute all requests queued up with queue_fetch_range(). + */ + void (*finish_fetch) (struct rewind_source *); + + /* + * Get the current WAL insert position in the source system. + */ + XLogRecPtr (*get_current_wal_insert_lsn) (struct rewind_source *); + + /* + * Free this rewind_source object. + */ + void (*destroy) (struct rewind_source *); + +} rewind_source; + +/* in libpq_source.c */ +extern rewind_source *init_libpq_source(PGconn *conn); + +/* in local_source.c */ +extern rewind_source *init_local_source(const char *datadir); + +#endif /* FETCH_H */ |