You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
postgres/src/bin/pg_basebackup/walmethods.h

135 lines
4.0 KiB

/*-------------------------------------------------------------------------
*
* walmethods.h
*
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
*
* IDENTIFICATION
* src/bin/pg_basebackup/walmethods.h
*-------------------------------------------------------------------------
*/
#include "common/compression.h"
struct WalWriteMethod;
typedef struct WalWriteMethod WalWriteMethod;
typedef struct
{
WalWriteMethod *wwmethod;
off_t currpos;
char *pathname;
/*
* MORE DATA FOLLOWS AT END OF STRUCT
*
* Each WalWriteMethod is expected to embed this as the first member of a
* larger struct with method-specific fields following.
*/
} Walfile;
typedef enum
{
CLOSE_NORMAL,
CLOSE_UNLINK,
CLOSE_NO_RENAME,
} WalCloseMethod;
/*
* Table of callbacks for a WalWriteMethod.
*/
typedef struct WalWriteMethodOps
{
/*
* Open a target file. Returns Walfile, or NULL if open failed. If a temp
* suffix is specified, a file with that name will be opened, and then
* automatically renamed in close(). If pad_to_size is specified, the file
* will be padded with NUL up to that size, if supported by the Walmethod.
*/
Walfile *(*open_for_write) (WalWriteMethod *wwmethod, const char *pathname, const char *temp_suffix, size_t pad_to_size);
/*
* Close an open Walfile, using one or more methods for handling automatic
* unlinking etc. Returns 0 on success, other values for error.
*/
int (*close) (Walfile *f, WalCloseMethod method);
/* Check if a file exist */
bool (*existsfile) (WalWriteMethod *wwmethod, const char *pathname);
/* Return the size of a file, or -1 on failure. */
ssize_t (*get_file_size) (WalWriteMethod *wwmethod, const char *pathname);
/*
* Return the name of the current file to work on in pg_malloc()'d string,
* without the base directory. This is useful for logging.
*/
char *(*get_file_name) (WalWriteMethod *wwmethod, const char *pathname, const char *temp_suffix);
/*
* Write count number of bytes to the file, and return the number of bytes
* actually written or -1 for error.
*/
ssize_t (*write) (Walfile *f, const void *buf, size_t count);
/*
* fsync the contents of the specified file. Returns 0 on success.
*/
int (*sync) (Walfile *f);
/*
* Clean up the Walmethod, closing any shared resources. For methods like
* tar, this includes writing updated headers. Returns true if the
* close/write/sync of shared resources succeeded, otherwise returns false
* (but the resources are still closed).
*/
bool (*finish) (WalWriteMethod *wwmethod);
/*
* Free subsidiary data associated with the WalWriteMethod, and the
* WalWriteMethod itself.
*/
void (*free) (WalWriteMethod *wwmethod);
} WalWriteMethodOps;
/*
* A WalWriteMethod structure represents a way of writing streaming WAL as
* it's received.
*
* All methods that have a failure return indicator will set lasterrstring
* or lasterrno (the former takes precedence) so that the caller can signal
* a suitable error.
*/
struct WalWriteMethod
{
const WalWriteMethodOps *ops;
pg_compress_algorithm compression_algorithm;
int compression_level;
bool sync;
const char *lasterrstring; /* if set, takes precedence over lasterrno */
int lasterrno;
/*
* MORE DATA FOLLOWS AT END OF STRUCT
*
* Each WalWriteMethod is expected to embed this as the first member of a
* larger struct with method-specific fields following.
*/
};
/*
* Available WAL methods:
* - WalDirectoryMethod - write WAL to regular files in a standard pg_wal
* - WalTarMethod - write WAL to a tarfile corresponding to pg_wal
* (only implements the methods required for pg_basebackup,
* not all those required for pg_receivewal)
*/
WalWriteMethod *CreateWalDirectoryMethod(const char *basedir,
pg_compress_algorithm compression_algorithm,
int compression_level, bool sync);
Rework compression options of pg_receivewal pg_receivewal includes since cada1af the option --compress, to allow the compression of WAL segments using gzip, with a value of 0 (the default) meaning that no compression can be used. This commit introduces a new option, called --compression-method, able to use as values "none", the default, and "gzip", to make things more extensible. The case of --compress=0 becomes fuzzy with this option layer, so we have made the choice to make pg_receivewal return an error when using "none" and a non-zero compression level, meaning that the authorized values of --compress are now [1,9] instead of [0,9]. Not specifying --compress with "gzip" as compression method makes pg_receivewal use the default of zlib instead (Z_DEFAULT_COMPRESSION). The code in charge of finding the streaming start LSN when scanning the existing archives is refactored and made more extensible. While on it, rename "compression" to "compression_level" in walmethods.c, to reduce the confusion with the introduction of the compression method, even if the tar method used by pg_basebackup does not rely on the compression method (yet, at least), but just on the compression level (this area could be improved more, actually). This is in preparation for an upcoming patch that adds LZ4 support to pg_receivewal. Author: Georgios Kokolatos Reviewed-by: Michael Paquier, Jian Guo, Magnus Hagander, Dilip Kumar, Robert Haas Discussion: https://postgr.es/m/ZCm1J5vfyQ2E6dYvXz8si39HQ2gwxSZ3IpYaVgYa3lUwY88SLapx9EEnOf5uEwrddhx2twG7zYKjVeuP5MwZXCNPybtsGouDsAD1o2L_I5E=@pm.me
4 years ago
WalWriteMethod *CreateWalTarMethod(const char *tarbase,
pg_compress_algorithm compression_algorithm,
int compression_level, bool sync);
const char *GetLastWalMethodError(WalWriteMethod *wwmethod);