Skip to content

Commit 3e06d9f

Browse files
committed
PGPRO-692: Improve check of compress-algorithm and compress-level
1 parent fbda569 commit 3e06d9f

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/archive.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ do_archive_push(char *wal_file_path, char *wal_file_name)
6464
if (access(backup_wal_file_path, F_OK) != -1)
6565
elog(ERROR, "file '%s', already exists.", backup_wal_file_path);
6666

67-
push_wal_file(absolute_wal_file_path, backup_wal_file_path,
68-
compress_shortcut);
67+
push_wal_file(absolute_wal_file_path, backup_wal_file_path);
6968
elog(INFO, "pg_probackup archive-push completed successfully");
7069

7170
return 0;

src/data.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ copy_meta(const char *from_path, const char *to_path)
750750
* Copy WAL segment from pgdata to archive catalog with possible compression.
751751
*/
752752
void
753-
push_wal_file(const char *from_path, const char *to_path, bool is_compress)
753+
push_wal_file(const char *from_path, const char *to_path)
754754
{
755755
FILE *in = NULL;
756756
FILE *out;
@@ -770,7 +770,10 @@ push_wal_file(const char *from_path, const char *to_path, bool is_compress)
770770

771771
/* open backup file for write */
772772
#ifdef HAVE_LIBZ
773-
if (is_compress)
773+
if (compress_alg == PGLZ_COMPRESS)
774+
elog(ERROR, "pglz compression is not supported");
775+
776+
if (compress_alg == ZLIB_COMPRESS)
774777
{
775778
snprintf(gz_to_path, sizeof(gz_to_path), "%s.gz", to_path);
776779
gz_out = gzopen(gz_to_path, "wb");
@@ -803,7 +806,7 @@ push_wal_file(const char *from_path, const char *to_path, bool is_compress)
803806
if (read_len > 0)
804807
{
805808
#ifdef HAVE_LIBZ
806-
if (is_compress)
809+
if (compress_alg == ZLIB_COMPRESS)
807810
{
808811
if (gzwrite(gz_out, buf, read_len) != read_len)
809812
elog(ERROR, "Cannot write to compressed WAL segment \"%s\": %s",
@@ -823,10 +826,10 @@ push_wal_file(const char *from_path, const char *to_path, bool is_compress)
823826
}
824827

825828
#ifdef HAVE_LIBZ
826-
if (is_compress && gzclose(gz_out) != 0)
829+
if (compress_alg == ZLIB_COMPRESS && gzclose(gz_out) != 0)
827830
elog(ERROR, "Cannot close compressed WAL segment \"%s\": %s",
828831
gz_to_path, get_gz_error(gz_out));
829-
else if (!is_compress)
832+
else if (compress_alg != ZLIB_COMPRESS)
830833
#endif
831834
{
832835
if (fflush(out) != 0 ||

src/pg_probackup.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ main(int argc, char *argv[])
403403
if (compress_level < 0 || compress_level > 9)
404404
elog(ERROR, "--compress-level value must be in the range from 0 to 9");
405405

406+
if (compress_level == 0)
407+
compress_alg = NOT_DEFINED_COMPRESS;
408+
406409
/* do actual operation */
407410
switch (backup_subcmd)
408411
{

src/pg_probackup.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ extern void restore_data_file(const char *from_root, const char *to_root,
427427
pgFile *file, pgBackup *backup);
428428
extern bool copy_file(const char *from_root, const char *to_root,
429429
pgFile *file);
430-
extern void push_wal_file(const char *from_path, const char *to_path,
431-
bool is_compress);
430+
extern void push_wal_file(const char *from_path, const char *to_path);
432431
extern void get_wal_file(const char *from_path, const char *to_path);
433432

434433
extern bool calc_file_checksum(pgFile *file);

0 commit comments

Comments
 (0)