Skip to content

Commit 6e856bd

Browse files
committed
PGPRO-427: added test_page_backup_with_corrupted_wal_segment
1 parent 248c449 commit 6e856bd

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

tests/page.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,103 @@ def test_page_backup_with_lost_wal_segment(self):
722722
self.show_pb(backup_dir, 'node')[1]['status'],
723723
'Backup {0} should have STATUS "ERROR"')
724724

725+
# Multi-thread PAGE backup
726+
try:
727+
self.backup_node(
728+
backup_dir, 'node', node,
729+
backup_type='page',
730+
options=["-j", "4", '--log-level-file=verbose'])
731+
self.assertEqual(
732+
1, 0,
733+
"Expecting Error because of wal segment disappearance.\n "
734+
"Output: {0} \n CMD: {1}".format(
735+
self.output, self.cmd))
736+
except ProbackupException as e:
737+
self.assertTrue(
738+
'INFO: Wait for LSN' in e.message and
739+
'in archived WAL segment' in e.message and
740+
'WARNING: could not read WAL record at' in e.message and
741+
'ERROR: WAL segment "{0}" is absent\n'.format(
742+
file) in e.message,
743+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
744+
repr(e.message), self.cmd))
745+
746+
self.assertEqual(
747+
'ERROR',
748+
self.show_pb(backup_dir, 'node')[2]['status'],
749+
'Backup {0} should have STATUS "ERROR"')
750+
751+
# Clean after yourself
752+
self.del_test_dir(module_name, fname)
753+
754+
# @unittest.skip("skip")
755+
def test_page_backup_with_corrupted_wal_segment(self):
756+
"""
757+
make node with archiving
758+
make archive backup, then generate some wals with pgbench,
759+
corrupt latest archived wal segment
760+
run page backup, expecting error because of missing wal segment
761+
make sure that backup status is 'ERROR'
762+
"""
763+
fname = self.id().split('.')[3]
764+
node = self.make_simple_node(
765+
base_dir="{0}/{1}/node".format(module_name, fname),
766+
initdb_params=['--data-checksums'],
767+
pg_options={'wal_level': 'replica'}
768+
)
769+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
770+
self.init_pb(backup_dir)
771+
self.add_instance(backup_dir, 'node', node)
772+
self.set_archiving(backup_dir, 'node', node)
773+
node.start()
774+
775+
self.backup_node(backup_dir, 'node', node)
776+
777+
# make some wals
778+
node.pgbench_init(scale=3)
779+
780+
# delete last wal segment
781+
wals_dir = os.path.join(backup_dir, 'wal', 'node')
782+
wals = [f for f in os.listdir(wals_dir) if os.path.isfile(os.path.join(
783+
wals_dir, f)) and not f.endswith('.backup')]
784+
wals = map(str, wals)
785+
file = os.path.join(wals_dir, max(wals))
786+
# file = os.path.join(wals_dir, '000000010000000000000004')
787+
print(file)
788+
with open(file, "rb+", 0) as f:
789+
f.seek(42)
790+
f.write(b"blah")
791+
f.flush()
792+
f.close
793+
794+
if self.archive_compress:
795+
file = file[:-3]
796+
797+
# Single-thread PAGE backup
798+
try:
799+
self.backup_node(
800+
backup_dir, 'node', node,
801+
backup_type='page', options=['--log-level-file=verbose'])
802+
self.assertEqual(
803+
1, 0,
804+
"Expecting Error because of wal segment disappearance.\n "
805+
"Output: {0} \n CMD: {1}".format(
806+
self.output, self.cmd))
807+
except ProbackupException as e:
808+
self.assertTrue(
809+
'INFO: Wait for LSN' in e.message and
810+
'in archived WAL segment' in e.message and
811+
'WARNING: could not read WAL record at' in e.message and
812+
'ERROR: WAL segment "{0}" is absent\n'.format(
813+
file) in e.message,
814+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
815+
repr(e.message), self.cmd))
816+
817+
self.assertEqual(
818+
'ERROR',
819+
self.show_pb(backup_dir, 'node')[1]['status'],
820+
'Backup {0} should have STATUS "ERROR"')
821+
725822
# Multi-thread PAGE backup
726823
try:
727824
self.backup_node(

0 commit comments

Comments
 (0)