summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2022-04-18 01:18:34 +0000
committerMichael Paquier2022-04-18 01:18:34 +0000
commit42e44f3b3830cbc051a5d83956546e2ef553b047 (patch)
tree4c646b477c0f3ac5313b5a1ec3df4d49af5c82d0
parent42dbbca58e8e87e461bb0a4fe48a450e90e1e932 (diff)
Handle compression level in pg_receivewal for LZ4
The new option set of pg_receivewal introduced in 042a923 to control the compression method makes it now easy to pass down various options, including the compression level. The change to be able to do is simple, and requires one LZ4F_preferences_t fed to LZ4F_compressBegin(). Note that LZ4F_INIT_PREFERENCES could be used to initialize the contents of LZ4F_preferences_t as required by LZ4, but this is only available since v1.8.3. memset()'ing its structure to 0 is enough. Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/bin/pg_basebackup/walmethods.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c
index d5bcc208a9..cc292718da 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -165,6 +165,7 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
{
size_t ctx_out;
size_t header_size;
+ LZ4F_preferences_t prefs;
ctx_out = LZ4F_createCompressionContext(&ctx, LZ4F_VERSION);
if (LZ4F_isError(ctx_out))
@@ -177,8 +178,12 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
lz4bufsize = LZ4F_compressBound(LZ4_IN_SIZE, NULL);
lz4buf = pg_malloc0(lz4bufsize);
+ /* assign the compression level, default is 0 */
+ memset(&prefs, 0, sizeof(prefs));
+ prefs.compressionLevel = dir_data->compression_level;
+
/* add the header */
- header_size = LZ4F_compressBegin(ctx, lz4buf, lz4bufsize, NULL);
+ header_size = LZ4F_compressBegin(ctx, lz4buf, lz4bufsize, &prefs);
if (LZ4F_isError(header_size))
{
dir_data->lasterrstring = LZ4F_getErrorName(header_size);