postgresql/src/include/common/compression.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.6 KiB
C
Raw Normal View History

/*-------------------------------------------------------------------------
*
* compression.h
*
* Shared definitions for compression methods and specifications.
*
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
*
* IDENTIFICATION
* src/include/common/compression.h
*-------------------------------------------------------------------------
*/
#ifndef PG_COMPRESSION_H
#define PG_COMPRESSION_H
/*
* These values are stored in disk, for example in files generated by pg_dump.
* Create the necessary backwards compatibility layers if their order changes.
*/
typedef enum pg_compress_algorithm
{
PG_COMPRESSION_NONE,
PG_COMPRESSION_GZIP,
PG_COMPRESSION_LZ4,
PG_COMPRESSION_ZSTD
} pg_compress_algorithm;
Simplify handling of compression level with compression specifications PG_COMPRESSION_OPTION_LEVEL is removed from the compression specification logic, and instead the compression level is always assigned with each library's default if nothing is directly given. This centralizes the checks on the compression methods supported by a given build, and always assigns a default compression level when parsing a compression specification. This results in complaining at an earlier stage than previously if a build supports a compression method or not, aka when parsing a specification in the backend or the frontend, and not when processing it. zstd, lz4 and zlib are able to handle in their respective routines setting up the compression level the case of a default value, hence the backend or frontend code (pg_receivewal or pg_basebackup) has now no need to know what the default compression level should be if nothing is specified: the logic is now done so as the specification parsing assigns it. It can also be enforced by passing down a "level" set to the default value, that the backend will accept (the replication protocol is for example able to handle a command like BASE_BACKUP (COMPRESSION_DETAIL 'gzip:level=-1')). This code simplification fixes an issue with pg_basebackup --gzip introduced by ffd5365, where the tarball of the streamed WAL segments would be created as of pg_wal.tar.gz with uncompressed contents, while the intention is to compress the segments with gzip at a default level. The origin of the confusion comes from the handling of the default compression level of gzip (-1 or Z_DEFAULT_COMPRESSION) and the value of 0 was getting assigned, which is what walmethods.c would consider as equivalent to no compression when streaming WAL segments with its tar methods. Assigning always the compression level removes the confusion of some code paths considering a value of 0 set in a specification as either no compression or a default compression level. Note that 010_pg_basebackup.pl has to be adjusted to skip a few tests where the shape of the compression detail string for client and server-side compression was checked using gzip. This is a result of the code simplification, as gzip specifications cannot be used if a build does not support it. Reported-by: Tom Lane Reviewed-by: Tom Lane Discussion: https://postgr.es/m/1400032.1662217889@sss.pgh.pa.us Backpatch-through: 15
2022-09-14 05:16:57 +02:00
#define PG_COMPRESSION_OPTION_WORKERS (1 << 0)
#define PG_COMPRESSION_OPTION_LONG_DISTANCE (1 << 1)
typedef struct pg_compress_specification
{
pg_compress_algorithm algorithm;
unsigned options; /* OR of PG_COMPRESSION_OPTION constants */
int level;
int workers;
bool long_distance;
char *parse_error; /* NULL if parsing was OK, else message */
} pg_compress_specification;
extern void parse_compress_options(const char *option, char **algorithm,
char **detail);
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