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

Commitb981df4

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 parentbf491a9 commitb981df4

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
@@ -695,11 +695,12 @@ pgarch_archiveXlog(char *xlog)
695695
* 2) because the oldest ones will sooner become candidates for
696696
* recycling at time of checkpoint
697697
*
698-
* NOTE: the "oldest" comparison will presently consider all segments of
699-
* a timeline with a smaller ID to be older than all segments of a timeline
700-
* with a larger ID; the net result being that past timelines are given
701-
* higher priority for archiving. This seems okay, or at least not
702-
* obviously worth changing.
698+
* NOTE: the "oldest" comparison will consider any .history file to be older
699+
* than any other file except another .history file. Segments on a timeline
700+
* with a smaller ID will be older than all segments on a timeline with a
701+
* larger ID; the net result being that past timelines are given higher
702+
* priority for archiving. This seems okay, or at least not obviously worth
703+
* changing.
703704
*/
704705
staticbool
705706
pgarch_readyXlog(char*xlog)
@@ -711,43 +712,62 @@ pgarch_readyXlog(char *xlog)
711712
* of calls, so....
712713
*/
713714
charXLogArchiveStatusDir[MAXPGPATH];
714-
charnewxlog[MAX_XFN_CHARS+6+1];
715715
DIR*rldir;
716716
structdirent*rlde;
717717
boolfound= false;
718+
boolhistoryFound= false;
718719

719720
snprintf(XLogArchiveStatusDir,MAXPGPATH,XLOGDIR"/archive_status");
720721
rldir=AllocateDir(XLogArchiveStatusDir);
721722

722723
while ((rlde=ReadDir(rldir,XLogArchiveStatusDir))!=NULL)
723724
{
724725
intbasenamelen= (int)strlen(rlde->d_name)-6;
726+
charbasename[MAX_XFN_CHARS+1];
727+
boolishistory;
725728

726-
if (basenamelen >=MIN_XFN_CHARS&&
727-
basenamelen <=MAX_XFN_CHARS&&
728-
strspn(rlde->d_name,VALID_XFN_CHARS) >=basenamelen&&
729-
strcmp(rlde->d_name+basenamelen,".ready")==0)
729+
/* Ignore entries with unexpected number of characters */
730+
if (basenamelen<MIN_XFN_CHARS||
731+
basenamelen>MAX_XFN_CHARS)
732+
continue;
733+
734+
/* Ignore entries with unexpected characters */
735+
if (strspn(rlde->d_name,VALID_XFN_CHARS)<basenamelen)
736+
continue;
737+
738+
/* Ignore anything not suffixed with .ready */
739+
if (strcmp(rlde->d_name+basenamelen,".ready")!=0)
740+
continue;
741+
742+
/* Truncate off the .ready */
743+
memcpy(basename,rlde->d_name,basenamelen);
744+
basename[basenamelen]='\0';
745+
746+
/* Is this a history file? */
747+
ishistory=IsTLHistoryFileName(basename);
748+
749+
/*
750+
* Consume the file to archive. History files have the highest
751+
* priority. If this is the first file or the first history file
752+
* ever, copy it. In the presence of a history file already chosen as
753+
* target, ignore all other files except history files which have been
754+
* generated for an older timeline than what is already chosen as
755+
* target to archive.
756+
*/
757+
if (!found|| (ishistory&& !historyFound))
730758
{
731-
if (!found)
732-
{
733-
strcpy(newxlog,rlde->d_name);
734-
found= true;
735-
}
736-
else
737-
{
738-
if (strcmp(rlde->d_name,newxlog)<0)
739-
strcpy(newxlog,rlde->d_name);
740-
}
759+
strcpy(xlog,basename);
760+
found= true;
761+
historyFound=ishistory;
762+
}
763+
elseif (ishistory|| !historyFound)
764+
{
765+
if (strcmp(basename,xlog)<0)
766+
strcpy(xlog,basename);
741767
}
742768
}
743769
FreeDir(rldir);
744770

745-
if (found)
746-
{
747-
/* truncate off the .ready */
748-
newxlog[strlen(newxlog)-6]='\0';
749-
strcpy(xlog,newxlog);
750-
}
751771
returnfound;
752772
}
753773

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp