Skip to content

Commit 9256d32

Browse files
committed
tests: added test_drop_rel_during_backup_delta(), test_drop_rel_during_backup_page() and test_drop_rel_during_backup_ptrack()
1 parent eae31a1 commit 9256d32

File tree

1 file changed

+196
-0
lines changed

1 file changed

+196
-0
lines changed

tests/backup_test.py

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,199 @@ def test_tablespace_handling(self):
626626

627627
# Clean after yourself
628628
self.del_test_dir(module_name, fname)
629+
630+
# @unittest.skip("skip")
631+
def test_drop_rel_during_backup_delta(self):
632+
""""""
633+
fname = self.id().split('.')[3]
634+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
635+
node = self.make_simple_node(
636+
base_dir=os.path.join(module_name, fname, 'node'),
637+
set_replication=True,
638+
initdb_params=['--data-checksums'],
639+
pg_options={
640+
'wal_level': 'replica'})
641+
642+
self.init_pb(backup_dir)
643+
self.add_instance(backup_dir, 'node', node)
644+
self.set_archiving(backup_dir, 'node', node)
645+
node.slow_start()
646+
647+
node.safe_psql(
648+
"postgres",
649+
"create table t_heap as select i"
650+
" as id from generate_series(0,100) i")
651+
652+
relative_path = node.safe_psql(
653+
"postgres",
654+
"select pg_relation_filepath('t_heap')").rstrip()
655+
656+
absolute_path = os.path.join(node.data_dir, relative_path)
657+
658+
# FULL backup
659+
self.backup_node(backup_dir, 'node', node, options=['--stream'])
660+
661+
# DELTA backup
662+
gdb = self.backup_node(
663+
backup_dir, 'node', node, backup_type='delta',
664+
gdb=True, options=['--log-level-file=verbose'])
665+
666+
gdb.set_breakpoint('backup_files')
667+
gdb.run_until_break()
668+
669+
# REMOVE file
670+
node.safe_psql(
671+
"postgres",
672+
"DROP TABLE t_heap")
673+
674+
node.safe_psql(
675+
"postgres",
676+
"CHECKPOINT")
677+
678+
# File removed, we can proceed with backup
679+
gdb.continue_execution_until_exit()
680+
681+
pgdata = self.pgdata_content(node.data_dir)
682+
683+
with open(os.path.join(backup_dir, 'log', 'pg_probackup.log')) as f:
684+
log_content = f.read()
685+
self.assertTrue(
686+
'LOG: File "{0}" is not found'.format(absolute_path) in log_content,
687+
'File "{0}" should be deleted but it`s not'.format(absolute_path))
688+
689+
node.cleanup()
690+
self.restore_node(backup_dir, 'node', node, options=["-j", "4"])
691+
692+
# Physical comparison
693+
pgdata_restored = self.pgdata_content(node.data_dir)
694+
self.compare_pgdata(pgdata, pgdata_restored)
695+
696+
# Clean after yourself
697+
self.del_test_dir(module_name, fname)
698+
699+
# @unittest.skip("skip")
700+
def test_drop_rel_during_backup_page(self):
701+
""""""
702+
fname = self.id().split('.')[3]
703+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
704+
node = self.make_simple_node(
705+
base_dir=os.path.join(module_name, fname, 'node'),
706+
set_replication=True,
707+
initdb_params=['--data-checksums'],
708+
pg_options={
709+
'wal_level': 'replica'})
710+
711+
self.init_pb(backup_dir)
712+
self.add_instance(backup_dir, 'node', node)
713+
self.set_archiving(backup_dir, 'node', node)
714+
node.slow_start()
715+
716+
node.safe_psql(
717+
"postgres",
718+
"create table t_heap as select i"
719+
" as id from generate_series(0,100) i")
720+
721+
relative_path = node.safe_psql(
722+
"postgres",
723+
"select pg_relation_filepath('t_heap')").rstrip()
724+
725+
absolute_path = os.path.join(node.data_dir, relative_path)
726+
727+
# FULL backup
728+
self.backup_node(backup_dir, 'node', node, options=['--stream'])
729+
730+
# PAGE backup
731+
gdb = self.backup_node(
732+
backup_dir, 'node', node, backup_type='page',
733+
gdb=True, options=['--log-level-file=verbose'])
734+
735+
gdb.set_breakpoint('backup_files')
736+
gdb.run_until_break()
737+
738+
# REMOVE file
739+
os.remove(absolute_path)
740+
741+
# File removed, we can proceed with backup
742+
gdb.continue_execution_until_exit()
743+
744+
pgdata = self.pgdata_content(node.data_dir)
745+
746+
with open(os.path.join(backup_dir, 'log', 'pg_probackup.log')) as f:
747+
log_content = f.read()
748+
self.assertTrue(
749+
'LOG: File "{0}" is not found'.format(absolute_path) in log_content,
750+
'File "{0}" should be deleted but it`s not'.format(absolute_path))
751+
752+
node.cleanup()
753+
self.restore_node(backup_dir, 'node', node, options=["-j", "4"])
754+
755+
# Physical comparison
756+
pgdata_restored = self.pgdata_content(node.data_dir)
757+
self.compare_pgdata(pgdata, pgdata_restored)
758+
759+
# Clean after yourself
760+
self.del_test_dir(module_name, fname)
761+
762+
# @unittest.skip("skip")
763+
def test_drop_rel_during_backup_ptrack(self):
764+
""""""
765+
fname = self.id().split('.')[3]
766+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
767+
node = self.make_simple_node(
768+
base_dir=os.path.join(module_name, fname, 'node'),
769+
set_replication=True,
770+
initdb_params=['--data-checksums'],
771+
pg_options={
772+
'wal_level': 'replica',
773+
'ptrack_enable': 'on'})
774+
775+
self.init_pb(backup_dir)
776+
self.add_instance(backup_dir, 'node', node)
777+
self.set_archiving(backup_dir, 'node', node)
778+
node.slow_start()
779+
780+
node.safe_psql(
781+
"postgres",
782+
"create table t_heap as select i"
783+
" as id from generate_series(0,100) i")
784+
785+
relative_path = node.safe_psql(
786+
"postgres",
787+
"select pg_relation_filepath('t_heap')").rstrip()
788+
789+
absolute_path = os.path.join(node.data_dir, relative_path)
790+
791+
# FULL backup
792+
self.backup_node(backup_dir, 'node', node, options=['--stream'])
793+
794+
# PTRACK backup
795+
gdb = self.backup_node(
796+
backup_dir, 'node', node, backup_type='ptrack',
797+
gdb=True, options=['--log-level-file=verbose'])
798+
799+
gdb.set_breakpoint('backup_files')
800+
gdb.run_until_break()
801+
802+
# REMOVE file
803+
os.remove(absolute_path)
804+
805+
# File removed, we can proceed with backup
806+
gdb.continue_execution_until_exit()
807+
808+
pgdata = self.pgdata_content(node.data_dir)
809+
810+
with open(os.path.join(backup_dir, 'log', 'pg_probackup.log')) as f:
811+
log_content = f.read()
812+
self.assertTrue(
813+
'LOG: File "{0}" is not found'.format(absolute_path) in log_content,
814+
'File "{0}" should be deleted but it`s not'.format(absolute_path))
815+
816+
node.cleanup()
817+
self.restore_node(backup_dir, 'node', node, options=["-j", "4"])
818+
819+
# Physical comparison
820+
pgdata_restored = self.pgdata_content(node.data_dir)
821+
self.compare_pgdata(pgdata, pgdata_restored)
822+
823+
# Clean after yourself
824+
self.del_test_dir(module_name, fname)

0 commit comments

Comments
 (0)