@@ -808,7 +808,7 @@ static bool XLogCheckpointNeeded(XLogSegNo new_segno);
808808static void XLogWrite (XLogwrtRqst WriteRqst ,bool flexible );
809809static bool InstallXLogFileSegment (XLogSegNo * segno ,char * tmppath ,
810810bool find_free ,XLogSegNo max_segno ,
811- bool use_lock , int elevel );
811+ bool use_lock );
812812static int XLogFileRead (XLogSegNo segno ,int emode ,TimeLineID tli ,
813813int source ,bool notexistOk );
814814static int XLogFileReadAnyTLI (XLogSegNo segno ,int emode ,int source );
@@ -3013,7 +3013,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
30133013max_segno = logsegno + CheckPointSegments ;
30143014if (!InstallXLogFileSegment (& installed_segno ,tmppath ,
30153015* use_existent ,max_segno ,
3016- use_lock , LOG ))
3016+ use_lock ))
30173017{
30183018/*
30193019 * No need for any more future segments, or InstallXLogFileSegment()
@@ -3040,20 +3040,25 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
30403040}
30413041
30423042/*
3043- *Copy aWAL segment filein pg_xlog directory .
3043+ *Create anew XLOG filesegment by copying a pre-existing one .
30443044 *
3045- * srcfnamesource filename
3046- * uptohow much of the source file to copy? (the rest is filled with
3047- *zeros)
3048- * segnoidentify segment to install.
3045+ * destsegno: identify segment to be created.
30493046 *
3050- * The file is first copied with a temporary filename, and then installed as
3051- * a newly-created segment.
3047+ * srcTLI, srclog, srcseg: identify segment to be copied (could be from
3048+ *a different timeline)
3049+ *
3050+ * upto: how much of the source file to copy (the rest is filled with
3051+ *zeros)
3052+ *
3053+ * Currently this is only used during recovery, and so there are no locking
3054+ * considerations. But we should be just as tense as XLogFileInit to avoid
3055+ * emplacing a bogus file.
30523056 */
30533057static void
3054- XLogFileCopy (char * srcfname ,int upto ,XLogSegNo segno )
3058+ XLogFileCopy (XLogSegNo destsegno ,TimeLineID srcTLI ,XLogSegNo srcsegno ,
3059+ int upto )
30553060{
3056- char srcpath [MAXPGPATH ];
3061+ char path [MAXPGPATH ];
30573062char tmppath [MAXPGPATH ];
30583063char buffer [XLOG_BLCKSZ ];
30593064int srcfd ;
@@ -3063,12 +3068,12 @@ XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
30633068/*
30643069 * Open the source file
30653070 */
3066- snprintf ( srcpath , MAXPGPATH , XLOGDIR "/%s" , srcfname );
3067- srcfd = OpenTransientFile (srcpath ,O_RDONLY |PG_BINARY ,0 );
3071+ XLogFilePath ( path , srcTLI , srcsegno );
3072+ srcfd = OpenTransientFile (path ,O_RDONLY |PG_BINARY ,0 );
30683073if (srcfd < 0 )
30693074ereport (ERROR ,
30703075(errcode_for_file_access (),
3071- errmsg ("could not open file \"%s\": %m" ,srcpath )));
3076+ errmsg ("could not open file \"%s\": %m" ,path )));
30723077
30733078/*
30743079 * Copy into a temp file name.
@@ -3112,11 +3117,11 @@ XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
31123117ereport (ERROR ,
31133118(errcode_for_file_access (),
31143119errmsg ("could not read file \"%s\": %m" ,
3115- srcpath )));
3120+ path )));
31163121else
31173122ereport (ERROR ,
31183123(errmsg ("not enough data in file \"%s\"" ,
3119- srcpath )));
3124+ path )));
31203125}
31213126}
31223127errno = 0 ;
@@ -3149,9 +3154,11 @@ XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
31493154
31503155CloseTransientFile (srcfd );
31513156
3152- /* install the new file */
3153- (void )InstallXLogFileSegment (& segno ,tmppath , false,
3154- 0 , false,ERROR );
3157+ /*
3158+ * Now move the segment into place with its final name.
3159+ */
3160+ if (!InstallXLogFileSegment (& destsegno ,tmppath , false,0 , false))
3161+ elog (ERROR ,"InstallXLogFileSegment should not have failed" );
31553162}
31563163
31573164/*
@@ -3178,16 +3185,14 @@ XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
31783185 * place. This should be TRUE except during bootstrap log creation. The
31793186 * caller must *not* hold the lock at call.
31803187 *
3181- * elevel: log level used by this routine.
3182- *
31833188 * Returns TRUE if the file was installed successfully. FALSE indicates that
31843189 * max_segno limit was exceeded, or an error occurred while renaming the
31853190 * file into place.
31863191 */
31873192static bool
31883193InstallXLogFileSegment (XLogSegNo * segno ,char * tmppath ,
31893194bool find_free ,XLogSegNo max_segno ,
3190- bool use_lock , int elevel )
3195+ bool use_lock )
31913196{
31923197char path [MAXPGPATH ];
31933198struct stat stat_buf ;
@@ -3232,7 +3237,7 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
32323237{
32333238if (use_lock )
32343239LWLockRelease (ControlFileLock );
3235- ereport (elevel ,
3240+ ereport (LOG ,
32363241(errcode_for_file_access (),
32373242errmsg ("could not link file \"%s\" to \"%s\" (initialization of log file): %m" ,
32383243tmppath ,path )));
@@ -3244,7 +3249,7 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
32443249{
32453250if (use_lock )
32463251LWLockRelease (ControlFileLock );
3247- ereport (elevel ,
3252+ ereport (LOG ,
32483253(errcode_for_file_access (),
32493254errmsg ("could not rename file \"%s\" to \"%s\" (initialization of log file): %m" ,
32503255tmppath ,path )));
@@ -3733,7 +3738,7 @@ RemoveXlogFile(const char *segname, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
37333738if (endlogSegNo <=recycleSegNo &&
37343739lstat (path ,& statbuf )== 0 && S_ISREG (statbuf .st_mode )&&
37353740InstallXLogFileSegment (& endlogSegNo ,path ,
3736- true,recycleSegNo , true, LOG ))
3741+ true,recycleSegNo , true))
37373742{
37383743ereport (DEBUG2 ,
37393744(errmsg ("recycled transaction log file \"%s\"" ,
@@ -5212,16 +5217,15 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
52125217 */
52135218if (endLogSegNo == startLogSegNo )
52145219{
5215- XLogFileName (xlogfname ,endTLI ,endLogSegNo );
5216-
52175220/*
52185221 * Make a copy of the file on the new timeline.
52195222 *
52205223 * Writing WAL isn't allowed yet, so there are no locking
52215224 * considerations. But we should be just as tense as XLogFileInit to
52225225 * avoid emplacing a bogus file.
52235226 */
5224- XLogFileCopy (xlogfname ,endOfLog %XLOG_SEG_SIZE ,endLogSegNo );
5227+ XLogFileCopy (endLogSegNo ,endTLI ,endLogSegNo ,
5228+ endOfLog %XLOG_SEG_SIZE );
52255229}
52265230else
52275231{