1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

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