Skip to content

Commit 42e44f3

Browse files
committed
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/YlPQGNAAa04raObK@paquier.xyz
1 parent 42dbbca commit 42e44f3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/bin/pg_basebackup/walmethods.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
165165
{
166166
size_t ctx_out;
167167
size_t header_size;
168+
LZ4F_preferences_t prefs;
168169

169170
ctx_out = LZ4F_createCompressionContext(&ctx, LZ4F_VERSION);
170171
if (LZ4F_isError(ctx_out))
@@ -177,8 +178,12 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
177178
lz4bufsize = LZ4F_compressBound(LZ4_IN_SIZE, NULL);
178179
lz4buf = pg_malloc0(lz4bufsize);
179180

181+
/* assign the compression level, default is 0 */
182+
memset(&prefs, 0, sizeof(prefs));
183+
prefs.compressionLevel = dir_data->compression_level;
184+
180185
/* add the header */
181-
header_size = LZ4F_compressBegin(ctx, lz4buf, lz4bufsize, NULL);
186+
header_size = LZ4F_compressBegin(ctx, lz4buf, lz4bufsize, &prefs);
182187
if (LZ4F_isError(header_size))
183188
{
184189
dir_data->lasterrstring = LZ4F_getErrorName(header_size);

0 commit comments

Comments
 (0)