@@ -660,3 +660,92 @@ def test_parallel_pagemap_1(self):
660
660
# Clean after yourself
661
661
node .cleanup ()
662
662
self .del_test_dir (module_name , fname )
663
+
664
+ # @unittest.skip("skip")
665
+ def test_page_backup_with_lost_wal_segment (self ):
666
+ """
667
+ make node with archiving
668
+ make archive backup, then generate some wals with pgbench,
669
+ delete latest archived wal segment
670
+ run page backup, expecting error because of missing wal segment
671
+ make sure that backup status is 'ERROR'
672
+ """
673
+ fname = self .id ().split ('.' )[3 ]
674
+ node = self .make_simple_node (
675
+ base_dir = "{0}/{1}/node" .format (module_name , fname ),
676
+ initdb_params = ['--data-checksums' ],
677
+ pg_options = {'wal_level' : 'replica' }
678
+ )
679
+ backup_dir = os .path .join (self .tmp_path , module_name , fname , 'backup' )
680
+ self .init_pb (backup_dir )
681
+ self .add_instance (backup_dir , 'node' , node )
682
+ self .set_archiving (backup_dir , 'node' , node )
683
+ node .start ()
684
+
685
+ self .backup_node (backup_dir , 'node' , node )
686
+
687
+ # make some wals
688
+ node .pgbench_init (scale = 3 )
689
+
690
+ # delete last wal segment
691
+ wals_dir = os .path .join (backup_dir , 'wal' , 'node' )
692
+ wals = [f for f in os .listdir (wals_dir ) if os .path .isfile (os .path .join (
693
+ wals_dir , f )) and not f .endswith ('.backup' )]
694
+ wals = map (str , wals )
695
+ file = os .path .join (wals_dir , max (wals ))
696
+ os .remove (file )
697
+ if self .archive_compress :
698
+ file = file [:- 3 ]
699
+
700
+ # Single-thread PAGE backup
701
+ try :
702
+ self .backup_node (
703
+ backup_dir , 'node' , node ,
704
+ backup_type = 'page' )
705
+ self .assertEqual (
706
+ 1 , 0 ,
707
+ "Expecting Error because of wal segment disappearance.\n "
708
+ "Output: {0} \n CMD: {1}" .format (
709
+ self .output , self .cmd ))
710
+ except ProbackupException as e :
711
+ self .assertTrue (
712
+ 'INFO: Wait for LSN' in e .message and
713
+ 'in archived WAL segment' in e .message and
714
+ 'WARNING: could not read WAL record at' in e .message and
715
+ 'ERROR: WAL segment "{0}" is absent\n ' .format (
716
+ file ) in e .message ,
717
+ '\n Unexpected Error Message: {0}\n CMD: {1}' .format (
718
+ repr (e .message ), self .cmd ))
719
+
720
+ self .assertEqual (
721
+ 'ERROR' ,
722
+ self .show_pb (backup_dir , 'node' )[1 ]['status' ],
723
+ 'Backup {0} should have STATUS "ERROR"' )
724
+
725
+ # Multi-thread PAGE backup
726
+ try :
727
+ self .backup_node (
728
+ backup_dir , 'node' , node ,
729
+ backup_type = 'page' , options = ["-j" , "4" ])
730
+ self .assertEqual (
731
+ 1 , 0 ,
732
+ "Expecting Error because of wal segment disappearance.\n "
733
+ "Output: {0} \n CMD: {1}" .format (
734
+ self .output , self .cmd ))
735
+ except ProbackupException as e :
736
+ self .assertTrue (
737
+ 'INFO: Wait for LSN' in e .message and
738
+ 'in archived WAL segment' in e .message and
739
+ 'WARNING: could not read WAL record at' in e .message and
740
+ 'ERROR: WAL segment "{0}" is absent\n ' .format (
741
+ file ) in e .message ,
742
+ '\n Unexpected Error Message: {0}\n CMD: {1}' .format (
743
+ repr (e .message ), self .cmd ))
744
+
745
+ self .assertEqual (
746
+ 'ERROR' ,
747
+ self .show_pb (backup_dir , 'node' )[1 ]['status' ],
748
+ 'Backup {0} should have STATUS "ERROR"' )
749
+
750
+ # Clean after yourself
751
+ self .del_test_dir (module_name , fname )
0 commit comments