diff options
author | Tomas Vondra | 2023-02-23 20:19:19 +0000 |
---|---|---|
committer | Tomas Vondra | 2023-02-23 20:19:26 +0000 |
commit | 0da243fed0875932f781aff08df782b56af58d02 (patch) | |
tree | 6b9699a82ab82a823c7c9305d1a644b320de16b4 /src/bin/pg_dump/compress_io.c | |
parent | e0b3074e894496b41b57fd1c96ede68803cf3df8 (diff) |
Add LZ4 compression to pg_dump
Expand pg_dump's compression streaming and file APIs to support the lz4
algorithm. The newly added compress_lz4.{c,h} files cover all the
functionality of the aforementioned APIs. Minor changes were necessary
in various pg_backup_* files, where code for the 'lz4' file suffix has
been added, as well as pg_dump's compression option parsing.
Author: Georgios Kokolatos
Reviewed-by: Michael Paquier, Rachel Heaton, Justin Pryzby, Shi Yu, Tomas Vondra
Discussion: https://postgr.es/m/faUNEOpts9vunEaLnmxmG-DldLSg_ql137OC3JYDmgrOMHm1RvvWY2IdBkv_CRxm5spCCb_OmKNk2T03TMm0fBEWveFF9wA1WizPuAgB7Ss%3D%40protonmail.com
Diffstat (limited to 'src/bin/pg_dump/compress_io.c')
-rw-r--r-- | src/bin/pg_dump/compress_io.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/bin/pg_dump/compress_io.c b/src/bin/pg_dump/compress_io.c index c2eb3dbb4a4..ce06f1eac9c 100644 --- a/src/bin/pg_dump/compress_io.c +++ b/src/bin/pg_dump/compress_io.c @@ -53,7 +53,7 @@ * InitDiscoverCompressFileHandle tries to infer the compression by the * filename suffix. If the suffix is not yet known then it tries to simply * open the file and if it fails, it tries to open the same file with the .gz - * suffix. + * suffix, and then again with the .lz4 suffix. * * IDENTIFICATION * src/bin/pg_dump/compress_io.c @@ -67,6 +67,7 @@ #include "compress_gzip.h" #include "compress_io.h" +#include "compress_lz4.h" #include "compress_none.h" #include "pg_backup_utils.h" @@ -93,6 +94,10 @@ supports_compression(const pg_compress_specification compression_spec) if (algorithm == PG_COMPRESSION_GZIP) supported = true; #endif +#ifdef USE_LZ4 + if (algorithm == PG_COMPRESSION_LZ4) + supported = true; +#endif if (!supported) return psprintf("this build does not support compression with %s", @@ -123,6 +128,8 @@ AllocateCompressor(const pg_compress_specification compression_spec, InitCompressorNone(cs, compression_spec); else if (compression_spec.algorithm == PG_COMPRESSION_GZIP) InitCompressorGzip(cs, compression_spec); + else if (compression_spec.algorithm == PG_COMPRESSION_LZ4) + InitCompressorLZ4(cs, compression_spec); return cs; } @@ -187,6 +194,8 @@ InitCompressFileHandle(const pg_compress_specification compression_spec) InitCompressFileHandleNone(CFH, compression_spec); else if (compression_spec.algorithm == PG_COMPRESSION_GZIP) InitCompressFileHandleGzip(CFH, compression_spec); + else if (compression_spec.algorithm == PG_COMPRESSION_LZ4) + InitCompressFileHandleLZ4(CFH, compression_spec); return CFH; } @@ -196,11 +205,11 @@ InitCompressFileHandle(const pg_compress_specification compression_spec) * be either "r" or "rb". * * If the file at 'path' contains the suffix of a supported compression method, - * currently this includes only ".gz", then this compression will be used + * currently this includes ".gz" and ".lz4", then this compression will be used * throughout. Otherwise the compression will be inferred by iteratively trying * to open the file at 'path', first as is, then by appending known compression * suffixes. So if you pass "foo" as 'path', this will open either "foo" or - * "foo.gz", trying in that order. + * "foo.gz" or "foo.lz4", trying in that order. * * On failure, return NULL with an error code in errno. */ @@ -239,6 +248,17 @@ InitDiscoverCompressFileHandle(const char *path, const char *mode) compression_spec.algorithm = PG_COMPRESSION_GZIP; } #endif +#ifdef USE_LZ4 + if (!exists) + { + free_keep_errno(fname); + fname = psprintf("%s.lz4", path); + exists = (stat(fname, &st) == 0); + + if (exists) + compression_spec.algorithm = PG_COMPRESSION_LZ4; + } +#endif } CFH = InitCompressFileHandle(compression_spec); |