@@ -807,7 +807,7 @@ static bool XLogCheckpointNeeded(XLogSegNo new_segno);
807
807
static void XLogWrite (XLogwrtRqst WriteRqst ,bool flexible );
808
808
static bool InstallXLogFileSegment (XLogSegNo * segno ,char * tmppath ,
809
809
bool find_free ,XLogSegNo max_segno ,
810
- bool use_lock );
810
+ bool use_lock , int elevel );
811
811
static int XLogFileRead (XLogSegNo segno ,int emode ,TimeLineID tli ,
812
812
int source ,bool notexistOk );
813
813
static int XLogFileReadAnyTLI (XLogSegNo segno ,int emode ,int source );
@@ -3012,7 +3012,7 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
3012
3012
max_segno = logsegno + CheckPointSegments ;
3013
3013
if (!InstallXLogFileSegment (& installed_segno ,tmppath ,
3014
3014
* use_existent ,max_segno ,
3015
- use_lock ))
3015
+ use_lock , LOG ))
3016
3016
{
3017
3017
/*
3018
3018
* No need for any more future segments, or InstallXLogFileSegment()
@@ -3041,18 +3041,16 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
3041
3041
/*
3042
3042
* Copy a WAL segment file in pg_xlog directory.
3043
3043
*
3044
- * dstfnamedestination filename
3045
3044
* srcfnamesource filename
3046
3045
* uptohow much of the source file to copy? (the rest is filled with
3047
3046
*zeros)
3047
+ * segnoidentify segment to install.
3048
3048
*
3049
- * If dstfname is not given, the file is created with a temporary filename,
3050
- * which is returned. Both filenames are relative to the pg_xlog directory.
3051
- *
3052
- * NB: Any existing file with the same name will be overwritten!
3049
+ * The file is first copied with a temporary filename, and then installed as
3050
+ * a newly-created segment.
3053
3051
*/
3054
- static char *
3055
- XLogFileCopy (char * dstfname , char * srcfname ,int upto )
3052
+ static void
3053
+ XLogFileCopy (char * srcfname ,int upto , XLogSegNo segno )
3056
3054
{
3057
3055
char srcpath [MAXPGPATH ];
3058
3056
char tmppath [MAXPGPATH ];
@@ -3150,25 +3148,9 @@ XLogFileCopy(char *dstfname, char *srcfname, int upto)
3150
3148
3151
3149
CloseTransientFile (srcfd );
3152
3150
3153
- /*
3154
- * Now move the segment into place with its final name. (Or just return
3155
- * the path to the file we created, if the caller wants to handle the rest
3156
- * on its own.)
3157
- */
3158
- if (dstfname )
3159
- {
3160
- char dstpath [MAXPGPATH ];
3161
-
3162
- snprintf (dstpath ,MAXPGPATH ,XLOGDIR "/%s" ,dstfname );
3163
- if (rename (tmppath ,dstpath )< 0 )
3164
- ereport (ERROR ,
3165
- (errcode_for_file_access (),
3166
- errmsg ("could not rename file \"%s\" to \"%s\": %m" ,
3167
- tmppath ,dstpath )));
3168
- return NULL ;
3169
- }
3170
- else
3171
- return pstrdup (tmppath );
3151
+ /* install the new file */
3152
+ (void )InstallXLogFileSegment (& segno ,tmppath , false,
3153
+ 0 , false,ERROR );
3172
3154
}
3173
3155
3174
3156
/*
@@ -3195,14 +3177,16 @@ XLogFileCopy(char *dstfname, char *srcfname, int upto)
3195
3177
* place. This should be TRUE except during bootstrap log creation. The
3196
3178
* caller must *not* hold the lock at call.
3197
3179
*
3180
+ * elevel: log level used by this routine.
3181
+ *
3198
3182
* Returns TRUE if the file was installed successfully. FALSE indicates that
3199
3183
* max_segno limit was exceeded, or an error occurred while renaming the
3200
3184
* file into place.
3201
3185
*/
3202
3186
static bool
3203
3187
InstallXLogFileSegment (XLogSegNo * segno ,char * tmppath ,
3204
3188
bool find_free ,XLogSegNo max_segno ,
3205
- bool use_lock )
3189
+ bool use_lock , int elevel )
3206
3190
{
3207
3191
char path [MAXPGPATH ];
3208
3192
struct stat stat_buf ;
@@ -3247,7 +3231,7 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
3247
3231
{
3248
3232
if (use_lock )
3249
3233
LWLockRelease (ControlFileLock );
3250
- ereport (LOG ,
3234
+ ereport (elevel ,
3251
3235
(errcode_for_file_access (),
3252
3236
errmsg ("could not link file \"%s\" to \"%s\" (initialization of log file): %m" ,
3253
3237
tmppath ,path )));
@@ -3259,7 +3243,7 @@ InstallXLogFileSegment(XLogSegNo *segno, char *tmppath,
3259
3243
{
3260
3244
if (use_lock )
3261
3245
LWLockRelease (ControlFileLock );
3262
- ereport (LOG ,
3246
+ ereport (elevel ,
3263
3247
(errcode_for_file_access (),
3264
3248
errmsg ("could not rename file \"%s\" to \"%s\" (initialization of log file): %m" ,
3265
3249
tmppath ,path )));
@@ -3748,7 +3732,7 @@ RemoveXlogFile(const char *segname, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
3748
3732
if (endlogSegNo <=recycleSegNo &&
3749
3733
lstat (path ,& statbuf )== 0 && S_ISREG (statbuf .st_mode )&&
3750
3734
InstallXLogFileSegment (& endlogSegNo ,path ,
3751
- true,recycleSegNo , true))
3735
+ true,recycleSegNo , true, LOG ))
3752
3736
{
3753
3737
ereport (DEBUG2 ,
3754
3738
(errmsg ("recycled transaction log file \"%s\"" ,
@@ -5227,8 +5211,6 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
5227
5211
*/
5228
5212
if (endLogSegNo == startLogSegNo )
5229
5213
{
5230
- char * tmpfname ;
5231
-
5232
5214
XLogFileName (xlogfname ,endTLI ,endLogSegNo );
5233
5215
5234
5216
/*
@@ -5238,9 +5220,7 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
5238
5220
* considerations. But we should be just as tense as XLogFileInit to
5239
5221
* avoid emplacing a bogus file.
5240
5222
*/
5241
- tmpfname = XLogFileCopy (NULL ,xlogfname ,endOfLog %XLOG_SEG_SIZE );
5242
- if (!InstallXLogFileSegment (& endLogSegNo ,tmpfname , false,0 , false))
5243
- elog (ERROR ,"InstallXLogFileSegment should not have failed" );
5223
+ XLogFileCopy (xlogfname ,endOfLog %XLOG_SEG_SIZE ,endLogSegNo );
5244
5224
}
5245
5225
else
5246
5226
{