@@ -2452,7 +2452,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
2452
2452
bool ispartialpage ;
2453
2453
bool last_iteration ;
2454
2454
bool finishing_seg ;
2455
- bool use_existent ;
2455
+ bool added ;
2456
2456
int curridx ;
2457
2457
int npages ;
2458
2458
int startidx ;
@@ -2518,8 +2518,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
2518
2518
wal_segment_size );
2519
2519
2520
2520
/* create/use new log file */
2521
- use_existent = true;
2522
- openLogFile = XLogFileInit (openLogSegNo , & use_existent );
2521
+ openLogFile = XLogFileInit (openLogSegNo , & added );
2523
2522
ReserveExternalFD ();
2524
2523
}
2525
2524
@@ -3288,9 +3287,7 @@ XLogNeedsFlush(XLogRecPtr record)
3288
3287
*
3289
3288
* logsegno: identify segment to be created/opened.
3290
3289
*
3291
- * *use_existent: if true, OK to use a pre-existing file (else, any
3292
- * pre-existing file will be deleted). On return, false iff this call added
3293
- * some segment on disk.
3290
+ * *added: on return, true if this call raised the number of extant segments.
3294
3291
*
3295
3292
* Returns FD of opened file.
3296
3293
*
@@ -3300,7 +3297,7 @@ XLogNeedsFlush(XLogRecPtr record)
3300
3297
* in a critical section.
3301
3298
*/
3302
3299
int
3303
- XLogFileInit (XLogSegNo logsegno , bool * use_existent )
3300
+ XLogFileInit (XLogSegNo logsegno , bool * added )
3304
3301
{
3305
3302
char path [MAXPGPATH ];
3306
3303
char tmppath [MAXPGPATH ];
@@ -3315,19 +3312,17 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
3315
3312
/*
3316
3313
* Try to use existent file (checkpoint maker may have created it already)
3317
3314
*/
3318
- if (* use_existent )
3315
+ * added = false;
3316
+ fd = BasicOpenFile (path , O_RDWR | PG_BINARY | get_sync_bit (sync_method ));
3317
+ if (fd < 0 )
3319
3318
{
3320
- fd = BasicOpenFile (path , O_RDWR | PG_BINARY | get_sync_bit (sync_method ));
3321
- if (fd < 0 )
3322
- {
3323
- if (errno != ENOENT )
3324
- ereport (ERROR ,
3325
- (errcode_for_file_access (),
3326
- errmsg ("could not open file \"%s\": %m" , path )));
3327
- }
3328
- else
3329
- return fd ;
3319
+ if (errno != ENOENT )
3320
+ ereport (ERROR ,
3321
+ (errcode_for_file_access (),
3322
+ errmsg ("could not open file \"%s\": %m" , path )));
3330
3323
}
3324
+ else
3325
+ return fd ;
3331
3326
3332
3327
/*
3333
3328
* Initialize an empty (all zeroes) segment. NOTE: it is possible that
@@ -3440,12 +3435,9 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
3440
3435
errmsg ("could not close file \"%s\": %m" , tmppath )));
3441
3436
3442
3437
/*
3443
- * Now move the segment into place with its final name.
3444
- *
3445
- * If caller didn't want to use a pre-existing file, get rid of any
3446
- * pre-existing file. Otherwise, cope with possibility that someone else
3447
- * has created the file while we were filling ours: if so, use ours to
3448
- * pre-create a future log segment.
3438
+ * Now move the segment into place with its final name. Cope with
3439
+ * possibility that someone else has created the file while we were
3440
+ * filling ours: if so, use ours to pre-create a future log segment.
3449
3441
*/
3450
3442
installed_segno = logsegno ;
3451
3443
@@ -3459,9 +3451,8 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
3459
3451
* CheckPointSegments.
3460
3452
*/
3461
3453
max_segno = logsegno + CheckPointSegments ;
3462
- if (InstallXLogFileSegment (& installed_segno , tmppath ,
3463
- * use_existent , max_segno ))
3464
- * use_existent = false;
3454
+ if (InstallXLogFileSegment (& installed_segno , tmppath , true, max_segno ))
3455
+ * added = true;
3465
3456
else
3466
3457
{
3467
3458
/*
@@ -3946,18 +3937,17 @@ PreallocXlogFiles(XLogRecPtr endptr)
3946
3937
{
3947
3938
XLogSegNo _logSegNo ;
3948
3939
int lf ;
3949
- bool use_existent ;
3940
+ bool added ;
3950
3941
uint64 offset ;
3951
3942
3952
3943
XLByteToPrevSeg (endptr , _logSegNo , wal_segment_size );
3953
3944
offset = XLogSegmentOffset (endptr - 1 , wal_segment_size );
3954
3945
if (offset >= (uint32 ) (0.75 * wal_segment_size ))
3955
3946
{
3956
3947
_logSegNo ++ ;
3957
- use_existent = true;
3958
- lf = XLogFileInit (_logSegNo , & use_existent );
3948
+ lf = XLogFileInit (_logSegNo , & added );
3959
3949
close (lf );
3960
- if (! use_existent )
3950
+ if (added )
3961
3951
CheckpointStats .ckpt_segs_added ++ ;
3962
3952
}
3963
3953
}
@@ -5271,7 +5261,7 @@ BootStrapXLOG(void)
5271
5261
XLogLongPageHeader longpage ;
5272
5262
XLogRecord * record ;
5273
5263
char * recptr ;
5274
- bool use_existent ;
5264
+ bool added ;
5275
5265
uint64 sysidentifier ;
5276
5266
struct timeval tv ;
5277
5267
pg_crc32c crc ;
@@ -5368,8 +5358,7 @@ BootStrapXLOG(void)
5368
5358
record -> xl_crc = crc ;
5369
5359
5370
5360
/* Create first XLOG segment file */
5371
- use_existent = false;
5372
- openLogFile = XLogFileInit (1 , & use_existent );
5361
+ openLogFile = XLogFileInit (1 , & added );
5373
5362
5374
5363
/*
5375
5364
* We needn't bother with Reserve/ReleaseExternalFD here, since we'll
@@ -5675,10 +5664,10 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
5675
5664
* The switch happened at a segment boundary, so just create the next
5676
5665
* segment on the new timeline.
5677
5666
*/
5678
- bool use_existent = true ;
5667
+ bool added ;
5679
5668
int fd ;
5680
5669
5681
- fd = XLogFileInit (startLogSegNo , & use_existent );
5670
+ fd = XLogFileInit (startLogSegNo , & added );
5682
5671
5683
5672
if (close (fd ) != 0 )
5684
5673
{
0 commit comments