Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8aa6b84

Browse files
author
Michael Paquier
committed
Fix history file parsing when fetched from archive
History file format has changed from 9.2 to 9.3 to indicate the WAL recordwhen timeline branched off. In 9.2, the complete WAL file name was usedwhile in 9.3 the WAL record is used (like 1/4000090). pg_rman contains acopy of a function of postgres core code to parse the history file thatwas not anymore compatible, leading to errors related to timelines.
1 parent71d019c commit8aa6b84

File tree

3 files changed

+23
-40
lines changed

3 files changed

+23
-40
lines changed

‎pg_rman.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ extern int pgFileCompareMtimeDesc(const void *f1, const void *f2);
306306

307307
/* in xlog.c */
308308
externboolxlog_is_complete_wal(constpgFile*file,intserver_version);
309-
externboolxlog_logfname2lsn(constchar*logfname,XLogRecPtr*lsn);
310309
externvoidxlog_fname(char*fname,size_tlen,TimeLineIDtli,XLogRecPtr*lsn);
311310

312311
/* in data.c */

‎restore.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -768,28 +768,41 @@ readTimeLineHistory(TimeLineID targetTLI)
768768
*/
769769
while (fd&&fgets(fline,sizeof(fline),fd)!=NULL)
770770
{
771-
/* skip leading whitespaces and check for # comment */
772771
char*ptr;
773-
char*endptr;
772+
TimeLineIDtli;
773+
uint32switchpoint_hi;
774+
uint32switchpoint_lo;
775+
intnfields;
774776

775777
for (ptr=fline;*ptr;ptr++)
776778
{
777-
if (!IsSpace(*ptr))
779+
if (!isspace((unsignedchar)*ptr))
778780
break;
779781
}
780782
if (*ptr=='\0'||*ptr=='#')
781783
continue;
782784

785+
/* Parse one entry... */
786+
nfields=sscanf(fline,"%u\t%X/%X",&tli,&switchpoint_hi,&switchpoint_lo);
787+
783788
timeline=pgut_new(pgTimeLine);
784789
timeline->tli=0;
785790
timeline->end=0;
786791

787792
/* expect a numeric timeline ID as first field of line */
788-
timeline->tli= (TimeLineID)strtoul(ptr,&endptr,0);
789-
if (endptr==ptr)
793+
timeline->tli=tli;
794+
795+
if (nfields<1)
796+
{
797+
/* expect a numeric timeline ID as first field of line */
790798
elog(ERROR_CORRUPTED,
791-
_("syntax error(timeline ID) in history file: %s"),
792-
fline);
799+
_("syntax error in history file: %s. Expected a numeric timeline ID."),
800+
fline);
801+
}
802+
if (nfields!=3)
803+
elog(ERROR_CORRUPTED,
804+
_("syntax error in history file: %s. Expected a transaction log switchpoint location."),
805+
fline);
793806

794807
if (last_timeline&&timeline->tli <=last_timeline->tli)
795808
elog(ERROR_CORRUPTED,
@@ -799,20 +812,9 @@ readTimeLineHistory(TimeLineID targetTLI)
799812
parray_insert(result,0,timeline);
800813
last_timeline=timeline;
801814

802-
/* parse end point(logfname, xid) in the timeline */
803-
for (ptr=endptr;*ptr;ptr++)
804-
{
805-
if (!IsSpace(*ptr))
806-
break;
807-
}
808-
if (*ptr=='\0'||*ptr=='#')
809-
elog(ERROR_CORRUPTED,
810-
_("End logfile must follow Timeline ID."));
811-
812-
if (!xlog_logfname2lsn(ptr,&timeline->end))
813-
elog(ERROR_CORRUPTED,
814-
_("syntax error(endfname) in history file: %s"),fline);
815-
/* we ignore the remainder of each line */
815+
/* Calculate the end lsn finally */
816+
timeline->end= (XLogRecPtr)
817+
((uint64)switchpoint_hi <<32) |switchpoint_lo;
816818
}
817819

818820
if (fd)

‎xlog.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,6 @@ xlog_is_complete_wal(const pgFile *file, int server_version)
109109
return true;
110110
}
111111

112-
bool
113-
xlog_logfname2lsn(constchar*logfname,XLogRecPtr*lsn)
114-
{
115-
uint32tli;
116-
uint32xlogid;
117-
uint32xrecoff;
118-
119-
if (sscanf(logfname,"%08X%08X%08X",
120-
&tli,&xlogid,&xrecoff)!=3)
121-
return false;
122-
123-
xrecoff *=XLogSegSize;
124-
125-
/* Finish calculation of LSN */
126-
*lsn= (XLogRecPtr) ((uint64)xlogid <<32) |xrecoff;
127-
return true;
128-
}
129-
130112
/*
131113
* based on XLogFileName() in xlog_internal.h
132114
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp