1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-12-11 11:41:33 +02:00

[Issue #261] PG13 support

This commit is contained in:
Grigory Smolkin 2020-09-25 11:09:42 +03:00
parent a693fb54af
commit eca14e0261
2 changed files with 83 additions and 30 deletions

View File

@ -422,14 +422,13 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
/* Extract information about files in backup_list parsing their names:*/
parse_filelist_filenames(backup_files_list, instance_config.pgdata);
elog(LOG, "Current Start LSN: %X/%X, TLI: %X",
(uint32) (current.start_lsn >> 32), (uint32) (current.start_lsn),
current.tli);
if (current.backup_mode != BACKUP_MODE_FULL)
{
elog(LOG, "Current tli: %X", current.tli);
elog(LOG, "Parent start_lsn: %X/%X",
(uint32) (prev_backup->start_lsn >> 32), (uint32) (prev_backup->start_lsn));
elog(LOG, "start_lsn: %X/%X",
(uint32) (current.start_lsn >> 32), (uint32) (current.start_lsn));
}
elog(LOG, "Parent Start LSN: %X/%X, TLI: %X",
(uint32) (prev_backup->start_lsn >> 32), (uint32) (prev_backup->start_lsn),
prev_backup->tli);
/*
* Build page mapping in incremental mode.

View File

@ -148,10 +148,12 @@ typedef struct
int ret;
} xlog_thread_arg;
static XLogRecord* WalReadRecord(XLogReaderState *xlogreader, XLogRecPtr startpoint, char **errormsg);
static XLogReaderState* WalReaderAllocate(uint32 wal_seg_size, XLogReaderData *reader_data);
static int SimpleXLogPageRead(XLogReaderState *xlogreader,
XLogRecPtr targetPagePtr,
int reqLen, XLogRecPtr targetRecPtr, char *readBuf,
TimeLineID *pageTLI);
int reqLen, XLogRecPtr targetRecPtr, char *readBuf);
static XLogReaderState *InitXLogPageRead(XLogReaderData *reader_data,
const char *archivedir,
TimeLineID tli, uint32 segment_size,
@ -551,7 +553,13 @@ read_recovery_info(const char *archivedir, TimeLineID tli, uint32 wal_seg_size,
TimestampTz last_time = 0;
char *errormsg;
record = XLogReadRecord(xlogreader, startpoint, &errormsg);
#if PG_VERSION_NUM >= 130000
if (XLogRecPtrIsInvalid(startpoint))
startpoint = SizeOfXLogShortPHD;
XLogBeginRead(xlogreader, startpoint);
#endif
record = WalReadRecord(xlogreader, startpoint, &errormsg);
if (record == NULL)
{
XLogRecPtr errptr;
@ -615,7 +623,13 @@ wal_contains_lsn(const char *archivedir, XLogRecPtr target_lsn,
xlogreader->system_identifier = instance_config.system_identifier;
res = XLogReadRecord(xlogreader, target_lsn, &errormsg) != NULL;
#if PG_VERSION_NUM >= 130000
if (XLogRecPtrIsInvalid(target_lsn))
target_lsn = SizeOfXLogShortPHD;
XLogBeginRead(xlogreader, target_lsn);
#endif
res = WalReadRecord(xlogreader, target_lsn, &errormsg) != NULL;
/* Didn't find 'target_lsn' and there is no error, return false */
if (errormsg)
@ -656,6 +670,12 @@ get_first_record_lsn(const char *archivedir, XLogSegNo segno,
/* Set startpoint to 0 in segno */
GetXLogRecPtr(segno, 0, wal_seg_size, startpoint);
#if PG_VERSION_NUM >= 130000
if (XLogRecPtrIsInvalid(startpoint))
startpoint = SizeOfXLogShortPHD;
XLogBeginRead(xlogreader, startpoint);
#endif
while (attempts <= timeout)
{
record = XLogFindNextRecord(xlogreader, startpoint);
@ -710,6 +730,12 @@ get_next_record_lsn(const char *archivedir, XLogSegNo segno,
/* Set startpoint to 0 in segno */
GetXLogRecPtr(segno, 0, wal_seg_size, startpoint);
#if PG_VERSION_NUM >= 130000
if (XLogRecPtrIsInvalid(startpoint))
startpoint = SizeOfXLogShortPHD;
XLogBeginRead(xlogreader, startpoint);
#endif
found = XLogFindNextRecord(xlogreader, startpoint);
if (XLogRecPtrIsInvalid(found))
@ -733,7 +759,7 @@ get_next_record_lsn(const char *archivedir, XLogSegNo segno,
if (interrupted)
elog(ERROR, "Interrupted during WAL reading");
record = XLogReadRecord(xlogreader, startpoint, &errormsg);
record = WalReadRecord(xlogreader, startpoint, &errormsg);
if (record == NULL)
{
@ -822,6 +848,13 @@ get_prior_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
XLogRecPtr found;
GetXLogRecPtr(segno, 0, wal_seg_size, startpoint);
#if PG_VERSION_NUM >= 130000
if (XLogRecPtrIsInvalid(startpoint))
startpoint = SizeOfXLogShortPHD;
XLogBeginRead(xlogreader, startpoint);
#endif
found = XLogFindNextRecord(xlogreader, startpoint);
if (XLogRecPtrIsInvalid(found))
@ -846,7 +879,7 @@ get_prior_record_lsn(const char *archivedir, XLogRecPtr start_lsn,
if (interrupted)
elog(ERROR, "Interrupted during WAL reading");
record = XLogReadRecord(xlogreader, startpoint, &errormsg);
record = WalReadRecord(xlogreader, startpoint, &errormsg);
if (record == NULL)
{
XLogRecPtr errptr;
@ -905,8 +938,7 @@ get_gz_error(gzFile gzf)
/* XLogreader callback function, to read a WAL page */
static int
SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
int reqLen, XLogRecPtr targetRecPtr, char *readBuf,
TimeLineID *pageTLI)
int reqLen, XLogRecPtr targetRecPtr, char *readBuf)
{
XLogReaderData *reader_data;
uint32 targetPageOff;
@ -1040,7 +1072,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
reader_data->prev_page_off == targetPageOff)
{
memcpy(readBuf, reader_data->page_buf, XLOG_BLCKSZ);
*pageTLI = reader_data->tli;
// *pageTLI = reader_data->tli;
return XLOG_BLCKSZ;
}
@ -1084,7 +1116,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
memcpy(reader_data->page_buf, readBuf, XLOG_BLCKSZ);
reader_data->prev_page_off = targetPageOff;
*pageTLI = reader_data->tli;
// *pageTLI = reader_data->tli;
return XLOG_BLCKSZ;
}
@ -1109,12 +1141,7 @@ InitXLogPageRead(XLogReaderData *reader_data, const char *archivedir,
if (allocate_reader)
{
#if PG_VERSION_NUM >= 110000
xlogreader = XLogReaderAllocate(wal_seg_size, &SimpleXLogPageRead,
reader_data);
#else
xlogreader = XLogReaderAllocate(&SimpleXLogPageRead, reader_data);
#endif
xlogreader = WalReaderAllocate(wal_seg_size, reader_data);
if (xlogreader == NULL)
elog(ERROR, "Out of memory");
xlogreader->system_identifier = instance_config.system_identifier;
@ -1314,16 +1341,18 @@ XLogThreadWorker(void *arg)
uint32 prev_page_off = 0;
bool need_read = true;
#if PG_VERSION_NUM >= 110000
xlogreader = XLogReaderAllocate(wal_seg_size, &SimpleXLogPageRead,
reader_data);
#else
xlogreader = XLogReaderAllocate(&SimpleXLogPageRead, reader_data);
#endif
xlogreader = WalReaderAllocate(wal_seg_size, reader_data);
if (xlogreader == NULL)
elog(ERROR, "Thread [%d]: out of memory", reader_data->thread_num);
xlogreader->system_identifier = instance_config.system_identifier;
#if PG_VERSION_NUM >= 130000
if (XLogRecPtrIsInvalid(thread_arg->startpoint))
thread_arg->startpoint = SizeOfXLogShortPHD;
XLogBeginRead(xlogreader, thread_arg->startpoint);
#endif
found = XLogFindNextRecord(xlogreader, thread_arg->startpoint);
/*
@ -1376,7 +1405,7 @@ XLogThreadWorker(void *arg)
!SwitchThreadToNextWal(xlogreader, thread_arg))
break;
record = XLogReadRecord(xlogreader, thread_arg->startpoint, &errormsg);
record = WalReadRecord(xlogreader, thread_arg->startpoint, &errormsg);
if (record == NULL)
{
@ -1857,3 +1886,28 @@ bool validate_wal_segment(TimeLineID tli, XLogSegNo segno, const char *prefetch_
return rc;
}
static XLogRecord* WalReadRecord(XLogReaderState *xlogreader, XLogRecPtr startpoint, char **errormsg)
{
#if PG_VERSION_NUM >= 130000
return XLogReadRecord(xlogreader, errormsg);
#else
return XLogReadRecord(xlogreader, startpoint, errormsg);
#endif
}
static XLogReaderState* WalReaderAllocate(uint32 wal_seg_size, XLogReaderData *reader_data)
{
#if PG_VERSION_NUM >= 130000
return XLogReaderAllocate(wal_seg_size, NULL,
XL_ROUTINE(.page_read = &SimpleXLogPageRead),
reader_data);
#elif PG_VERSION_NUM >= 110000
return XLogReaderAllocate(wal_seg_size, &SimpleXLogPageRead,
reader_data);
#else
return XLogReaderAllocate(&SimpleXLogPageRead, reader_data);
#endif
}