Skip to content

Commit fcc4ed7

Browse files
gsmolkArthur Zakirov
authored and
Arthur Zakirov
committed
PGPRO-1892: added test_continue_failed_merge_with_corrupted_delta_backup
1 parent 03c9fba commit fcc4ed7

File tree

2 files changed

+138
-1
lines changed

2 files changed

+138
-1
lines changed

Diff for: tests/merge.py

+127-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import unittest
44
import os
5-
from .helpers.ptrack_helpers import ProbackupTest
5+
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
66

77
module_name = "merge"
88

@@ -622,3 +622,129 @@ def test_continue_failed_merge(self):
622622

623623
# Clean after yourself
624624
self.del_test_dir(module_name, fname)
625+
626+
# @unittest.skip("skip")
627+
def test_continue_failed_merge_with_corrupted_delta_backup(self):
628+
"""
629+
Fail merge via gdb, corrupt DELTA backup, try to continue merge
630+
"""
631+
fname = self.id().split('.')[3]
632+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
633+
node = self.make_simple_node(
634+
base_dir="{0}/{1}/node".format(module_name, fname),
635+
set_replication=True, initdb_params=['--data-checksums'],
636+
pg_options={
637+
'wal_level': 'replica'
638+
}
639+
)
640+
641+
self.init_pb(backup_dir)
642+
self.add_instance(backup_dir, 'node', node)
643+
self.set_archiving(backup_dir, 'node', node)
644+
node.start()
645+
646+
# FULL backup
647+
self.backup_node(backup_dir, 'node', node)
648+
649+
node.safe_psql(
650+
"postgres",
651+
"create table t_heap as select i as id,"
652+
" md5(i::text) as text, md5(i::text)::tsvector as tsvector"
653+
" from generate_series(0,1000) i"
654+
)
655+
656+
old_path = node.safe_psql(
657+
"postgres",
658+
"select pg_relation_filepath('t_heap')").rstrip()
659+
660+
# DELTA BACKUP
661+
self.backup_node(
662+
backup_dir, 'node', node, backup_type='delta'
663+
)
664+
665+
node.safe_psql(
666+
"postgres",
667+
"update t_heap set id = 100500"
668+
)
669+
670+
node.safe_psql(
671+
"postgres",
672+
"vacuum full t_heap"
673+
)
674+
675+
new_path = node.safe_psql(
676+
"postgres",
677+
"select pg_relation_filepath('t_heap')").rstrip()
678+
679+
# DELTA BACKUP
680+
backup_id_2 = self.backup_node(
681+
backup_dir, 'node', node, backup_type='delta'
682+
)
683+
684+
backup_id = self.show_pb(backup_dir, "node")[1]["id"]
685+
686+
# Failed MERGE
687+
gdb = self.merge_backup(backup_dir, "node", backup_id, gdb=True)
688+
gdb.set_breakpoint('copy_file')
689+
gdb.run_until_break()
690+
691+
if gdb.continue_execution_until_break(2) != 'breakpoint-hit':
692+
print('Failed to hit breakpoint')
693+
exit(1)
694+
695+
gdb._execute('signal SIGKILL')
696+
697+
print(self.show_pb(backup_dir, as_text=True, as_json=False))
698+
699+
# CORRUPT incremental backup
700+
# read block from future
701+
# block_size + backup_header = 8200
702+
file = os.path.join(
703+
backup_dir, 'backups/node', backup_id_2, 'database', new_path)
704+
with open(file, 'rb') as f:
705+
f.seek(8200)
706+
block_1 = f.read(8200)
707+
f.close
708+
709+
# write block from future
710+
file = os.path.join(
711+
backup_dir, 'backups/node', backup_id, 'database', old_path)
712+
with open(file, 'r+b') as f:
713+
f.seek(8200)
714+
f.write(block_1)
715+
f.close
716+
717+
# Try to continue failed MERGE
718+
try:
719+
self.merge_backup(backup_dir, "node", backup_id)
720+
self.assertEqual(
721+
1, 0,
722+
"Expecting Error because of incremental backup corruption.\n "
723+
"Output: {0} \n CMD: {1}".format(
724+
repr(self.output), self.cmd))
725+
except ProbackupException as e:
726+
self.assertEqual(
727+
e.message,
728+
'INSERT ERROR MESSAGE HERE\n',
729+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
730+
repr(e.message), self.cmd))
731+
732+
# Drop node and restore it
733+
node.cleanup()
734+
self.restore_node(backup_dir, 'node', node)
735+
736+
# Clean after yourself
737+
self.del_test_dir(module_name, fname)
738+
739+
# 1. always use parent link when merging (intermediates may be from different chain)
740+
# 2. page backup we are merging with may disappear after failed merge,
741+
# it should not be possible to continue merge after that
742+
# PAGE_A MERGING (disappear)
743+
# FULL MERGING
744+
745+
# FULL MERGING
746+
747+
# PAGE_B OK (new backup)
748+
# FULL MERGING
749+
750+
# 3. Need new test with corrupted FULL backup

Diff for: tests/validate_test.py

+11
Original file line numberDiff line numberDiff line change
@@ -3136,3 +3136,14 @@ def test_corrupt_pg_control_via_resetxlog(self):
31363136
self.del_test_dir(module_name, fname)
31373137

31383138
# validate empty backup list
3139+
# page from future during validate
3140+
# page from future during backup
3141+
3142+
# corrupt block, so file become unaligned:
3143+
# 712 Assert(header.compressed_size <= BLCKSZ);
3144+
# 713
3145+
# 714 read_len = fread(compressed_page.data, 1,
3146+
# 715 MAXALIGN(header.compressed_size), in);
3147+
# 716 if (read_len != MAXALIGN(header.compressed_size))
3148+
# -> 717 elog(ERROR, "cannot read block %u of \"%s\" read %lu of %d",
3149+
# 718 blknum, file->path, read_len, header.compressed_size);

0 commit comments

Comments
 (0)