diff --git a/src/data.c b/src/data.c index b9b25b11..1ed5bfee 100644 --- a/src/data.c +++ b/src/data.c @@ -1751,32 +1751,27 @@ fileEqualCRC(const char *path1, const char *path2, bool path2_is_compressed) INIT_CRC32C(crc2); gz_in = gzopen(path2, PG_BINARY_R); if (gz_in == NULL) - { - /* There is no such file or it cannot be read */ - elog(LOG, + /* File cannot be read */ + elog(ERROR, "Cannot compare WAL file \"%s\" with compressed \"%s\"", path1, path2); - return false; - } for (;;) { size_t read_len = 0; read_len = gzread(gz_in, buf, sizeof(buf)); if (read_len != sizeof(buf) && !gzeof(gz_in)) - { /* An error occurred while reading the file */ - elog(LOG, + elog(ERROR, "Cannot compare WAL file \"%s\" with compressed \"%s\"", path1, path2); - return false; - } + COMP_CRC32C(crc2, buf, read_len); if (gzeof(gz_in) || read_len == 0) break; } FIN_CRC32C(crc2); - + if (gzclose(gz_in) != 0) elog(ERROR, "Cannot close compressed WAL file \"%s\": %s", path2, get_gz_error(gz_in, errno)); diff --git a/tests/archive.py b/tests/archive.py index 4ed783d6..45b235cd 100644 --- a/tests/archive.py +++ b/tests/archive.py @@ -1,4 +1,6 @@ import os +import shutil +import zlib import unittest from .helpers.ptrack_helpers import ProbackupTest, ProbackupException, archive_script from datetime import datetime, timedelta @@ -325,7 +327,15 @@ class ArchiveTest(ProbackupTest, unittest.TestCase): ) self.assertFalse('pg_probackup archive-push completed successfully' in log_content) - os.remove(file) + wal_src = os.path.join(node.data_dir, 'pg_wal', '000000010000000000000001') + if self.archive_compress: + with open(wal_src, 'rb') as f_in, open(file, 'wb') as f_out: + original_wal = f_in.read() + compressed_wal = zlib.compress(original_wal, 1) + f_out.write(compressed_wal) + else: + shutil.copyfile(wal_src, file) + self.switch_wal_segment(node) sleep(5)