Skip to content

Commit 74cd9c5

Browse files
committed
[Issue #326] Handle empty history files correctly
1 parent 294e7dc commit 74cd9c5

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/catalog.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,10 @@ catalog_get_timelines(InstanceConfig *instance)
15811581
sscanf(file->name, "%08X.history", &tli);
15821582
timelines = read_timeline_history(arclog_path, tli, true);
15831583

1584+
/* History file is empty or corrupted, disregard it */
1585+
if (!timelines)
1586+
continue;
1587+
15841588
if (!tlinfo || tlinfo->tli != tli)
15851589
{
15861590
tlinfo = timelineInfoNew(tli);

src/restore.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
289289
/* Read timeline history files from archives */
290290
timelines = read_timeline_history(arclog_path, rt->target_tli, true);
291291

292+
if (!timelines)
293+
elog(WARNING, "Failed to get history file for target timeline %i", rt->target_tli);
294+
292295
if (!satisfy_timeline(timelines, current_backup))
293296
{
294297
if (target_backup_id != INVALID_BACKUP_ID)
@@ -1778,6 +1781,14 @@ read_timeline_history(const char *arclog_path, TimeLineID targetTLI, bool strict
17781781
if (last_timeline && targetTLI <= last_timeline->tli)
17791782
elog(ERROR, "Timeline IDs must be less than child timeline's ID.");
17801783

1784+
/* History file is empty or corrupted */
1785+
if (parray_num(result) != 1)
1786+
{
1787+
elog(WARNING, "History file is corrupted: \"%s\"", path);
1788+
pg_free(result);
1789+
return NULL;
1790+
}
1791+
17811792
/* append target timeline */
17821793
entry = pgut_new(TimeLineHistoryEntry);
17831794
entry->tli = targetTLI;

0 commit comments

Comments
 (0)