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

Commit9378701

Browse files
committed
Prioritize history files when archiving
At the end of recovery for the post-promotion process, a new historyfile is created followed by the last partial segment of the previoustimeline. Based on the timing, the archiver would first try to archivethe last partial segment and then the history file. This can delay thedetection of a new timeline taken, particularly depending on the time ittakes to transfer the last partial segment as it delays the moment thehistory file of the new timeline gets archived. This can cause promotedstandbys to use the same timeline as one already taken depending on thecircumstances if multiple instances look at archives at the samelocation.This commit changes the order of archiving so as history files arearchived in priority over other file types, which reduces the likelihoodof the same timeline being taken (still not reducing the window tozero), and it makes the archiver behave more consistently with thestartup process doing its post-promotion business.Author: David SteeleReviewed-by: Michael Paquier, Kyotaro HoriguchiDiscussion:https://postgr.es/m/929068cf-69e1-bba2-9dc0-e05986aed471@pgmasters.netBackpatch-through: 9.5
1 parentffcd98c commit9378701

File tree

1 file changed

+46
-26
lines changed

1 file changed

+46
-26
lines changed

‎src/backend/postmaster/pgarch.c

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,12 @@ pgarch_archiveXlog(char *xlog)
651651
* 2) because the oldest ones will sooner become candidates for
652652
* recycling at time of checkpoint
653653
*
654-
* NOTE: the "oldest" comparison will presently consider all segments of
655-
* a timeline with a smaller ID to be older than all segments of a timeline
656-
* with a larger ID; the net result being that past timelines are given
657-
* higher priority for archiving. This seems okay, or at least not
658-
* obviously worth changing.
654+
* NOTE: the "oldest" comparison will consider any .history file to be older
655+
* than any other file except another .history file. Segments on a timeline
656+
* with a smaller ID will be older than all segments on a timeline with a
657+
* larger ID; the net result being that past timelines are given higher
658+
* priority for archiving. This seems okay, or at least not obviously worth
659+
* changing.
659660
*/
660661
staticbool
661662
pgarch_readyXlog(char*xlog)
@@ -667,10 +668,10 @@ pgarch_readyXlog(char *xlog)
667668
* of calls, so....
668669
*/
669670
charXLogArchiveStatusDir[MAXPGPATH];
670-
charnewxlog[MAX_XFN_CHARS+6+1];
671671
DIR*rldir;
672672
structdirent*rlde;
673673
boolfound= false;
674+
boolhistoryFound= false;
674675

675676
snprintf(XLogArchiveStatusDir,MAXPGPATH,XLOGDIR"/archive_status");
676677
rldir=AllocateDir(XLogArchiveStatusDir);
@@ -683,32 +684,51 @@ pgarch_readyXlog(char *xlog)
683684
while ((rlde=ReadDir(rldir,XLogArchiveStatusDir))!=NULL)
684685
{
685686
intbasenamelen= (int)strlen(rlde->d_name)-6;
687+
charbasename[MAX_XFN_CHARS+1];
688+
boolishistory;
686689

687-
if (basenamelen >=MIN_XFN_CHARS&&
688-
basenamelen <=MAX_XFN_CHARS&&
689-
strspn(rlde->d_name,VALID_XFN_CHARS) >=basenamelen&&
690-
strcmp(rlde->d_name+basenamelen,".ready")==0)
690+
/* Ignore entries with unexpected number of characters */
691+
if (basenamelen<MIN_XFN_CHARS||
692+
basenamelen>MAX_XFN_CHARS)
693+
continue;
694+
695+
/* Ignore entries with unexpected characters */
696+
if (strspn(rlde->d_name,VALID_XFN_CHARS)<basenamelen)
697+
continue;
698+
699+
/* Ignore anything not suffixed with .ready */
700+
if (strcmp(rlde->d_name+basenamelen,".ready")!=0)
701+
continue;
702+
703+
/* Truncate off the .ready */
704+
memcpy(basename,rlde->d_name,basenamelen);
705+
basename[basenamelen]='\0';
706+
707+
/* Is this a history file? */
708+
ishistory=IsTLHistoryFileName(basename);
709+
710+
/*
711+
* Consume the file to archive. History files have the highest
712+
* priority. If this is the first file or the first history file
713+
* ever, copy it. In the presence of a history file already chosen as
714+
* target, ignore all other files except history files which have been
715+
* generated for an older timeline than what is already chosen as
716+
* target to archive.
717+
*/
718+
if (!found|| (ishistory&& !historyFound))
691719
{
692-
if (!found)
693-
{
694-
strcpy(newxlog,rlde->d_name);
695-
found= true;
696-
}
697-
else
698-
{
699-
if (strcmp(rlde->d_name,newxlog)<0)
700-
strcpy(newxlog,rlde->d_name);
701-
}
720+
strcpy(xlog,basename);
721+
found= true;
722+
historyFound=ishistory;
723+
}
724+
elseif (ishistory|| !historyFound)
725+
{
726+
if (strcmp(basename,xlog)<0)
727+
strcpy(xlog,basename);
702728
}
703729
}
704730
FreeDir(rldir);
705731

706-
if (found)
707-
{
708-
/* truncate off the .ready */
709-
newxlog[strlen(newxlog)-6]='\0';
710-
strcpy(xlog,newxlog);
711-
}
712732
returnfound;
713733
}
714734

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp