@@ -2424,7 +2424,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
2424
2424
bool ispartialpage ;
2425
2425
bool last_iteration ;
2426
2426
bool finishing_seg ;
2427
- bool use_existent ;
2427
+ bool added ;
2428
2428
int curridx ;
2429
2429
int npages ;
2430
2430
int startidx ;
@@ -2490,8 +2490,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
2490
2490
wal_segment_size );
2491
2491
2492
2492
/* create/use new log file */
2493
- use_existent = true;
2494
- openLogFile = XLogFileInit (openLogSegNo , & use_existent );
2493
+ openLogFile = XLogFileInit (openLogSegNo , & added );
2495
2494
ReserveExternalFD ();
2496
2495
}
2497
2496
@@ -3260,9 +3259,7 @@ XLogNeedsFlush(XLogRecPtr record)
3260
3259
*
3261
3260
* logsegno: identify segment to be created/opened.
3262
3261
*
3263
- * *use_existent: if true, OK to use a pre-existing file (else, any
3264
- * pre-existing file will be deleted). On return, false iff this call added
3265
- * some segment on disk.
3262
+ * *added: on return, true if this call raised the number of extant segments.
3266
3263
*
3267
3264
* Returns FD of opened file.
3268
3265
*
@@ -3272,7 +3269,7 @@ XLogNeedsFlush(XLogRecPtr record)
3272
3269
* in a critical section.
3273
3270
*/
3274
3271
int
3275
- XLogFileInit (XLogSegNo logsegno , bool * use_existent )
3272
+ XLogFileInit (XLogSegNo logsegno , bool * added )
3276
3273
{
3277
3274
char path [MAXPGPATH ];
3278
3275
char tmppath [MAXPGPATH ];
@@ -3287,19 +3284,17 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
3287
3284
/*
3288
3285
* Try to use existent file (checkpoint maker may have created it already)
3289
3286
*/
3290
- if (* use_existent )
3287
+ * added = false;
3288
+ fd = BasicOpenFile (path , O_RDWR | PG_BINARY | get_sync_bit (sync_method ));
3289
+ if (fd < 0 )
3291
3290
{
3292
- fd = BasicOpenFile (path , O_RDWR | PG_BINARY | get_sync_bit (sync_method ));
3293
- if (fd < 0 )
3294
- {
3295
- if (errno != ENOENT )
3296
- ereport (ERROR ,
3297
- (errcode_for_file_access (),
3298
- errmsg ("could not open file \"%s\": %m" , path )));
3299
- }
3300
- else
3301
- return fd ;
3291
+ if (errno != ENOENT )
3292
+ ereport (ERROR ,
3293
+ (errcode_for_file_access (),
3294
+ errmsg ("could not open file \"%s\": %m" , path )));
3302
3295
}
3296
+ else
3297
+ return fd ;
3303
3298
3304
3299
/*
3305
3300
* Initialize an empty (all zeroes) segment. NOTE: it is possible that
@@ -3412,12 +3407,9 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
3412
3407
errmsg ("could not close file \"%s\": %m" , tmppath )));
3413
3408
3414
3409
/*
3415
- * Now move the segment into place with its final name.
3416
- *
3417
- * If caller didn't want to use a pre-existing file, get rid of any
3418
- * pre-existing file. Otherwise, cope with possibility that someone else
3419
- * has created the file while we were filling ours: if so, use ours to
3420
- * pre-create a future log segment.
3410
+ * Now move the segment into place with its final name. Cope with
3411
+ * possibility that someone else has created the file while we were
3412
+ * filling ours: if so, use ours to pre-create a future log segment.
3421
3413
*/
3422
3414
installed_segno = logsegno ;
3423
3415
@@ -3431,9 +3423,8 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
3431
3423
* CheckPointSegments.
3432
3424
*/
3433
3425
max_segno = logsegno + CheckPointSegments ;
3434
- if (InstallXLogFileSegment (& installed_segno , tmppath ,
3435
- * use_existent , max_segno ))
3436
- * use_existent = false;
3426
+ if (InstallXLogFileSegment (& installed_segno , tmppath , true, max_segno ))
3427
+ * added = true;
3437
3428
else
3438
3429
{
3439
3430
/*
@@ -3918,18 +3909,17 @@ PreallocXlogFiles(XLogRecPtr endptr)
3918
3909
{
3919
3910
XLogSegNo _logSegNo ;
3920
3911
int lf ;
3921
- bool use_existent ;
3912
+ bool added ;
3922
3913
uint64 offset ;
3923
3914
3924
3915
XLByteToPrevSeg (endptr , _logSegNo , wal_segment_size );
3925
3916
offset = XLogSegmentOffset (endptr - 1 , wal_segment_size );
3926
3917
if (offset >= (uint32 ) (0.75 * wal_segment_size ))
3927
3918
{
3928
3919
_logSegNo ++ ;
3929
- use_existent = true;
3930
- lf = XLogFileInit (_logSegNo , & use_existent );
3920
+ lf = XLogFileInit (_logSegNo , & added );
3931
3921
close (lf );
3932
- if (! use_existent )
3922
+ if (added )
3933
3923
CheckpointStats .ckpt_segs_added ++ ;
3934
3924
}
3935
3925
}
@@ -5224,7 +5214,7 @@ BootStrapXLOG(void)
5224
5214
XLogLongPageHeader longpage ;
5225
5215
XLogRecord * record ;
5226
5216
char * recptr ;
5227
- bool use_existent ;
5217
+ bool added ;
5228
5218
uint64 sysidentifier ;
5229
5219
struct timeval tv ;
5230
5220
pg_crc32c crc ;
@@ -5321,8 +5311,7 @@ BootStrapXLOG(void)
5321
5311
record -> xl_crc = crc ;
5322
5312
5323
5313
/* Create first XLOG segment file */
5324
- use_existent = false;
5325
- openLogFile = XLogFileInit (1 , & use_existent );
5314
+ openLogFile = XLogFileInit (1 , & added );
5326
5315
5327
5316
/*
5328
5317
* We needn't bother with Reserve/ReleaseExternalFD here, since we'll
@@ -5628,10 +5617,10 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
5628
5617
* The switch happened at a segment boundary, so just create the next
5629
5618
* segment on the new timeline.
5630
5619
*/
5631
- bool use_existent = true ;
5620
+ bool added ;
5632
5621
int fd ;
5633
5622
5634
- fd = XLogFileInit (startLogSegNo , & use_existent );
5623
+ fd = XLogFileInit (startLogSegNo , & added );
5635
5624
5636
5625
if (close (fd ) != 0 )
5637
5626
{
0 commit comments