|
2 | 2 |
|
3 | 3 | import unittest
|
4 | 4 | import os
|
5 |
| -from .helpers.ptrack_helpers import ProbackupTest |
| 5 | +from .helpers.ptrack_helpers import ProbackupTest, ProbackupException |
6 | 6 |
|
7 | 7 | module_name = "merge"
|
8 | 8 |
|
@@ -622,3 +622,129 @@ def test_continue_failed_merge(self):
|
622 | 622 |
|
623 | 623 | # Clean after yourself
|
624 | 624 | 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 |
0 commit comments