@@ -2440,7 +2440,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
2440
2440
bool ispartialpage ;
2441
2441
bool last_iteration ;
2442
2442
bool finishing_seg ;
2443
- bool use_existent ;
2443
+ bool added ;
2444
2444
int curridx ;
2445
2445
int npages ;
2446
2446
int startidx ;
@@ -2507,8 +2507,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
2507
2507
wal_segment_size );
2508
2508
2509
2509
/* create/use new log file */
2510
- use_existent = true;
2511
- openLogFile = XLogFileInit (openLogSegNo , & use_existent );
2510
+ openLogFile = XLogFileInit (openLogSegNo , & added );
2512
2511
ReserveExternalFD ();
2513
2512
}
2514
2513
@@ -3258,9 +3257,7 @@ XLogNeedsFlush(XLogRecPtr record)
3258
3257
*
3259
3258
* logsegno: identify segment to be created/opened.
3260
3259
*
3261
- * *use_existent: if true, OK to use a pre-existing file (else, any
3262
- * pre-existing file will be deleted). On return, false iff this call added
3263
- * some segment on disk.
3260
+ * *added: on return, true if this call raised the number of extant segments.
3264
3261
*
3265
3262
* Returns FD of opened file.
3266
3263
*
@@ -3270,7 +3267,7 @@ XLogNeedsFlush(XLogRecPtr record)
3270
3267
* in a critical section.
3271
3268
*/
3272
3269
int
3273
- XLogFileInit (XLogSegNo logsegno , bool * use_existent )
3270
+ XLogFileInit (XLogSegNo logsegno , bool * added )
3274
3271
{
3275
3272
char path [MAXPGPATH ];
3276
3273
char tmppath [MAXPGPATH ];
@@ -3286,19 +3283,17 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
3286
3283
/*
3287
3284
* Try to use existent file (checkpoint maker may have created it already)
3288
3285
*/
3289
- if (* use_existent )
3286
+ * added = false;
3287
+ fd = BasicOpenFile (path , O_RDWR | PG_BINARY | get_sync_bit (sync_method ));
3288
+ if (fd < 0 )
3290
3289
{
3291
- fd = BasicOpenFile (path , O_RDWR | PG_BINARY | get_sync_bit (sync_method ));
3292
- if (fd < 0 )
3293
- {
3294
- if (errno != ENOENT )
3295
- ereport (ERROR ,
3296
- (errcode_for_file_access (),
3297
- errmsg ("could not open file \"%s\": %m" , path )));
3298
- }
3299
- else
3300
- return fd ;
3290
+ if (errno != ENOENT )
3291
+ ereport (ERROR ,
3292
+ (errcode_for_file_access (),
3293
+ errmsg ("could not open file \"%s\": %m" , path )));
3301
3294
}
3295
+ else
3296
+ return fd ;
3302
3297
3303
3298
/*
3304
3299
* Initialize an empty (all zeroes) segment. NOTE: it is possible that
@@ -3395,12 +3390,9 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
3395
3390
errmsg ("could not close file \"%s\": %m" , tmppath )));
3396
3391
3397
3392
/*
3398
- * Now move the segment into place with its final name.
3399
- *
3400
- * If caller didn't want to use a pre-existing file, get rid of any
3401
- * pre-existing file. Otherwise, cope with possibility that someone else
3402
- * has created the file while we were filling ours: if so, use ours to
3403
- * pre-create a future log segment.
3393
+ * Now move the segment into place with its final name. Cope with
3394
+ * possibility that someone else has created the file while we were
3395
+ * filling ours: if so, use ours to pre-create a future log segment.
3404
3396
*/
3405
3397
installed_segno = logsegno ;
3406
3398
@@ -3414,9 +3406,8 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
3414
3406
* CheckPointSegments.
3415
3407
*/
3416
3408
max_segno = logsegno + CheckPointSegments ;
3417
- if (InstallXLogFileSegment (& installed_segno , tmppath ,
3418
- * use_existent , max_segno ))
3419
- * use_existent = false;
3409
+ if (InstallXLogFileSegment (& installed_segno , tmppath , true, max_segno ))
3410
+ * added = true;
3420
3411
else
3421
3412
{
3422
3413
/*
@@ -3901,18 +3892,17 @@ PreallocXlogFiles(XLogRecPtr endptr)
3901
3892
{
3902
3893
XLogSegNo _logSegNo ;
3903
3894
int lf ;
3904
- bool use_existent ;
3895
+ bool added ;
3905
3896
uint64 offset ;
3906
3897
3907
3898
XLByteToPrevSeg (endptr , _logSegNo , wal_segment_size );
3908
3899
offset = XLogSegmentOffset (endptr - 1 , wal_segment_size );
3909
3900
if (offset >= (uint32 ) (0.75 * wal_segment_size ))
3910
3901
{
3911
3902
_logSegNo ++ ;
3912
- use_existent = true;
3913
- lf = XLogFileInit (_logSegNo , & use_existent );
3903
+ lf = XLogFileInit (_logSegNo , & added );
3914
3904
close (lf );
3915
- if (! use_existent )
3905
+ if (added )
3916
3906
CheckpointStats .ckpt_segs_added ++ ;
3917
3907
}
3918
3908
}
@@ -5225,7 +5215,7 @@ BootStrapXLOG(void)
5225
5215
XLogLongPageHeader longpage ;
5226
5216
XLogRecord * record ;
5227
5217
char * recptr ;
5228
- bool use_existent ;
5218
+ bool added ;
5229
5219
uint64 sysidentifier ;
5230
5220
struct timeval tv ;
5231
5221
pg_crc32c crc ;
@@ -5322,8 +5312,7 @@ BootStrapXLOG(void)
5322
5312
record -> xl_crc = crc ;
5323
5313
5324
5314
/* Create first XLOG segment file */
5325
- use_existent = false;
5326
- openLogFile = XLogFileInit (1 , & use_existent );
5315
+ openLogFile = XLogFileInit (1 , & added );
5327
5316
5328
5317
/*
5329
5318
* We needn't bother with Reserve/ReleaseExternalFD here, since we'll
@@ -5629,10 +5618,10 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
5629
5618
* The switch happened at a segment boundary, so just create the next
5630
5619
* segment on the new timeline.
5631
5620
*/
5632
- bool use_existent = true ;
5621
+ bool added ;
5633
5622
int fd ;
5634
5623
5635
- fd = XLogFileInit (startLogSegNo , & use_existent );
5624
+ fd = XLogFileInit (startLogSegNo , & added );
5636
5625
5637
5626
if (close (fd ) != 0 )
5638
5627
{
0 commit comments