From 30845bf4a636516db8e17aa1c531d2d01cccbd1c Mon Sep 17 00:00:00 2001 From: Zhuravlev Uriy aka stalkerg Date: Thu, 10 Mar 2016 17:40:33 +0300 Subject: [PATCH] Check ptrack control file. --- backup.c | 6 ++++++ parsexlog.c | 2 -- pg_arman.h | 1 + util.c | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/backup.c b/backup.c index 7e09f08a..1f6addd0 100644 --- a/backup.c +++ b/backup.c @@ -230,6 +230,12 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt) if (current.backup_mode == BACKUP_MODE_DIFF_PTRACK) { + XLogRecPtr ptrack_lsn = get_last_ptrack_lsn(); + if (ptrack_lsn < prev_backup->start_lsn || ptrack_lsn >= current.start_lsn) + elog(ERROR, "Wrong ptrack lsn:%lx prev:%lx current:%lx", + ptrack_lsn, + prev_backup->start_lsn, + current.start_lsn); parray_qsort(backup_files_list, pgFileComparePathDesc); make_pagemap_from_ptrack(backup_files_list); } diff --git a/parsexlog.c b/parsexlog.c index 3487c351..21682766 100644 --- a/parsexlog.c +++ b/parsexlog.c @@ -107,11 +107,9 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, { XLogPageReadPrivate *private = (XLogPageReadPrivate *) xlogreader->private_data; uint32 targetPageOff; - XLogRecPtr targetSegEnd; XLogSegNo targetSegNo; XLByteToSeg(targetPagePtr, targetSegNo); - XLogSegNoOffsetToRecPtr(targetSegNo + 1, 0, targetSegEnd); targetPageOff = targetPagePtr % XLogSegSize; /* diff --git a/pg_arman.h b/pg_arman.h index 82d16410..bb68fb18 100644 --- a/pg_arman.h +++ b/pg_arman.h @@ -298,6 +298,7 @@ extern void time2iso(char *buf, size_t len, time_t time); extern const char *status2str(BackupStatus status); extern void remove_trailing_space(char *buf, int comment_mark); extern void remove_not_digit(char *buf, size_t len, const char *str); +extern XLogRecPtr get_last_ptrack_lsn(void); /* in status.c */ extern bool is_pg_running(void); diff --git a/util.c b/util.c index 684ee668..b6a8f2a7 100644 --- a/util.c +++ b/util.c @@ -75,6 +75,21 @@ sanityChecks(void) "target master need to use either data checksums or \"wal_log_hints = on\"."); } +XLogRecPtr +get_last_ptrack_lsn(void) +{ + char *buffer; + size_t size; + XLogRecPtr lsn; + + buffer = slurpFile(pgdata, "global/ptrack_control", &size, false); + if (buffer == NULL) + return 0; + + lsn = *(XLogRecPtr *)buffer; + return lsn; +} + /* * Utility shared by backup and restore to fetch the current timeline * used by a node.