|
14 | 14 | #include <time.h>
|
15 | 15 | #include <unistd.h>
|
16 | 16 |
|
17 |
| -static void delete_walfiles(XLogRecPtr oldest_lsn, TimeLineID oldest_tli, |
18 |
| - uint32 xlog_seg_size); |
19 |
| -static void delete_walfiles_internal(XLogRecPtr keep_lsn, timelineInfo *tli, |
| 17 | +static void delete_walfiles(XLogRecPtr keep_lsn, timelineInfo *tli, |
20 | 18 | uint32 xlog_seg_size, bool dry_run);
|
21 | 19 | static void do_retention_internal(parray *backup_list, parray *to_keep_list,
|
22 | 20 | parray *to_purge_list);
|
@@ -641,10 +639,10 @@ do_retention_wal(bool dry_run)
|
641 | 639 | * can be safely purged.
|
642 | 640 | */
|
643 | 641 | if (tlinfo->oldest_backup)
|
644 |
| - delete_walfiles_internal(tlinfo->oldest_backup->start_lsn, |
| 642 | + delete_walfiles(tlinfo->oldest_backup->start_lsn, |
645 | 643 | tlinfo, instance_config.xlog_seg_size, dry_run);
|
646 | 644 | else
|
647 |
| - delete_walfiles_internal(InvalidXLogRecPtr, |
| 645 | + delete_walfiles(InvalidXLogRecPtr, |
648 | 646 | tlinfo, instance_config.xlog_seg_size, dry_run);
|
649 | 647 | }
|
650 | 648 | }
|
@@ -732,7 +730,7 @@ delete_backup_files(pgBackup *backup)
|
732 | 730 | * Q: Maybe we should stop treating partial WAL segments as second-class citizens?
|
733 | 731 | */
|
734 | 732 | static void
|
735 |
| -delete_walfiles_internal(XLogRecPtr keep_lsn, timelineInfo *tlinfo, |
| 733 | +delete_walfiles(XLogRecPtr keep_lsn, timelineInfo *tlinfo, |
736 | 734 | uint32 xlog_seg_size, bool dry_run)
|
737 | 735 | {
|
738 | 736 | XLogSegNo StartSegNo; /* First segment to delete */
|
@@ -866,118 +864,6 @@ delete_walfiles_internal(XLogRecPtr keep_lsn, timelineInfo *tlinfo,
|
866 | 864 | }
|
867 | 865 | }
|
868 | 866 |
|
869 |
| -/* |
870 |
| - * Deletes WAL segments up to oldest_lsn or all WAL segments (if all backups |
871 |
| - * was deleted and so oldest_lsn is invalid). |
872 |
| - * |
873 |
| - * oldest_lsn - if valid, function deletes WAL segments, which contain lsn |
874 |
| - * older than oldest_lsn. If it is invalid function deletes all WAL segments. |
875 |
| - * oldest_tli - is used to construct oldest WAL segment in addition to |
876 |
| - * oldest_lsn. |
877 |
| - */ |
878 |
| -static void |
879 |
| -delete_walfiles(XLogRecPtr oldest_lsn, TimeLineID oldest_tli, |
880 |
| - uint32 xlog_seg_size) |
881 |
| -{ |
882 |
| - XLogSegNo targetSegNo; |
883 |
| - char oldestSegmentNeeded[MAXFNAMELEN]; |
884 |
| - DIR *arcdir; |
885 |
| - struct dirent *arcde; |
886 |
| - char wal_file[MAXPGPATH]; |
887 |
| - char max_wal_file[MAXPGPATH]; |
888 |
| - char min_wal_file[MAXPGPATH]; |
889 |
| - int rc; |
890 |
| - |
891 |
| - max_wal_file[0] = '\0'; |
892 |
| - min_wal_file[0] = '\0'; |
893 |
| - |
894 |
| - if (!XLogRecPtrIsInvalid(oldest_lsn)) |
895 |
| - { |
896 |
| - GetXLogSegNo(oldest_lsn, targetSegNo, xlog_seg_size); |
897 |
| - GetXLogFileName(oldestSegmentNeeded, oldest_tli, targetSegNo, |
898 |
| - xlog_seg_size); |
899 |
| - |
900 |
| - elog(LOG, "removing WAL segments older than %s", oldestSegmentNeeded); |
901 |
| - } |
902 |
| - else |
903 |
| - elog(LOG, "removing all WAL segments"); |
904 |
| - |
905 |
| - /* |
906 |
| - * Now it is time to do the actual work and to remove all the segments |
907 |
| - * not needed anymore. |
908 |
| - */ |
909 |
| - if ((arcdir = opendir(arclog_path)) != NULL) |
910 |
| - { |
911 |
| - while (errno = 0, (arcde = readdir(arcdir)) != NULL) |
912 |
| - { |
913 |
| - /* |
914 |
| - * We ignore the timeline part of the WAL segment identifiers in |
915 |
| - * deciding whether a segment is still needed. This ensures that |
916 |
| - * we won't prematurely remove a segment from a parent timeline. |
917 |
| - * We could probably be a little more proactive about removing |
918 |
| - * segments of non-parent timelines, but that would be a whole lot |
919 |
| - * more complicated. |
920 |
| - * |
921 |
| - * We use the alphanumeric sorting property of the filenames to |
922 |
| - * decide which ones are earlier than the exclusiveCleanupFileName |
923 |
| - * file. Note that this means files are not removed in the order |
924 |
| - * they were originally written, in case this worries you. |
925 |
| - * |
926 |
| - * We also should not forget that WAL segment can be compressed. |
927 |
| - */ |
928 |
| - if (IsXLogFileName(arcde->d_name) || |
929 |
| - IsPartialXLogFileName(arcde->d_name) || |
930 |
| - IsBackupHistoryFileName(arcde->d_name) || |
931 |
| - IsCompressedXLogFileName(arcde->d_name)) |
932 |
| - { |
933 |
| - if (XLogRecPtrIsInvalid(oldest_lsn) || |
934 |
| - strncmp(arcde->d_name + 8, oldestSegmentNeeded + 8, 16) < 0) |
935 |
| - { |
936 |
| - /* |
937 |
| - * Use the original file name again now, including any |
938 |
| - * extension that might have been chopped off before testing |
939 |
| - * the sequence. |
940 |
| - */ |
941 |
| - snprintf(wal_file, MAXPGPATH, "%s/%s", |
942 |
| - arclog_path, arcde->d_name); |
943 |
| - |
944 |
| - rc = unlink(wal_file); |
945 |
| - if (rc != 0) |
946 |
| - { |
947 |
| - elog(WARNING, "could not remove file \"%s\": %s", |
948 |
| - wal_file, strerror(errno)); |
949 |
| - break; |
950 |
| - } |
951 |
| - elog(LOG, "removed WAL segment \"%s\"", wal_file); |
952 |
| - |
953 |
| - if (max_wal_file[0] == '\0' || |
954 |
| - strcmp(max_wal_file + 8, arcde->d_name + 8) < 0) |
955 |
| - strcpy(max_wal_file, arcde->d_name); |
956 |
| - |
957 |
| - if (min_wal_file[0] == '\0' || |
958 |
| - strcmp(min_wal_file + 8, arcde->d_name + 8) > 0) |
959 |
| - strcpy(min_wal_file, arcde->d_name); |
960 |
| - } |
961 |
| - } |
962 |
| - } |
963 |
| - |
964 |
| - if (min_wal_file[0] != '\0') |
965 |
| - elog(INFO, "removed min WAL segment \"%s\"", min_wal_file); |
966 |
| - if (max_wal_file[0] != '\0') |
967 |
| - elog(INFO, "removed max WAL segment \"%s\"", max_wal_file); |
968 |
| - |
969 |
| - if (errno) |
970 |
| - elog(WARNING, "could not read archive location \"%s\": %s", |
971 |
| - arclog_path, strerror(errno)); |
972 |
| - if (closedir(arcdir)) |
973 |
| - elog(WARNING, "could not close archive location \"%s\": %s", |
974 |
| - arclog_path, strerror(errno)); |
975 |
| - } |
976 |
| - else |
977 |
| - elog(WARNING, "could not open archive location \"%s\": %s", |
978 |
| - arclog_path, strerror(errno)); |
979 |
| -} |
980 |
| - |
981 | 867 |
|
982 | 868 | /* Delete all backup files and wal files of given instance. */
|
983 | 869 | int
|
|
0 commit comments