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

Commita016f59

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 parentff9c222 commita016f59

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
@@ -648,11 +648,12 @@ pgarch_archiveXlog(char *xlog)
648648
* 2) because the oldest ones will sooner become candidates for
649649
* recycling at time of checkpoint
650650
*
651-
* NOTE: the "oldest" comparison will presently consider all segments of
652-
* a timeline with a smaller ID to be older than all segments of a timeline
653-
* with a larger ID; the net result being that past timelines are given
654-
* higher priority for archiving. This seems okay, or at least not
655-
* obviously worth changing.
651+
* NOTE: the "oldest" comparison will consider any .history file to be older
652+
* than any other file except another .history file. Segments on a timeline
653+
* with a smaller ID will be older than all segments on a timeline with a
654+
* larger ID; the net result being that past timelines are given higher
655+
* priority for archiving. This seems okay, or at least not obviously worth
656+
* changing.
656657
*/
657658
staticbool
658659
pgarch_readyXlog(char*xlog)
@@ -664,43 +665,62 @@ pgarch_readyXlog(char *xlog)
664665
* of calls, so....
665666
*/
666667
charXLogArchiveStatusDir[MAXPGPATH];
667-
charnewxlog[MAX_XFN_CHARS+6+1];
668668
DIR*rldir;
669669
structdirent*rlde;
670670
boolfound= false;
671+
boolhistoryFound= false;
671672

672673
snprintf(XLogArchiveStatusDir,MAXPGPATH,XLOGDIR"/archive_status");
673674
rldir=AllocateDir(XLogArchiveStatusDir);
674675

675676
while ((rlde=ReadDir(rldir,XLogArchiveStatusDir))!=NULL)
676677
{
677678
intbasenamelen= (int)strlen(rlde->d_name)-6;
679+
charbasename[MAX_XFN_CHARS+1];
680+
boolishistory;
678681

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

698-
if (found)
699-
{
700-
/* truncate off the .ready */
701-
newxlog[strlen(newxlog)-6]='\0';
702-
strcpy(xlog,newxlog);
703-
}
704724
returnfound;
705725
}
706726

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp