On Fri, Jan 21, 2022 at 09:57:41AM -0500, Robert Haas wrote: > Thanks. One thing I just noticed is that the enum we're using here is > called WalCompressionMethod. But we're not compressing WAL. We're > compressing tarfiles of the data directory.
Also, having this enum in walmethods.h is perhaps not the best place either, even more if you plan to use that in pg_basebackup for the server-side compression. One idea is to rename this enum to DataCompressionMethod, moving it into a new header, like common.h as of the attached. -- Michael
From 3d2aec3abdfa8d2c6faf639c1cbaaf73d9064f11 Mon Sep 17 00:00:00 2001 From: Michael Paquier <mich...@paquier.xyz> Date: Sat, 22 Jan 2022 14:43:19 +0900 Subject: [PATCH] Move declaration in new header for pg_basebackup --- src/bin/pg_basebackup/common.h | 26 ++++++++++++++++++++++++++ src/bin/pg_basebackup/pg_basebackup.c | 5 +++-- src/bin/pg_basebackup/pg_receivewal.c | 6 +++--- src/bin/pg_basebackup/walmethods.c | 12 ++++++------ src/bin/pg_basebackup/walmethods.h | 15 ++++----------- src/tools/pgindent/typedefs.list | 2 +- 6 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 src/bin/pg_basebackup/common.h diff --git a/src/bin/pg_basebackup/common.h b/src/bin/pg_basebackup/common.h new file mode 100644 index 0000000000..abad3b25ca --- /dev/null +++ b/src/bin/pg_basebackup/common.h @@ -0,0 +1,26 @@ +/*------------------------------------------------------------------------- + * + * common.h + * + * Common declarations shared across all tools of src/bin/pg_basebackup/. + * + * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group + * + * IDENTIFICATION + * src/bin/pg_basebackup/common.h + * + *------------------------------------------------------------------------- + */ + +#ifndef BASEBACKUP_COMMON_H +#define BASEBACKUP_COMMON_H + +/* Types of compression supported */ +typedef enum +{ + COMPRESSION_GZIP, + COMPRESSION_LZ4, + COMPRESSION_NONE +} DataCompressionMethod; + +#endif /* BASEBACKUP_COMMON_H */ diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index d5b0ade10d..2c66e4fd87 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -29,6 +29,7 @@ #include "access/xlog_internal.h" #include "bbstreamer.h" +#include "common.h" #include "common/file_perm.h" #include "common/file_utils.h" #include "common/logging.h" @@ -123,7 +124,7 @@ static bool showprogress = false; static bool estimatesize = true; static int verbose = 0; static int compresslevel = 0; -static WalCompressionMethod compressmethod = COMPRESSION_NONE; +static DataCompressionMethod compressmethod = COMPRESSION_NONE; static IncludeWal includewal = STREAM_WAL; static bool fastcheckpoint = false; static bool writerecoveryconf = false; @@ -943,7 +944,7 @@ parse_max_rate(char *src) * from the parsed results. */ static void -parse_compress_options(char *src, WalCompressionMethod *methodres, +parse_compress_options(char *src, DataCompressionMethod *methodres, int *levelres) { char *sep; diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c index ccb215c398..9f2e633c80 100644 --- a/src/bin/pg_basebackup/pg_receivewal.c +++ b/src/bin/pg_basebackup/pg_receivewal.c @@ -52,7 +52,7 @@ static bool do_drop_slot = false; static bool do_sync = true; static bool synchronous = false; static char *replication_slot = NULL; -static WalCompressionMethod compression_method = COMPRESSION_NONE; +static DataCompressionMethod compression_method = COMPRESSION_NONE; static XLogRecPtr endpos = InvalidXLogRecPtr; @@ -114,7 +114,7 @@ usage(void) */ static bool is_xlogfilename(const char *filename, bool *ispartial, - WalCompressionMethod *wal_compression_method) + DataCompressionMethod *wal_compression_method) { size_t fname_len = strlen(filename); size_t xlog_pattern_len = strspn(filename, "0123456789ABCDEF"); @@ -285,7 +285,7 @@ FindStreamingStart(uint32 *tli) { uint32 tli; XLogSegNo segno; - WalCompressionMethod wal_compression_method; + DataCompressionMethod wal_compression_method; bool ispartial; if (!is_xlogfilename(dirent->d_name, diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c index f74bd13315..b87afec5a6 100644 --- a/src/bin/pg_basebackup/walmethods.c +++ b/src/bin/pg_basebackup/walmethods.c @@ -49,7 +49,7 @@ typedef struct DirectoryMethodData { char *basedir; - WalCompressionMethod compression_method; + DataCompressionMethod compression_method; int compression_level; bool sync; const char *lasterrstring; /* if set, takes precedence over lasterrno */ @@ -561,7 +561,7 @@ dir_get_file_size(const char *pathname) return statbuf.st_size; } -static WalCompressionMethod +static DataCompressionMethod dir_compression_method(void) { return dir_data->compression_method; @@ -608,7 +608,7 @@ dir_finish(void) WalWriteMethod * CreateWalDirectoryMethod(const char *basedir, - WalCompressionMethod compression_method, + DataCompressionMethod compression_method, int compression_level, bool sync) { WalWriteMethod *method; @@ -662,7 +662,7 @@ typedef struct TarMethodData { char *tarfilename; int fd; - WalCompressionMethod compression_method; + DataCompressionMethod compression_method; int compression_level; bool sync; TarMethodFile *currentfile; @@ -983,7 +983,7 @@ tar_get_file_size(const char *pathname) return -1; } -static WalCompressionMethod +static DataCompressionMethod tar_compression_method(void) { return tar_data->compression_method; @@ -1322,7 +1322,7 @@ tar_finish(void) */ WalWriteMethod * CreateWalTarMethod(const char *tarbase, - WalCompressionMethod compression_method, + DataCompressionMethod compression_method, int compression_level, bool sync) { WalWriteMethod *method; diff --git a/src/bin/pg_basebackup/walmethods.h b/src/bin/pg_basebackup/walmethods.h index 2dfb353baa..2dc2e6c913 100644 --- a/src/bin/pg_basebackup/walmethods.h +++ b/src/bin/pg_basebackup/walmethods.h @@ -9,6 +9,7 @@ *------------------------------------------------------------------------- */ +#include "common.h" typedef void *Walfile; @@ -19,14 +20,6 @@ typedef enum CLOSE_NO_RENAME } WalCloseMethod; -/* Types of compression supported */ -typedef enum -{ - COMPRESSION_GZIP, - COMPRESSION_LZ4, - COMPRESSION_NONE -} WalCompressionMethod; - /* * A WalWriteMethod structure represents the different methods used * to write the streaming WAL as it's received. @@ -67,7 +60,7 @@ struct WalWriteMethod char *(*get_file_name) (const char *pathname, const char *temp_suffix); /* Returns the compression method */ - WalCompressionMethod (*compression_method) (void); + DataCompressionMethod (*compression_method) (void); /* * Write count number of bytes to the file, and return the number of bytes @@ -103,10 +96,10 @@ struct WalWriteMethod * not all those required for pg_receivewal) */ WalWriteMethod *CreateWalDirectoryMethod(const char *basedir, - WalCompressionMethod compression_method, + DataCompressionMethod compression_method, int compression, bool sync); WalWriteMethod *CreateWalTarMethod(const char *tarbase, - WalCompressionMethod compression_method, + DataCompressionMethod compression_method, int compression, bool sync); /* Cleanup routines for previously-created methods */ diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index 89249ecc97..e31c3ea641 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -520,6 +520,7 @@ DR_sqlfunction DR_transientrel DSA DWORD +DataCompressionMethod DataDumperPtr DataPageDeleteStack DatabaseInfo @@ -2863,7 +2864,6 @@ WaitEventTimeout WaitPMResult WalCloseMethod WalCompression -WalCompressionMethod WalLevel WalRcvData WalRcvExecResult -- 2.34.1
signature.asc
Description: PGP signature