@@ -808,7 +808,7 @@ static bool XLogCheckpointNeeded(XLogSegNo new_segno);
808808static void XLogWrite (XLogwrtRqst WriteRqst , bool flexible );
809809static bool InstallXLogFileSegment (XLogSegNo * segno , char * tmppath ,
810810 bool find_free , XLogSegNo max_segno ,
811- bool use_lock , int elevel );
811+ bool use_lock );
812812static int XLogFileRead (XLogSegNo segno , int emode , TimeLineID tli ,
813813 int 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)
30133013 max_segno = logsegno + CheckPointSegments ;
30143014 if (!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 a WAL segment file in pg_xlog directory .
3043+ * Create a new XLOG file segment by copying a pre-existing one .
30443044 *
3045- * srcfname source filename
3046- * upto how much of the source file to copy? (the rest is filled with
3047- * zeros)
3048- * segno identify 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 ];
30573062 char tmppath [MAXPGPATH ];
30583063 char buffer [XLOG_BLCKSZ ];
30593064 int 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 );
30683073 if (srcfd < 0 )
30693074 ereport (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)
31123117 ereport (ERROR ,
31133118 (errcode_for_file_access (),
31143119 errmsg ("could not read file \"%s\": %m" ,
3115- srcpath )));
3120+ path )));
31163121 else
31173122 ereport (ERROR ,
31183123 (errmsg ("not enough data in file \"%s\"" ,
3119- srcpath )));
3124+ path )));
31203125 }
31213126 }
31223127 errno = 0 ;
@@ -3149,9 +3154,11 @@ XLogFileCopy(char *srcfname, int upto, XLogSegNo segno)
31493154
31503155 CloseTransientFile (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 ,
31893194 bool find_free , XLogSegNo max_segno ,
3190- bool use_lock , int elevel )
3195+ bool use_lock )
31913196{
31923197 char path [MAXPGPATH ];
31933198 struct stat stat_buf ;
@@ -3232,7 +3237,7 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
32323237 {
32333238 if (use_lock )
32343239 LWLockRelease (ControlFileLock );
3235- ereport (elevel ,
3240+ ereport (LOG ,
32363241 (errcode_for_file_access (),
32373242 errmsg ("could not link file \"%s\" to \"%s\" (initialization of log file): %m" ,
32383243 tmppath , path )));
@@ -3244,7 +3249,7 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
32443249 {
32453250 if (use_lock )
32463251 LWLockRelease (ControlFileLock );
3247- ereport (elevel ,
3252+ ereport (LOG ,
32483253 (errcode_for_file_access (),
32493254 errmsg ("could not rename file \"%s\" to \"%s\" (initialization of log file): %m" ,
32503255 tmppath , path )));
@@ -3733,7 +3738,7 @@ RemoveXlogFile(const char *segname, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
37333738 if (endlogSegNo <= recycleSegNo &&
37343739 lstat (path , & statbuf ) == 0 && S_ISREG (statbuf .st_mode ) &&
37353740 InstallXLogFileSegment (& endlogSegNo , path ,
3736- true, recycleSegNo , true, LOG ))
3741+ true, recycleSegNo , true))
37373742 {
37383743 ereport (DEBUG2 ,
37393744 (errmsg ("recycled transaction log file \"%s\"" ,
@@ -5212,16 +5217,15 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
52125217 */
52135218 if (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 }
52265230 else
52275231 {
0 commit comments