Skip to content

Commit 1e9615f

Browse files
committed
Use InvalidXLogRecPtr to mark infinite end, a couple code cleanup
1 parent de9c3b6 commit 1e9615f

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/backup.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ do_backup_instance(void)
474474

475475
pgBackup *prev_backup = NULL;
476476
parray *prev_backup_filelist = NULL;
477+
parray *backup_list = NULL;
477478

478479
pgFile *pg_control = NULL;
479480

@@ -515,7 +516,6 @@ do_backup_instance(void)
515516
current.backup_mode == BACKUP_MODE_DIFF_PTRACK ||
516517
current.backup_mode == BACKUP_MODE_DIFF_DELTA)
517518
{
518-
parray *backup_list;
519519
char prev_backup_filelist_path[MAXPGPATH];
520520

521521
/* get list of backups already taken */
@@ -525,7 +525,6 @@ do_backup_instance(void)
525525
if (prev_backup == NULL)
526526
elog(ERROR, "Valid backup on current timeline is not found. "
527527
"Create new FULL backup before an incremental one.");
528-
parray_free(backup_list);
529528

530529
pgBackupGetPath(prev_backup, prev_backup_filelist_path,
531530
lengthof(prev_backup_filelist_path), DATABASE_FILE_LIST);
@@ -832,6 +831,13 @@ do_backup_instance(void)
832831
current.data_bytes += file->write_size;
833832
}
834833

834+
/* Cleanup */
835+
if (backup_list)
836+
{
837+
parray_walk(backup_list, pgBackupFree);
838+
parray_free(backup_list);
839+
}
840+
835841
parray_walk(backup_files_list, pgFileFree);
836842
parray_free(backup_files_list);
837843
backup_files_list = NULL;

src/pg_probackup.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ extern int do_restore_or_validate(time_t target_backup_id,
418418
extern bool satisfy_timeline(const parray *timelines, const pgBackup *backup);
419419
extern bool satisfy_recovery_target(const pgBackup *backup,
420420
const pgRecoveryTarget *rt);
421-
extern parray * readTimeLineHistory_probackup(TimeLineID targetTLI);
422421
extern pgRecoveryTarget *parseRecoveryTargetOptions(
423422
const char *target_time, const char *target_xid,
424423
const char *target_inclusive, TimeLineID target_tli, const char* target_lsn,

src/restore.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static void restore_backup(pgBackup *backup);
3333
static void create_recovery_conf(time_t backup_id,
3434
pgRecoveryTarget *rt,
3535
pgBackup *backup);
36+
static parray *read_timeline_history(TimeLineID targetTLI);
3637
static void *restore_files(void *arg);
3738
static void remove_deleted_files(pgBackup *backup);
3839

@@ -138,7 +139,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
138139

139140
elog(LOG, "target timeline ID = %u", rt->recovery_target_tli);
140141
/* Read timeline history files from archives */
141-
timelines = readTimeLineHistory_probackup(rt->recovery_target_tli);
142+
timelines = read_timeline_history(rt->recovery_target_tli);
142143

143144
if (!satisfy_timeline(timelines, current_backup))
144145
{
@@ -149,6 +150,9 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
149150
/* Try to find another backup that satisfies target timeline */
150151
continue;
151152
}
153+
154+
parray_walk(timelines, pfree);
155+
parray_free(timelines);
152156
}
153157

154158
if (!satisfy_recovery_target(current_backup, rt))
@@ -731,7 +735,7 @@ create_recovery_conf(time_t backup_id,
731735
* based on readTimeLineHistory() in timeline.c
732736
*/
733737
parray *
734-
readTimeLineHistory_probackup(TimeLineID targetTLI)
738+
read_timeline_history(TimeLineID targetTLI)
735739
{
736740
parray *result;
737741
char path[MAXPGPATH];
@@ -820,8 +824,7 @@ readTimeLineHistory_probackup(TimeLineID targetTLI)
820824
entry = pgut_new(TimeLineHistoryEntry);
821825
entry->tli = targetTLI;
822826
/* LSN in target timeline is valid */
823-
/* TODO ensure that -1UL --> -1L fix is correct */
824-
entry->end = (uint32) (-1L << 32) | -1L;
827+
entry->end = InvalidXLogRecPtr;
825828
parray_insert(result, 0, entry);
826829

827830
return result;
@@ -853,7 +856,8 @@ satisfy_timeline(const parray *timelines, const pgBackup *backup)
853856

854857
timeline = (TimeLineHistoryEntry *) parray_get(timelines, i);
855858
if (backup->tli == timeline->tli &&
856-
backup->stop_lsn < timeline->end)
859+
(XLogRecPtrIsInvalid(timeline->end) ||
860+
backup->stop_lsn < timeline->end))
857861
return true;
858862
}
859863
return false;

0 commit comments

Comments
 (0)