Skip to content

Commit 723c2b0

Browse files
committedDec 28, 2018
Bug fix: Consider target_lsn during validate WAL
1 parent 7d53afb commit 723c2b0

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed
 

‎src/parsexlog.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ validate_wal(pgBackup *backup, const char *archivedir,
519519
TimestampTz last_time = 0;
520520
char last_timestamp[100],
521521
target_timestamp[100];
522+
XLogRecPtr last_lsn = InvalidXLogRecPtr;
522523
bool all_wal = false;
523524
char backup_xlog_path[MAXPGPATH];
524525

@@ -585,6 +586,7 @@ validate_wal(pgBackup *backup, const char *archivedir,
585586
/* We can restore at least up to the backup end */
586587
time2iso(last_timestamp, lengthof(last_timestamp), backup->recovery_time);
587588
last_xid = backup->recovery_xid;
589+
last_lsn = backup->stop_lsn;
588590

589591
if ((TransactionIdIsValid(target_xid) && target_xid == last_xid)
590592
|| (target_time != 0 && backup->recovery_time >= target_time)
@@ -608,6 +610,7 @@ validate_wal(pgBackup *backup, const char *archivedir,
608610
timestamp_record = getRecordTimestamp(xlogreader, &last_time);
609611
if (XLogRecGetXid(xlogreader) != InvalidTransactionId)
610612
last_xid = XLogRecGetXid(xlogreader);
613+
last_lsn = xlogreader->ReadRecPtr;
611614

612615
/* Check target xid */
613616
if (TransactionIdIsValid(target_xid) && target_xid == last_xid)
@@ -616,12 +619,19 @@ validate_wal(pgBackup *backup, const char *archivedir,
616619
break;
617620
}
618621
/* Check target time */
619-
else if (target_time != 0 && timestamp_record && timestamptz_to_time_t(last_time) >= target_time)
622+
else if (target_time != 0 && timestamp_record &&
623+
timestamptz_to_time_t(last_time) >= target_time)
620624
{
621625
all_wal = true;
622626
break;
623627
}
624-
/* If there are no target xid and target time */
628+
/* Check target lsn */
629+
else if (XRecOffIsValid(target_xid) && last_lsn >= target_lsn)
630+
{
631+
all_wal = true;
632+
break;
633+
}
634+
/* If there are no target xid, target time and target lsn */
625635
else if (!TransactionIdIsValid(target_xid) && target_time == 0 &&
626636
xlogreader->ReadRecPtr == backup->stop_lsn)
627637
{
@@ -638,15 +648,17 @@ validate_wal(pgBackup *backup, const char *archivedir,
638648

639649
/* There are all needed WAL records */
640650
if (all_wal)
641-
elog(INFO, "backup validation completed successfully on time %s and xid " XID_FMT,
642-
last_timestamp, last_xid);
651+
elog(INFO, "backup validation completed successfully on time %s, xid " XID_FMT " and LSN %X/%X",
652+
last_timestamp, last_xid,
653+
(uint32) (last_lsn >> 32), (uint32) last_lsn);
643654
/* Some needed WAL records are absent */
644655
else
645656
{
646657
PrintXLogCorruptionMsg(&private, WARNING);
647658

648-
elog(WARNING, "recovery can be done up to time %s and xid " XID_FMT,
649-
last_timestamp, last_xid);
659+
elog(WARNING, "recovery can be done up to time %s, xid " XID_FMT " and LSN %X/%X",
660+
last_timestamp, last_xid,
661+
(uint32) (last_lsn >> 32), (uint32) last_lsn);
650662

651663
if (target_time > 0)
652664
time2iso(target_timestamp, lengthof(target_timestamp),

‎src/pg_probackup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ bool smooth_checkpoint;
6969
bool is_remote_backup = false;
7070

7171
/* restore options */
72-
static char *target_time;
73-
static char *target_xid;
74-
static char *target_lsn;
75-
static char *target_inclusive;
72+
static char *target_time = NULL;
73+
static char *target_xid = NULL;
74+
static char *target_lsn = NULL;
75+
static char *target_inclusive = NULL;
7676
static TimeLineID target_tli;
7777
static bool target_immediate;
7878
static char *target_name = NULL;

0 commit comments

Comments
 (0)
Please sign in to comment.