Skip to content

Commit 20d4dcc

Browse files
Modifyed test test_arhive_push_file_exists. Fixed fileEqualCRC()
error handling
1 parent 6deb3bb commit 20d4dcc

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/data.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,32 +1751,27 @@ fileEqualCRC(const char *path1, const char *path2, bool path2_is_compressed)
17511751
INIT_CRC32C(crc2);
17521752
gz_in = gzopen(path2, PG_BINARY_R);
17531753
if (gz_in == NULL)
1754-
{
1755-
/* There is no such file or it cannot be read */
1756-
elog(LOG,
1754+
/* File cannot be read */
1755+
elog(ERROR,
17571756
"Cannot compare WAL file \"%s\" with compressed \"%s\"",
17581757
path1, path2);
1759-
return false;
1760-
}
17611758

17621759
for (;;)
17631760
{
17641761
size_t read_len = 0;
17651762
read_len = gzread(gz_in, buf, sizeof(buf));
17661763
if (read_len != sizeof(buf) && !gzeof(gz_in))
1767-
{
17681764
/* An error occurred while reading the file */
1769-
elog(LOG,
1765+
elog(ERROR,
17701766
"Cannot compare WAL file \"%s\" with compressed \"%s\"",
17711767
path1, path2);
1772-
return false;
1773-
}
1768+
17741769
COMP_CRC32C(crc2, buf, read_len);
17751770
if (gzeof(gz_in) || read_len == 0)
17761771
break;
17771772
}
17781773
FIN_CRC32C(crc2);
1779-
1774+
17801775
if (gzclose(gz_in) != 0)
17811776
elog(ERROR, "Cannot close compressed WAL file \"%s\": %s",
17821777
path2, get_gz_error(gz_in, errno));

tests/archive.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
import shutil
3+
import zlib
24
import unittest
35
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException, archive_script
46
from datetime import datetime, timedelta
@@ -325,7 +327,15 @@ def test_arhive_push_file_exists(self):
325327
)
326328
self.assertFalse('pg_probackup archive-push completed successfully' in log_content)
327329

328-
os.remove(file)
330+
wal_src = os.path.join(node.data_dir, 'pg_wal', '000000010000000000000001')
331+
if self.archive_compress:
332+
with open(wal_src, 'rb') as f_in, open(file, 'wb') as f_out:
333+
original_wal = f_in.read()
334+
compressed_wal = zlib.compress(original_wal, 1)
335+
f_out.write(compressed_wal)
336+
else:
337+
shutil.copyfile(wal_src, file)
338+
329339
self.switch_wal_segment(node)
330340
sleep(5)
331341

0 commit comments

Comments
 (0)