Rename backup_compression.{c,h} to compression.{c,h}

Compression option handling (level, algorithm or even workers) can be
used across several parts of the system and not only base backups.
Structures, objects and routines are renamed in consequence, to remove
the concept of base backups from this part of the code making this
change straight-forward.

pg_receivewal, that has gained support for LZ4 since babbbb5, will make
use of this infrastructure for its set of compression options, bringing
more consistency with pg_basebackup.  This cleanup needs to be done
before releasing a beta of 15.  pg_dump is a potential future target, as
well, and adding more compression options to it may happen in 16~.

Author: Michael Paquier
Reviewed-by: Robert Haas, Georgios Kokolatos
Discussion: https://postgr.es/m/YlPQGNAAa04raObK@paquier.xyz
This commit is contained in:
Michael Paquier 2022-04-12 13:38:54 +09:00
parent bd037dc928
commit a4b57543ac
17 changed files with 142 additions and 140 deletions

View File

@ -17,7 +17,7 @@
#include <time.h>
#include "access/xlog_internal.h" /* for pg_start/stop_backup */
#include "common/backup_compression.h"
#include "common/compression.h"
#include "common/file_perm.h"
#include "commands/defrem.h"
#include "lib/stringinfo.h"
@ -68,8 +68,8 @@ typedef struct
bool use_copytblspc;
BaseBackupTargetHandle *target_handle;
backup_manifest_option manifest;
bc_algorithm compression;
bc_specification compression_specification;
pg_compress_algorithm compression;
pg_compress_specification compression_specification;
pg_checksum_type manifest_checksum_type;
} basebackup_options;
@ -691,8 +691,8 @@ parse_basebackup_options(List *options, basebackup_options *opt)
MemSet(opt, 0, sizeof(*opt));
opt->manifest = MANIFEST_OPTION_NO;
opt->manifest_checksum_type = CHECKSUM_TYPE_CRC32C;
opt->compression = BACKUP_COMPRESSION_NONE;
opt->compression_specification.algorithm = BACKUP_COMPRESSION_NONE;
opt->compression = PG_COMPRESSION_NONE;
opt->compression_specification.algorithm = PG_COMPRESSION_NONE;
foreach(lopt, options)
{
@ -859,7 +859,7 @@ parse_basebackup_options(List *options, basebackup_options *opt)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("duplicate option \"%s\"", defel->defname)));
if (!parse_bc_algorithm(optval, &opt->compression))
if (!parse_compress_algorithm(optval, &opt->compression))
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("unrecognized compression algorithm \"%s\"",
@ -924,10 +924,10 @@ parse_basebackup_options(List *options, basebackup_options *opt)
{
char *error_detail;
parse_bc_specification(opt->compression, compression_detail_str,
&opt->compression_specification);
parse_compress_specification(opt->compression, compression_detail_str,
&opt->compression_specification);
error_detail =
validate_bc_specification(&opt->compression_specification);
validate_compress_specification(&opt->compression_specification);
if (error_detail != NULL)
ereport(ERROR,
errcode(ERRCODE_SYNTAX_ERROR),
@ -978,11 +978,11 @@ SendBaseBackup(BaseBackupCmd *cmd)
sink = bbsink_throttle_new(sink, opt.maxrate);
/* Set up server-side compression, if client requested it */
if (opt.compression == BACKUP_COMPRESSION_GZIP)
if (opt.compression == PG_COMPRESSION_GZIP)
sink = bbsink_gzip_new(sink, &opt.compression_specification);
else if (opt.compression == BACKUP_COMPRESSION_LZ4)
else if (opt.compression == PG_COMPRESSION_LZ4)
sink = bbsink_lz4_new(sink, &opt.compression_specification);
else if (opt.compression == BACKUP_COMPRESSION_ZSTD)
else if (opt.compression == PG_COMPRESSION_ZSTD)
sink = bbsink_zstd_new(sink, &opt.compression_specification);
/* Set up progress reporting. */

View File

@ -59,7 +59,7 @@ const bbsink_ops bbsink_gzip_ops = {
* Create a new basebackup sink that performs gzip compression.
*/
bbsink *
bbsink_gzip_new(bbsink *next, bc_specification *compress)
bbsink_gzip_new(bbsink *next, pg_compress_specification *compress)
{
#ifndef HAVE_LIBZ
ereport(ERROR,
@ -72,7 +72,7 @@ bbsink_gzip_new(bbsink *next, bc_specification *compress)
Assert(next != NULL);
if ((compress->options & BACKUP_COMPRESSION_OPTION_LEVEL) == 0)
if ((compress->options & PG_COMPRESSION_OPTION_LEVEL) == 0)
compresslevel = Z_DEFAULT_COMPRESSION;
else
{

View File

@ -59,7 +59,7 @@ const bbsink_ops bbsink_lz4_ops = {
* Create a new basebackup sink that performs lz4 compression.
*/
bbsink *
bbsink_lz4_new(bbsink *next, bc_specification *compress)
bbsink_lz4_new(bbsink *next, pg_compress_specification *compress)
{
#ifndef USE_LZ4
ereport(ERROR,
@ -72,7 +72,7 @@ bbsink_lz4_new(bbsink *next, bc_specification *compress)
Assert(next != NULL);
if ((compress->options & BACKUP_COMPRESSION_OPTION_LEVEL) == 0)
if ((compress->options & PG_COMPRESSION_OPTION_LEVEL) == 0)
compresslevel = 0;
else
{

View File

@ -26,7 +26,7 @@ typedef struct bbsink_zstd
bbsink base;
/* Compression options */
bc_specification *compress;
pg_compress_specification *compress;
ZSTD_CCtx *cctx;
ZSTD_outBuffer zstd_outBuf;
@ -58,7 +58,7 @@ const bbsink_ops bbsink_zstd_ops = {
* Create a new basebackup sink that performs zstd compression.
*/
bbsink *
bbsink_zstd_new(bbsink *next, bc_specification *compress)
bbsink_zstd_new(bbsink *next, pg_compress_specification *compress)
{
#ifndef USE_ZSTD
ereport(ERROR,
@ -90,13 +90,13 @@ bbsink_zstd_begin_backup(bbsink *sink)
bbsink_zstd *mysink = (bbsink_zstd *) sink;
size_t output_buffer_bound;
size_t ret;
bc_specification *compress = mysink->compress;
pg_compress_specification *compress = mysink->compress;
mysink->cctx = ZSTD_createCCtx();
if (!mysink->cctx)
elog(ERROR, "could not create zstd compression context");
if ((compress->options & BACKUP_COMPRESSION_OPTION_LEVEL) != 0)
if ((compress->options & PG_COMPRESSION_OPTION_LEVEL) != 0)
{
ret = ZSTD_CCtx_setParameter(mysink->cctx, ZSTD_c_compressionLevel,
compress->level);
@ -105,7 +105,7 @@ bbsink_zstd_begin_backup(bbsink *sink)
compress->level, ZSTD_getErrorName(ret));
}
if ((compress->options & BACKUP_COMPRESSION_OPTION_WORKERS) != 0)
if ((compress->options & PG_COMPRESSION_OPTION_WORKERS) != 0)
{
/*
* On older versions of libzstd, this option does not exist, and trying

View File

@ -22,7 +22,7 @@
#ifndef BBSTREAMER_H
#define BBSTREAMER_H
#include "common/backup_compression.h"
#include "common/compression.h"
#include "lib/stringinfo.h"
#include "pqexpbuffer.h"
@ -201,17 +201,17 @@ bbstreamer_buffer_until(bbstreamer *streamer, const char **data, int *len,
*/
extern bbstreamer *bbstreamer_plain_writer_new(char *pathname, FILE *file);
extern bbstreamer *bbstreamer_gzip_writer_new(char *pathname, FILE *file,
bc_specification *compress);
pg_compress_specification *compress);
extern bbstreamer *bbstreamer_extractor_new(const char *basepath,
const char *(*link_map) (const char *),
void (*report_output_file) (const char *));
extern bbstreamer *bbstreamer_gzip_decompressor_new(bbstreamer *next);
extern bbstreamer *bbstreamer_lz4_compressor_new(bbstreamer *next,
bc_specification *compress);
pg_compress_specification *compress);
extern bbstreamer *bbstreamer_lz4_decompressor_new(bbstreamer *next);
extern bbstreamer *bbstreamer_zstd_compressor_new(bbstreamer *next,
bc_specification *compress);
pg_compress_specification *compress);
extern bbstreamer *bbstreamer_zstd_decompressor_new(bbstreamer *next);
extern bbstreamer *bbstreamer_tar_parser_new(bbstreamer *next);
extern bbstreamer *bbstreamer_tar_terminator_new(bbstreamer *next);

View File

@ -77,7 +77,7 @@ const bbstreamer_ops bbstreamer_gzip_decompressor_ops = {
*/
bbstreamer *
bbstreamer_gzip_writer_new(char *pathname, FILE *file,
bc_specification *compress)
pg_compress_specification *compress)
{
#ifdef HAVE_LIBZ
bbstreamer_gzip_writer *streamer;
@ -107,7 +107,7 @@ bbstreamer_gzip_writer_new(char *pathname, FILE *file,
pg_fatal("could not open output file: %m");
}
if ((compress->options & BACKUP_COMPRESSION_OPTION_LEVEL) != 0 &&
if ((compress->options & PG_COMPRESSION_OPTION_LEVEL) != 0 &&
gzsetparams(streamer->gzfile, compress->level,
Z_DEFAULT_STRATEGY) != Z_OK)
pg_fatal("could not set compression level %d: %s",

View File

@ -67,7 +67,7 @@ const bbstreamer_ops bbstreamer_lz4_decompressor_ops = {
* blocks.
*/
bbstreamer *
bbstreamer_lz4_compressor_new(bbstreamer *next, bc_specification *compress)
bbstreamer_lz4_compressor_new(bbstreamer *next, pg_compress_specification *compress)
{
#ifdef USE_LZ4
bbstreamer_lz4_frame *streamer;
@ -88,7 +88,7 @@ bbstreamer_lz4_compressor_new(bbstreamer *next, bc_specification *compress)
prefs = &streamer->prefs;
memset(prefs, 0, sizeof(LZ4F_preferences_t));
prefs->frameInfo.blockSizeID = LZ4F_max256KB;
if ((compress->options & BACKUP_COMPRESSION_OPTION_LEVEL) != 0)
if ((compress->options & PG_COMPRESSION_OPTION_LEVEL) != 0)
prefs->compressionLevel = compress->level;
ctxError = LZ4F_createCompressionContext(&streamer->cctx, LZ4F_VERSION);

View File

@ -63,7 +63,7 @@ const bbstreamer_ops bbstreamer_zstd_decompressor_ops = {
* blocks.
*/
bbstreamer *
bbstreamer_zstd_compressor_new(bbstreamer *next, bc_specification *compress)
bbstreamer_zstd_compressor_new(bbstreamer *next, pg_compress_specification *compress)
{
#ifdef USE_ZSTD
bbstreamer_zstd_frame *streamer;
@ -85,7 +85,7 @@ bbstreamer_zstd_compressor_new(bbstreamer *next, bc_specification *compress)
pg_fatal("could not create zstd compression context");
/* Set compression level, if specified */
if ((compress->options & BACKUP_COMPRESSION_OPTION_LEVEL) != 0)
if ((compress->options & PG_COMPRESSION_OPTION_LEVEL) != 0)
{
ret = ZSTD_CCtx_setParameter(streamer->cctx, ZSTD_c_compressionLevel,
compress->level);
@ -95,7 +95,7 @@ bbstreamer_zstd_compressor_new(bbstreamer *next, bc_specification *compress)
}
/* Set # of workers, if specified */
if ((compress->options & BACKUP_COMPRESSION_OPTION_WORKERS) != 0)
if ((compress->options & PG_COMPRESSION_OPTION_WORKERS) != 0)
{
/*
* On older versions of libzstd, this option does not exist, and

View File

@ -14,7 +14,7 @@ GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) \
receivelog.c \
streamutil.c \
walmethods.c \
../../common/backup_compression.c \
../../common/compression.c \
../../common/fe_memutils.c \
../../common/file_utils.c \
../../fe_utils/recovery_gen.c

View File

@ -29,7 +29,7 @@
#include "access/xlog_internal.h"
#include "bbstreamer.h"
#include "common/backup_compression.h"
#include "common/compression.h"
#include "common/file_perm.h"
#include "common/file_utils.h"
#include "common/logging.h"
@ -58,7 +58,7 @@ typedef struct TablespaceList
typedef struct ArchiveStreamState
{
int tablespacenum;
bc_specification *compress;
pg_compress_specification *compress;
bbstreamer *streamer;
bbstreamer *manifest_inject_streamer;
PQExpBuffer manifest_buffer;
@ -198,7 +198,7 @@ static bbstreamer *CreateBackupStreamer(char *archive_name, char *spclocation,
bbstreamer **manifest_inject_streamer_p,
bool is_recovery_guc_supported,
bool expect_unterminated_tarfile,
bc_specification *compress);
pg_compress_specification *compress);
static void ReceiveArchiveStreamChunk(size_t r, char *copybuf,
void *callback_data);
static char GetCopyDataByte(size_t r, char *copybuf, size_t *cursor);
@ -207,7 +207,7 @@ static uint64 GetCopyDataUInt64(size_t r, char *copybuf, size_t *cursor);
static void GetCopyDataEnd(size_t r, char *copybuf, size_t cursor);
static void ReportCopyDataParseError(size_t r, char *copybuf);
static void ReceiveTarFile(PGconn *conn, char *archive_name, char *spclocation,
bool tablespacenum, bc_specification *compress);
bool tablespacenum, pg_compress_specification *compress);
static void ReceiveTarCopyChunk(size_t r, char *copybuf, void *callback_data);
static void ReceiveBackupManifest(PGconn *conn);
static void ReceiveBackupManifestChunk(size_t r, char *copybuf,
@ -217,7 +217,7 @@ static void ReceiveBackupManifestInMemoryChunk(size_t r, char *copybuf,
void *callback_data);
static void BaseBackup(char *compression_algorithm, char *compression_detail,
CompressionLocation compressloc,
bc_specification *client_compress);
pg_compress_specification *client_compress);
static bool reached_end_position(XLogRecPtr segendpos, uint32 timeline,
bool segment_finished);
@ -1077,7 +1077,7 @@ CreateBackupStreamer(char *archive_name, char *spclocation,
bbstreamer **manifest_inject_streamer_p,
bool is_recovery_guc_supported,
bool expect_unterminated_tarfile,
bc_specification *compress)
pg_compress_specification *compress)
{
bbstreamer *streamer = NULL;
bbstreamer *manifest_inject_streamer = NULL;
@ -1193,23 +1193,23 @@ CreateBackupStreamer(char *archive_name, char *spclocation,
archive_file = NULL;
}
if (compress->algorithm == BACKUP_COMPRESSION_NONE)
if (compress->algorithm == PG_COMPRESSION_NONE)
streamer = bbstreamer_plain_writer_new(archive_filename,
archive_file);
else if (compress->algorithm == BACKUP_COMPRESSION_GZIP)
else if (compress->algorithm == PG_COMPRESSION_GZIP)
{
strlcat(archive_filename, ".gz", sizeof(archive_filename));
streamer = bbstreamer_gzip_writer_new(archive_filename,
archive_file, compress);
}
else if (compress->algorithm == BACKUP_COMPRESSION_LZ4)
else if (compress->algorithm == PG_COMPRESSION_LZ4)
{
strlcat(archive_filename, ".lz4", sizeof(archive_filename));
streamer = bbstreamer_plain_writer_new(archive_filename,
archive_file);
streamer = bbstreamer_lz4_compressor_new(streamer, compress);
}
else if (compress->algorithm == BACKUP_COMPRESSION_ZSTD)
else if (compress->algorithm == PG_COMPRESSION_ZSTD)
{
strlcat(archive_filename, ".zst", sizeof(archive_filename));
streamer = bbstreamer_plain_writer_new(archive_filename,
@ -1288,7 +1288,7 @@ CreateBackupStreamer(char *archive_name, char *spclocation,
* manifest if present - as a single COPY stream.
*/
static void
ReceiveArchiveStream(PGconn *conn, bc_specification *compress)
ReceiveArchiveStream(PGconn *conn, pg_compress_specification *compress)
{
ArchiveStreamState state;
@ -1604,7 +1604,7 @@ ReportCopyDataParseError(size_t r, char *copybuf)
*/
static void
ReceiveTarFile(PGconn *conn, char *archive_name, char *spclocation,
bool tablespacenum, bc_specification *compress)
bool tablespacenum, pg_compress_specification *compress)
{
WriteTarState state;
bbstreamer *manifest_inject_streamer;
@ -1758,7 +1758,7 @@ ReceiveBackupManifestInMemoryChunk(size_t r, char *copybuf,
static void
BaseBackup(char *compression_algorithm, char *compression_detail,
CompressionLocation compressloc, bc_specification *client_compress)
CompressionLocation compressloc, pg_compress_specification *client_compress)
{
PGresult *res;
char *sysidentifier;
@ -2025,11 +2025,11 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
if (verbose)
pg_log_info("starting background WAL receiver");
if (client_compress->algorithm == BACKUP_COMPRESSION_GZIP)
if (client_compress->algorithm == PG_COMPRESSION_GZIP)
{
wal_compress_method = COMPRESSION_GZIP;
wal_compress_level =
(client_compress->options & BACKUP_COMPRESSION_OPTION_LEVEL)
(client_compress->options & PG_COMPRESSION_OPTION_LEVEL)
!= 0 ? client_compress->level : 0;
}
else
@ -2316,7 +2316,7 @@ main(int argc, char **argv)
char *compression_algorithm = "none";
char *compression_detail = NULL;
CompressionLocation compressloc = COMPRESS_LOCATION_UNSPECIFIED;
bc_specification client_compress;
pg_compress_specification client_compress;
pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
@ -2558,15 +2558,15 @@ main(int argc, char **argv)
*/
if (compressloc == COMPRESS_LOCATION_CLIENT)
{
bc_algorithm alg;
pg_compress_algorithm alg;
char *error_detail;
if (!parse_bc_algorithm(compression_algorithm, &alg))
if (!parse_compress_algorithm(compression_algorithm, &alg))
pg_fatal("unrecognized compression algorithm \"%s\"",
compression_algorithm);
parse_bc_specification(alg, compression_detail, &client_compress);
error_detail = validate_bc_specification(&client_compress);
parse_compress_specification(alg, compression_detail, &client_compress);
error_detail = validate_compress_specification(&client_compress);
if (error_detail != NULL)
pg_fatal("invalid compression specification: %s",
error_detail);
@ -2574,7 +2574,7 @@ main(int argc, char **argv)
else
{
Assert(compressloc == COMPRESS_LOCATION_SERVER);
client_compress.algorithm = BACKUP_COMPRESSION_NONE;
client_compress.algorithm = PG_COMPRESSION_NONE;
client_compress.options = 0;
}
@ -2593,7 +2593,7 @@ main(int argc, char **argv)
* Client-side compression doesn't make sense unless tar format is in use.
*/
if (format == 'p' && compressloc == COMPRESS_LOCATION_CLIENT &&
client_compress.algorithm != BACKUP_COMPRESSION_NONE)
client_compress.algorithm != PG_COMPRESSION_NONE)
{
pg_log_error("only tar mode backups can be compressed");
pg_log_error_hint("Try \"%s --help\" for more information.", progname);

View File

@ -47,9 +47,9 @@ LIBS += $(PTHREAD_LIBS)
OBJS_COMMON = \
archive.o \
backup_compression.o \
base64.o \
checksum_helper.o \
compression.o \
config_info.o \
controldata_utils.o \
d2s.o \

View File

@ -1,8 +1,8 @@
/*-------------------------------------------------------------------------
*
* backup_compression.c
* compression.c
*
* Shared code for backup compression methods and specifications.
* Shared code for compression methods and specifications.
*
* A compression specification specifies the parameters that should be used
* when performing compression with a specific algorithm. The simplest
@ -12,12 +12,12 @@
* Otherwise, a compression specification is a comma-separated list of items,
* each having the form keyword or keyword=value.
*
* Currently, the only supported keyword is "level".
* Currently, the only supported keywords are "level" and "workers".
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
*
* IDENTIFICATION
* src/common/backup_compression.c
* src/common/compression.c
*-------------------------------------------------------------------------
*/
@ -27,26 +27,26 @@
#include "postgres_fe.h"
#endif
#include "common/backup_compression.h"
#include "common/compression.h"
static int expect_integer_value(char *keyword, char *value,
bc_specification *result);
pg_compress_specification *result);
/*
* Look up a compression algorithm by name. Returns true and sets *algorithm
* if the name is recognized. Otherwise returns false.
*/
bool
parse_bc_algorithm(char *name, bc_algorithm *algorithm)
parse_compress_algorithm(char *name, pg_compress_algorithm *algorithm)
{
if (strcmp(name, "none") == 0)
*algorithm = BACKUP_COMPRESSION_NONE;
*algorithm = PG_COMPRESSION_NONE;
else if (strcmp(name, "gzip") == 0)
*algorithm = BACKUP_COMPRESSION_GZIP;
*algorithm = PG_COMPRESSION_GZIP;
else if (strcmp(name, "lz4") == 0)
*algorithm = BACKUP_COMPRESSION_LZ4;
*algorithm = PG_COMPRESSION_LZ4;
else if (strcmp(name, "zstd") == 0)
*algorithm = BACKUP_COMPRESSION_ZSTD;
*algorithm = PG_COMPRESSION_ZSTD;
else
return false;
return true;
@ -57,17 +57,17 @@ parse_bc_algorithm(char *name, bc_algorithm *algorithm)
* algorithm.
*/
const char *
get_bc_algorithm_name(bc_algorithm algorithm)
get_compress_algorithm_name(pg_compress_algorithm algorithm)
{
switch (algorithm)
{
case BACKUP_COMPRESSION_NONE:
case PG_COMPRESSION_NONE:
return "none";
case BACKUP_COMPRESSION_GZIP:
case PG_COMPRESSION_GZIP:
return "gzip";
case BACKUP_COMPRESSION_LZ4:
case PG_COMPRESSION_LZ4:
return "lz4";
case BACKUP_COMPRESSION_ZSTD:
case PG_COMPRESSION_ZSTD:
return "zstd";
/* no default, to provoke compiler warnings if values are added */
}
@ -88,12 +88,12 @@ get_bc_algorithm_name(bc_algorithm algorithm)
* Note, however, even if there's no parse error, the string might not make
* sense: e.g. for gzip, level=12 is not sensible, but it does parse OK.
*
* Use validate_bc_specification() to find out whether a compression
* Use validate_compress_specification() to find out whether a compression
* specification is semantically sensible.
*/
void
parse_bc_specification(bc_algorithm algorithm, char *specification,
bc_specification *result)
parse_compress_specification(pg_compress_algorithm algorithm, char *specification,
pg_compress_specification *result)
{
int bare_level;
char *bare_level_endp;
@ -113,7 +113,7 @@ parse_bc_specification(bc_algorithm algorithm, char *specification,
if (specification != bare_level_endp && *bare_level_endp == '\0')
{
result->level = bare_level;
result->options |= BACKUP_COMPRESSION_OPTION_LEVEL;
result->options |= PG_COMPRESSION_OPTION_LEVEL;
return;
}
@ -175,12 +175,12 @@ parse_bc_specification(bc_algorithm algorithm, char *specification,
if (strcmp(keyword, "level") == 0)
{
result->level = expect_integer_value(keyword, value, result);
result->options |= BACKUP_COMPRESSION_OPTION_LEVEL;
result->options |= PG_COMPRESSION_OPTION_LEVEL;
}
else if (strcmp(keyword, "workers") == 0)
{
result->workers = expect_integer_value(keyword, value, result);
result->options |= BACKUP_COMPRESSION_OPTION_WORKERS;
result->options |= PG_COMPRESSION_OPTION_WORKERS;
}
else
result->parse_error =
@ -215,7 +215,7 @@ parse_bc_specification(bc_algorithm algorithm, char *specification,
* and return -1.
*/
static int
expect_integer_value(char *keyword, char *value, bc_specification *result)
expect_integer_value(char *keyword, char *value, pg_compress_specification *result)
{
int ivalue;
char *ivalue_endp;
@ -247,7 +247,7 @@ expect_integer_value(char *keyword, char *value, bc_specification *result)
* compression method.
*/
char *
validate_bc_specification(bc_specification *spec)
validate_compress_specification(pg_compress_specification *spec)
{
/* If it didn't even parse OK, it's definitely no good. */
if (spec->parse_error != NULL)
@ -258,24 +258,24 @@ validate_bc_specification(bc_specification *spec)
* a compression level and that the level is within the legal range for
* the algorithm.
*/
if ((spec->options & BACKUP_COMPRESSION_OPTION_LEVEL) != 0)
if ((spec->options & PG_COMPRESSION_OPTION_LEVEL) != 0)
{
int min_level = 1;
int max_level;
if (spec->algorithm == BACKUP_COMPRESSION_GZIP)
if (spec->algorithm == PG_COMPRESSION_GZIP)
max_level = 9;
else if (spec->algorithm == BACKUP_COMPRESSION_LZ4)
else if (spec->algorithm == PG_COMPRESSION_LZ4)
max_level = 12;
else if (spec->algorithm == BACKUP_COMPRESSION_ZSTD)
else if (spec->algorithm == PG_COMPRESSION_ZSTD)
max_level = 22;
else
return psprintf(_("compression algorithm \"%s\" does not accept a compression level"),
get_bc_algorithm_name(spec->algorithm));
get_compress_algorithm_name(spec->algorithm));
if (spec->level < min_level || spec->level > max_level)
return psprintf(_("compression algorithm \"%s\" expects a compression level between %d and %d"),
get_bc_algorithm_name(spec->algorithm),
get_compress_algorithm_name(spec->algorithm),
min_level, max_level);
}
@ -283,11 +283,11 @@ validate_bc_specification(bc_specification *spec)
* Of the compression algorithms that we currently support, only zstd
* allows parallel workers.
*/
if ((spec->options & BACKUP_COMPRESSION_OPTION_WORKERS) != 0 &&
(spec->algorithm != BACKUP_COMPRESSION_ZSTD))
if ((spec->options & PG_COMPRESSION_OPTION_WORKERS) != 0 &&
(spec->algorithm != PG_COMPRESSION_ZSTD))
{
return psprintf(_("compression algorithm \"%s\" does not accept a worker count"),
get_bc_algorithm_name(spec->algorithm));
get_compress_algorithm_name(spec->algorithm));
}
return NULL;

View File

@ -1,46 +0,0 @@
/*-------------------------------------------------------------------------
*
* backup_compression.h
*
* Shared definitions for backup compression methods and specifications.
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
*
* IDENTIFICATION
* src/common/backup_compression.h
*-------------------------------------------------------------------------
*/
#ifndef BACKUP_COMPRESSION_H
#define BACKUP_COMPRESSION_H
typedef enum bc_algorithm
{
BACKUP_COMPRESSION_NONE,
BACKUP_COMPRESSION_GZIP,
BACKUP_COMPRESSION_LZ4,
BACKUP_COMPRESSION_ZSTD
} bc_algorithm;
#define BACKUP_COMPRESSION_OPTION_LEVEL (1 << 0)
#define BACKUP_COMPRESSION_OPTION_WORKERS (1 << 1)
typedef struct bc_specification
{
bc_algorithm algorithm;
unsigned options; /* OR of BACKUP_COMPRESSION_OPTION constants */
int level;
int workers;
char *parse_error; /* NULL if parsing was OK, else message */
} bc_specification;
extern bool parse_bc_algorithm(char *name, bc_algorithm *algorithm);
extern const char *get_bc_algorithm_name(bc_algorithm algorithm);
extern void parse_bc_specification(bc_algorithm algorithm,
char *specification,
bc_specification *result);
extern char *validate_bc_specification(bc_specification *);
#endif

View File

@ -0,0 +1,46 @@
/*-------------------------------------------------------------------------
*
* compression.h
*
* Shared definitions for compression methods and specifications.
*
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
*
* IDENTIFICATION
* src/common/compression.h
*-------------------------------------------------------------------------
*/
#ifndef PG_COMPRESSION_H
#define PG_COMPRESSION_H
typedef enum pg_compress_algorithm
{
PG_COMPRESSION_NONE,
PG_COMPRESSION_GZIP,
PG_COMPRESSION_LZ4,
PG_COMPRESSION_ZSTD
} pg_compress_algorithm;
#define PG_COMPRESSION_OPTION_LEVEL (1 << 0)
#define PG_COMPRESSION_OPTION_WORKERS (1 << 1)
typedef struct pg_compress_specification
{
pg_compress_algorithm algorithm;
unsigned options; /* OR of PG_COMPRESSION_OPTION constants */
int level;
int workers;
char *parse_error; /* NULL if parsing was OK, else message */
} pg_compress_specification;
extern bool parse_compress_algorithm(char *name, pg_compress_algorithm *algorithm);
extern const char *get_compress_algorithm_name(pg_compress_algorithm algorithm);
extern void parse_compress_specification(pg_compress_algorithm algorithm,
char *specification,
pg_compress_specification *result);
extern char *validate_compress_specification(pg_compress_specification *);
#endif

View File

@ -27,7 +27,7 @@
#define BASEBACKUP_SINK_H
#include "access/xlog_internal.h"
#include "common/backup_compression.h"
#include "common/compression.h"
#include "nodes/pg_list.h"
/* Forward declarations. */
@ -284,9 +284,9 @@ extern void bbsink_forward_cleanup(bbsink *sink);
/* Constructors for various types of sinks. */
extern bbsink *bbsink_copystream_new(bool send_to_client);
extern bbsink *bbsink_gzip_new(bbsink *next, bc_specification *);
extern bbsink *bbsink_lz4_new(bbsink *next, bc_specification *);
extern bbsink *bbsink_zstd_new(bbsink *next, bc_specification *);
extern bbsink *bbsink_gzip_new(bbsink *next, pg_compress_specification *);
extern bbsink *bbsink_lz4_new(bbsink *next, pg_compress_specification *);
extern bbsink *bbsink_zstd_new(bbsink *next, pg_compress_specification *);
extern bbsink *bbsink_progress_new(bbsink *next, bool estimate_backup_size);
extern bbsink *bbsink_server_new(bbsink *next, char *pathname);
extern bbsink *bbsink_throttle_new(bbsink *next, uint32 maxrate);

View File

@ -124,7 +124,7 @@ sub mkvcbuild
}
our @pgcommonallfiles = qw(
archive.c backup_compression.c base64.c checksum_helper.c
archive.c base64.c checksum_helper.c compression.c
config_info.c controldata_utils.c d2s.c encnames.c exec.c
f2s.c file_perm.c file_utils.c hashfn.c ip.c jsonapi.c
keywords.c kwlookup.c link-canary.c md5_common.c

View File

@ -3365,6 +3365,8 @@ pg_be_sasl_mech
pg_checksum_context
pg_checksum_raw_context
pg_checksum_type
pg_compress_algorithm
pg_compress_specification
pg_conn_host
pg_conn_host_type
pg_conv_map