From 3603f7c6e66afda7c7bf4acdefd4e5b04c5478b3 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 12 Apr 2022 17:28:17 +0900 Subject: [PATCH] Remove WalCompressionMethod in favor of pg_compress_algorithm The same structure, with the same set of elements (for none, lz4, gzip and zstd), exists in compression.h, so let's make use of the centralized version instead of duplicating things. Some of the variables used previously for WalCompressionMethod are renamed to stick better with the new structure and routine names. WalCompressionMethod was leading to some confusion in walmethods.c, as it was sometimes used to refer to some data unrelated to WAL. Reported-by: Robert Haas Author: Michael Paquier Reviewed-by: Robert Haas, Georgios Kokolatos Discussion: https://postgr.es/m/YlPQGNAAa04raObK@paquier.xyz --- src/bin/pg_basebackup/pg_basebackup.c | 18 ++--- src/bin/pg_basebackup/pg_receivewal.c | 44 ++++++------ src/bin/pg_basebackup/receivelog.c | 2 +- src/bin/pg_basebackup/walmethods.c | 96 +++++++++++++-------------- src/bin/pg_basebackup/walmethods.h | 16 ++--- 5 files changed, 84 insertions(+), 92 deletions(-) diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index 91bdaf6cc2..6be0454476 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -520,7 +520,7 @@ typedef struct char xlog[MAXPGPATH]; /* directory or tarfile depending on mode */ char *sysidentifier; int timeline; - WalCompressionMethod wal_compress_method; + pg_compress_algorithm wal_compress_algorithm; int wal_compress_level; } logstreamer_param; @@ -550,11 +550,11 @@ LogStreamerMain(logstreamer_param *param) stream.replication_slot = replication_slot; if (format == 'p') stream.walmethod = CreateWalDirectoryMethod(param->xlog, - COMPRESSION_NONE, 0, + PG_COMPRESSION_NONE, 0, stream.do_sync); else stream.walmethod = CreateWalTarMethod(param->xlog, - param->wal_compress_method, + param->wal_compress_algorithm, param->wal_compress_level, stream.do_sync); @@ -602,7 +602,7 @@ LogStreamerMain(logstreamer_param *param) */ static void StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier, - WalCompressionMethod wal_compress_method, + pg_compress_algorithm wal_compress_algorithm, int wal_compress_level) { logstreamer_param *param; @@ -613,7 +613,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier, param = pg_malloc0(sizeof(logstreamer_param)); param->timeline = timeline; param->sysidentifier = sysidentifier; - param->wal_compress_method = wal_compress_method; + param->wal_compress_algorithm = wal_compress_algorithm; param->wal_compress_level = wal_compress_level; /* Convert the starting position */ @@ -2019,7 +2019,7 @@ BaseBackup(char *compression_algorithm, char *compression_detail, */ if (includewal == STREAM_WAL) { - WalCompressionMethod wal_compress_method; + pg_compress_algorithm wal_compress_algorithm; int wal_compress_level; if (verbose) @@ -2027,19 +2027,19 @@ BaseBackup(char *compression_algorithm, char *compression_detail, if (client_compress->algorithm == PG_COMPRESSION_GZIP) { - wal_compress_method = COMPRESSION_GZIP; + wal_compress_algorithm = PG_COMPRESSION_GZIP; wal_compress_level = (client_compress->options & PG_COMPRESSION_OPTION_LEVEL) != 0 ? client_compress->level : 0; } else { - wal_compress_method = COMPRESSION_NONE; + wal_compress_algorithm = PG_COMPRESSION_NONE; wal_compress_level = 0; } StartLogStreamer(xlogstart, starttli, sysidentifier, - wal_compress_method, wal_compress_level); + wal_compress_algorithm, wal_compress_level); } if (serverMajor >= 1500) diff --git a/src/bin/pg_basebackup/pg_receivewal.c b/src/bin/pg_basebackup/pg_receivewal.c index 23e04741fd..ede1d4648d 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 pg_compress_algorithm compression_algorithm = PG_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) + pg_compress_algorithm *wal_compression_algorithm) { size_t fname_len = strlen(filename); size_t xlog_pattern_len = strspn(filename, "0123456789ABCDEF"); @@ -127,7 +127,7 @@ is_xlogfilename(const char *filename, bool *ispartial, if (fname_len == XLOG_FNAME_LEN) { *ispartial = false; - *wal_compression_method = COMPRESSION_NONE; + *wal_compression_algorithm = PG_COMPRESSION_NONE; return true; } @@ -136,7 +136,7 @@ is_xlogfilename(const char *filename, bool *ispartial, strcmp(filename + XLOG_FNAME_LEN, ".gz") == 0) { *ispartial = false; - *wal_compression_method = COMPRESSION_GZIP; + *wal_compression_algorithm = PG_COMPRESSION_GZIP; return true; } @@ -145,7 +145,7 @@ is_xlogfilename(const char *filename, bool *ispartial, strcmp(filename + XLOG_FNAME_LEN, ".lz4") == 0) { *ispartial = false; - *wal_compression_method = COMPRESSION_LZ4; + *wal_compression_algorithm = PG_COMPRESSION_LZ4; return true; } @@ -154,7 +154,7 @@ is_xlogfilename(const char *filename, bool *ispartial, strcmp(filename + XLOG_FNAME_LEN, ".partial") == 0) { *ispartial = true; - *wal_compression_method = COMPRESSION_NONE; + *wal_compression_algorithm = PG_COMPRESSION_NONE; return true; } @@ -163,7 +163,7 @@ is_xlogfilename(const char *filename, bool *ispartial, strcmp(filename + XLOG_FNAME_LEN, ".gz.partial") == 0) { *ispartial = true; - *wal_compression_method = COMPRESSION_GZIP; + *wal_compression_algorithm = PG_COMPRESSION_GZIP; return true; } @@ -172,7 +172,7 @@ is_xlogfilename(const char *filename, bool *ispartial, strcmp(filename + XLOG_FNAME_LEN, ".lz4.partial") == 0) { *ispartial = true; - *wal_compression_method = COMPRESSION_LZ4; + *wal_compression_algorithm = PG_COMPRESSION_LZ4; return true; } @@ -279,11 +279,11 @@ FindStreamingStart(uint32 *tli) { uint32 tli; XLogSegNo segno; - WalCompressionMethod wal_compression_method; + pg_compress_algorithm wal_compression_algorithm; bool ispartial; if (!is_xlogfilename(dirent->d_name, - &ispartial, &wal_compression_method)) + &ispartial, &wal_compression_algorithm)) continue; /* @@ -309,7 +309,7 @@ FindStreamingStart(uint32 *tli) * where WAL segments could have been compressed by a different source * than pg_receivewal, like an archive_command with lz4. */ - if (!ispartial && wal_compression_method == COMPRESSION_NONE) + if (!ispartial && wal_compression_algorithm == PG_COMPRESSION_NONE) { struct stat statbuf; char fullpath[MAXPGPATH * 2]; @@ -325,7 +325,7 @@ FindStreamingStart(uint32 *tli) continue; } } - else if (!ispartial && wal_compression_method == COMPRESSION_GZIP) + else if (!ispartial && wal_compression_algorithm == PG_COMPRESSION_GZIP) { int fd; char buf[4]; @@ -364,7 +364,7 @@ FindStreamingStart(uint32 *tli) continue; } } - else if (!ispartial && wal_compression_method == COMPRESSION_LZ4) + else if (!ispartial && wal_compression_algorithm == PG_COMPRESSION_LZ4) { #ifdef USE_LZ4 #define LZ4_CHUNK_SZ 64 * 1024 /* 64kB as maximum chunk size read */ @@ -590,7 +590,7 @@ StreamLog(void) stream.do_sync = do_sync; stream.mark_done = false; stream.walmethod = CreateWalDirectoryMethod(basedir, - compression_method, + compression_algorithm, compresslevel, stream.do_sync); stream.partial_suffix = ".partial"; @@ -750,11 +750,11 @@ main(int argc, char **argv) break; case 6: if (pg_strcasecmp(optarg, "gzip") == 0) - compression_method = COMPRESSION_GZIP; + compression_algorithm = PG_COMPRESSION_GZIP; else if (pg_strcasecmp(optarg, "lz4") == 0) - compression_method = COMPRESSION_LZ4; + compression_algorithm = PG_COMPRESSION_LZ4; else if (pg_strcasecmp(optarg, "none") == 0) - compression_method = COMPRESSION_NONE; + compression_algorithm = PG_COMPRESSION_NONE; else pg_fatal("invalid value \"%s\" for option %s", optarg, "--compression-method"); @@ -814,9 +814,9 @@ main(int argc, char **argv) /* * Compression-related options. */ - switch (compression_method) + switch (compression_algorithm) { - case COMPRESSION_NONE: + case PG_COMPRESSION_NONE: if (compresslevel != 0) { pg_log_error("cannot use --compress with --compression-method=%s", @@ -825,7 +825,7 @@ main(int argc, char **argv) exit(1); } break; - case COMPRESSION_GZIP: + case PG_COMPRESSION_GZIP: #ifdef HAVE_LIBZ if (compresslevel == 0) { @@ -837,7 +837,7 @@ main(int argc, char **argv) "gzip"); #endif break; - case COMPRESSION_LZ4: + case PG_COMPRESSION_LZ4: #ifdef USE_LZ4 if (compresslevel != 0) { @@ -851,7 +851,7 @@ main(int argc, char **argv) "LZ4"); #endif break; - case COMPRESSION_ZSTD: + case PG_COMPRESSION_ZSTD: pg_fatal("compression with %s is not yet supported", "ZSTD"); break; } diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c index 42d50931d3..ad866a7602 100644 --- a/src/bin/pg_basebackup/receivelog.c +++ b/src/bin/pg_basebackup/receivelog.c @@ -114,7 +114,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint) * When streaming to tar, no file with this name will exist before, so we * never have to verify a size. */ - if (stream->walmethod->compression_method() == COMPRESSION_NONE && + if (stream->walmethod->compression_algorithm() == PG_COMPRESSION_NONE && stream->walmethod->existsfile(fn)) { size = stream->walmethod->get_file_size(fn); diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c index acd242d2c9..d5bcc208a9 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; + pg_compress_algorithm compression_algorithm; int compression_level; bool sync; const char *lasterrstring; /* if set, takes precedence over lasterrno */ @@ -97,8 +97,8 @@ dir_get_file_name(const char *pathname, const char *temp_suffix) snprintf(filename, MAXPGPATH, "%s%s%s", pathname, - dir_data->compression_method == COMPRESSION_GZIP ? ".gz" : - dir_data->compression_method == COMPRESSION_LZ4 ? ".lz4" : "", + dir_data->compression_algorithm == PG_COMPRESSION_GZIP ? ".gz" : + dir_data->compression_algorithm == PG_COMPRESSION_LZ4 ? ".lz4" : "", temp_suffix ? temp_suffix : ""); return filename; @@ -141,7 +141,7 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ } #ifdef HAVE_LIBZ - if (dir_data->compression_method == COMPRESSION_GZIP) + if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP) { gzfp = gzdopen(fd, "wb"); if (gzfp == NULL) @@ -161,7 +161,7 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ } #endif #ifdef USE_LZ4 - if (dir_data->compression_method == COMPRESSION_LZ4) + if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4) { size_t ctx_out; size_t header_size; @@ -202,7 +202,7 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ #endif /* Do pre-padding on non-compressed files */ - if (pad_to_size && dir_data->compression_method == COMPRESSION_NONE) + if (pad_to_size && dir_data->compression_algorithm == PG_COMPRESSION_NONE) { PGAlignedXLogBlock zerobuf; int bytes; @@ -241,12 +241,12 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ { dir_data->lasterrno = errno; #ifdef HAVE_LIBZ - if (dir_data->compression_method == COMPRESSION_GZIP) + if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP) gzclose(gzfp); else #endif #ifdef USE_LZ4 - if (dir_data->compression_method == COMPRESSION_LZ4) + if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4) { (void) LZ4F_compressEnd(ctx, lz4buf, lz4bufsize, NULL); (void) LZ4F_freeCompressionContext(ctx); @@ -262,11 +262,11 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ f = pg_malloc0(sizeof(DirectoryMethodFile)); #ifdef HAVE_LIBZ - if (dir_data->compression_method == COMPRESSION_GZIP) + if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP) f->gzfp = gzfp; #endif #ifdef USE_LZ4 - if (dir_data->compression_method == COMPRESSION_LZ4) + if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4) { f->ctx = ctx; f->lz4buf = lz4buf; @@ -294,7 +294,7 @@ dir_write(Walfile f, const void *buf, size_t count) dir_clear_error(); #ifdef HAVE_LIBZ - if (dir_data->compression_method == COMPRESSION_GZIP) + if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP) { errno = 0; r = (ssize_t) gzwrite(df->gzfp, buf, count); @@ -307,7 +307,7 @@ dir_write(Walfile f, const void *buf, size_t count) else #endif #ifdef USE_LZ4 - if (dir_data->compression_method == COMPRESSION_LZ4) + if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4) { size_t chunk; size_t remaining; @@ -387,7 +387,7 @@ dir_close(Walfile f, WalCloseMethod method) dir_clear_error(); #ifdef HAVE_LIBZ - if (dir_data->compression_method == COMPRESSION_GZIP) + if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP) { errno = 0; /* in case gzclose() doesn't set it */ r = gzclose(df->gzfp); @@ -395,7 +395,7 @@ dir_close(Walfile f, WalCloseMethod method) else #endif #ifdef USE_LZ4 - if (dir_data->compression_method == COMPRESSION_LZ4) + if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4) { size_t compressed; @@ -514,7 +514,7 @@ dir_sync(Walfile f) return 0; #ifdef HAVE_LIBZ - if (dir_data->compression_method == COMPRESSION_GZIP) + if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP) { if (gzflush(((DirectoryMethodFile *) f)->gzfp, Z_SYNC_FLUSH) != Z_OK) { @@ -524,7 +524,7 @@ dir_sync(Walfile f) } #endif #ifdef USE_LZ4 - if (dir_data->compression_method == COMPRESSION_LZ4) + if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4) { DirectoryMethodFile *df = (DirectoryMethodFile *) f; size_t compressed; @@ -571,10 +571,10 @@ dir_get_file_size(const char *pathname) return statbuf.st_size; } -static WalCompressionMethod -dir_compression_method(void) +static pg_compress_algorithm +dir_compression_algorithm(void) { - return dir_data->compression_method; + return dir_data->compression_algorithm; } static bool @@ -618,7 +618,7 @@ dir_finish(void) WalWriteMethod * CreateWalDirectoryMethod(const char *basedir, - WalCompressionMethod compression_method, + pg_compress_algorithm compression_algorithm, int compression_level, bool sync) { WalWriteMethod *method; @@ -629,7 +629,7 @@ CreateWalDirectoryMethod(const char *basedir, method->get_current_pos = dir_get_current_pos; method->get_file_size = dir_get_file_size; method->get_file_name = dir_get_file_name; - method->compression_method = dir_compression_method; + method->compression_algorithm = dir_compression_algorithm; method->close = dir_close; method->sync = dir_sync; method->existsfile = dir_existsfile; @@ -637,7 +637,7 @@ CreateWalDirectoryMethod(const char *basedir, method->getlasterror = dir_getlasterror; dir_data = pg_malloc0(sizeof(DirectoryMethodData)); - dir_data->compression_method = compression_method; + dir_data->compression_algorithm = compression_algorithm; dir_data->compression_level = compression_level; dir_data->basedir = pg_strdup(basedir); dir_data->sync = sync; @@ -672,7 +672,7 @@ typedef struct TarMethodData { char *tarfilename; int fd; - WalCompressionMethod compression_method; + pg_compress_algorithm compression_algorithm; int compression_level; bool sync; TarMethodFile *currentfile; @@ -759,7 +759,7 @@ tar_write(Walfile f, const void *buf, size_t count) tar_clear_error(); /* Tarfile will always be positioned at the end */ - if (tar_data->compression_method == COMPRESSION_NONE) + if (tar_data->compression_algorithm == PG_COMPRESSION_NONE) { errno = 0; r = write(tar_data->fd, buf, count); @@ -773,7 +773,7 @@ tar_write(Walfile f, const void *buf, size_t count) return r; } #ifdef HAVE_LIBZ - else if (tar_data->compression_method == COMPRESSION_GZIP) + else if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP) { if (!tar_write_compressed_data(unconstify(void *, buf), count, false)) return -1; @@ -842,7 +842,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ } #ifdef HAVE_LIBZ - if (tar_data->compression_method == COMPRESSION_GZIP) + if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP) { tar_data->zp = (z_streamp) pg_malloc(sizeof(z_stream)); tar_data->zp->zalloc = Z_NULL; @@ -893,7 +893,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ pg_free(tmppath); #ifdef HAVE_LIBZ - if (tar_data->compression_method == COMPRESSION_GZIP) + if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP) { /* Flush existing data */ if (!tar_write_compressed_data(NULL, 0, true)) @@ -918,7 +918,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ } tar_data->currentfile->currpos = 0; - if (tar_data->compression_method == COMPRESSION_NONE) + if (tar_data->compression_algorithm == PG_COMPRESSION_NONE) { errno = 0; if (write(tar_data->fd, tar_data->currentfile->header, @@ -932,7 +932,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ } } #ifdef HAVE_LIBZ - else if (tar_data->compression_method == COMPRESSION_GZIP) + else if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP) { /* Write header through the zlib APIs but with no compression */ if (!tar_write_compressed_data(tar_data->currentfile->header, @@ -962,7 +962,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ if (pad_to_size) { tar_data->currentfile->pad_to_size = pad_to_size; - if (tar_data->compression_method == COMPRESSION_NONE) + if (tar_data->compression_algorithm == PG_COMPRESSION_NONE) { /* Uncompressed, so pad now */ if (!tar_write_padding_data(tar_data->currentfile, pad_to_size)) @@ -993,10 +993,10 @@ tar_get_file_size(const char *pathname) return -1; } -static WalCompressionMethod -tar_compression_method(void) +static pg_compress_algorithm +tar_compression_algorithm(void) { - return tar_data->compression_method; + return tar_data->compression_algorithm; } static off_t @@ -1023,7 +1023,7 @@ tar_sync(Walfile f) * Always sync the whole tarfile, because that's all we can do. This makes * no sense on compressed files, so just ignore those. */ - if (tar_data->compression_method != COMPRESSION_NONE) + if (tar_data->compression_algorithm != PG_COMPRESSION_NONE) return 0; r = fsync(tar_data->fd); @@ -1044,7 +1044,7 @@ tar_close(Walfile f, WalCloseMethod method) if (method == CLOSE_UNLINK) { - if (tar_data->compression_method != COMPRESSION_NONE) + if (tar_data->compression_algorithm != PG_COMPRESSION_NONE) { tar_set_error("unlink not supported with compression"); return -1; @@ -1075,7 +1075,7 @@ tar_close(Walfile f, WalCloseMethod method) */ if (tf->pad_to_size) { - if (tar_data->compression_method == COMPRESSION_GZIP) + if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP) { /* * A compressed tarfile is padded on close since we cannot know @@ -1116,7 +1116,7 @@ tar_close(Walfile f, WalCloseMethod method) #ifdef HAVE_LIBZ - if (tar_data->compression_method == COMPRESSION_GZIP) + if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP) { /* Flush the current buffer */ if (!tar_write_compressed_data(NULL, 0, true)) @@ -1145,7 +1145,7 @@ tar_close(Walfile f, WalCloseMethod method) tar_data->lasterrno = errno; return -1; } - if (tar_data->compression_method == COMPRESSION_NONE) + if (tar_data->compression_algorithm == PG_COMPRESSION_NONE) { errno = 0; if (write(tar_data->fd, tf->header, TAR_BLOCK_SIZE) != TAR_BLOCK_SIZE) @@ -1156,7 +1156,7 @@ tar_close(Walfile f, WalCloseMethod method) } } #ifdef HAVE_LIBZ - else if (tar_data->compression_method == COMPRESSION_GZIP) + else if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP) { /* Turn off compression */ if (deflateParams(tar_data->zp, 0, 0) != Z_OK) @@ -1230,7 +1230,7 @@ tar_finish(void) /* A tarfile always ends with two empty blocks */ MemSet(zerobuf, 0, sizeof(zerobuf)); - if (tar_data->compression_method == COMPRESSION_NONE) + if (tar_data->compression_algorithm == PG_COMPRESSION_NONE) { errno = 0; if (write(tar_data->fd, zerobuf, sizeof(zerobuf)) != sizeof(zerobuf)) @@ -1241,7 +1241,7 @@ tar_finish(void) } } #ifdef HAVE_LIBZ - else if (tar_data->compression_method == COMPRESSION_GZIP) + else if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP) { if (!tar_write_compressed_data(zerobuf, sizeof(zerobuf), false)) return false; @@ -1324,18 +1324,18 @@ tar_finish(void) } /* - * The argument compression_method is currently ignored. It is in place for + * The argument compression_algorithm is currently ignored. It is in place for * symmetry with CreateWalDirectoryMethod which uses it for distinguishing * between the different compression methods. CreateWalTarMethod and its family * of functions handle only zlib compression. */ WalWriteMethod * CreateWalTarMethod(const char *tarbase, - WalCompressionMethod compression_method, + pg_compress_algorithm compression_algorithm, int compression_level, bool sync) { WalWriteMethod *method; - const char *suffix = (compression_method == COMPRESSION_GZIP) ? + const char *suffix = (compression_algorithm == PG_COMPRESSION_GZIP) ? ".tar.gz" : ".tar"; method = pg_malloc0(sizeof(WalWriteMethod)); @@ -1344,7 +1344,7 @@ CreateWalTarMethod(const char *tarbase, method->get_current_pos = tar_get_current_pos; method->get_file_size = tar_get_file_size; method->get_file_name = tar_get_file_name; - method->compression_method = tar_compression_method; + method->compression_algorithm = tar_compression_algorithm; method->close = tar_close; method->sync = tar_sync; method->existsfile = tar_existsfile; @@ -1355,11 +1355,11 @@ CreateWalTarMethod(const char *tarbase, tar_data->tarfilename = pg_malloc0(strlen(tarbase) + strlen(suffix) + 1); sprintf(tar_data->tarfilename, "%s%s", tarbase, suffix); tar_data->fd = -1; - tar_data->compression_method = compression_method; + tar_data->compression_algorithm = compression_algorithm; tar_data->compression_level = compression_level; tar_data->sync = sync; #ifdef HAVE_LIBZ - if (compression_method == COMPRESSION_GZIP) + if (compression_algorithm == PG_COMPRESSION_GZIP) tar_data->zlibOut = (char *) pg_malloc(ZLIB_OUT_SIZE + 1); #endif @@ -1371,7 +1371,7 @@ FreeWalTarMethod(void) { pg_free(tar_data->tarfilename); #ifdef HAVE_LIBZ - if (tar_data->compression_method == COMPRESSION_GZIP) + if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP) pg_free(tar_data->zlibOut); #endif pg_free(tar_data); diff --git a/src/bin/pg_basebackup/walmethods.h b/src/bin/pg_basebackup/walmethods.h index ec54019cfc..76530dc941 100644 --- a/src/bin/pg_basebackup/walmethods.h +++ b/src/bin/pg_basebackup/walmethods.h @@ -9,6 +9,7 @@ *------------------------------------------------------------------------- */ +#include "common/compression.h" typedef void *Walfile; @@ -19,15 +20,6 @@ typedef enum CLOSE_NO_RENAME } WalCloseMethod; -/* Types of compression supported */ -typedef enum -{ - COMPRESSION_GZIP, - COMPRESSION_LZ4, - COMPRESSION_ZSTD, - COMPRESSION_NONE -} WalCompressionMethod; - /* * A WalWriteMethod structure represents the different methods used * to write the streaming WAL as it's received. @@ -68,7 +60,7 @@ struct WalWriteMethod char *(*get_file_name) (const char *pathname, const char *temp_suffix); /* Returns the compression method */ - WalCompressionMethod (*compression_method) (void); + pg_compress_algorithm (*compression_algorithm) (void); /* * Write count number of bytes to the file, and return the number of bytes @@ -104,10 +96,10 @@ struct WalWriteMethod * not all those required for pg_receivewal) */ WalWriteMethod *CreateWalDirectoryMethod(const char *basedir, - WalCompressionMethod compression_method, + pg_compress_algorithm compression_algo, int compression, bool sync); WalWriteMethod *CreateWalTarMethod(const char *tarbase, - WalCompressionMethod compression_method, + pg_compress_algorithm compression_algo, int compression, bool sync); /* Cleanup routines for previously-created methods */