Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit421484f

Browse files
committed
Remove XLogFileInit() ability to unlink a pre-existing file.
Only initdb used it. initdb refuses to operate on a non-empty directoryand generally does not cope with pre-existing files of other kinds.Hence, use the opportunity to simplify.Discussion:https://postgr.es/m/20210202151416.GB3304930@rfd.leadboat.com
1 parent85656bc commit421484f

File tree

3 files changed

+28
-40
lines changed

3 files changed

+28
-40
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
24242424
boolispartialpage;
24252425
boollast_iteration;
24262426
boolfinishing_seg;
2427-
booluse_existent;
2427+
booladded;
24282428
intcurridx;
24292429
intnpages;
24302430
intstartidx;
@@ -2490,8 +2490,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible)
24902490
wal_segment_size);
24912491

24922492
/* create/use new log file */
2493-
use_existent= true;
2494-
openLogFile=XLogFileInit(openLogSegNo,&use_existent);
2493+
openLogFile=XLogFileInit(openLogSegNo,&added);
24952494
ReserveExternalFD();
24962495
}
24972496

@@ -3260,9 +3259,7 @@ XLogNeedsFlush(XLogRecPtr record)
32603259
*
32613260
* logsegno: identify segment to be created/opened.
32623261
*
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.
32663263
*
32673264
* Returns FD of opened file.
32683265
*
@@ -3272,7 +3269,7 @@ XLogNeedsFlush(XLogRecPtr record)
32723269
* in a critical section.
32733270
*/
32743271
int
3275-
XLogFileInit(XLogSegNologsegno,bool*use_existent)
3272+
XLogFileInit(XLogSegNologsegno,bool*added)
32763273
{
32773274
charpath[MAXPGPATH];
32783275
chartmppath[MAXPGPATH];
@@ -3287,19 +3284,17 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
32873284
/*
32883285
* Try to use existent file (checkpoint maker may have created it already)
32893286
*/
3290-
if (*use_existent)
3287+
*added= false;
3288+
fd=BasicOpenFile(path,O_RDWR |PG_BINARY |get_sync_bit(sync_method));
3289+
if (fd<0)
32913290
{
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-
returnfd;
3291+
if (errno!=ENOENT)
3292+
ereport(ERROR,
3293+
(errcode_for_file_access(),
3294+
errmsg("could not open file \"%s\": %m",path)));
33023295
}
3296+
else
3297+
returnfd;
33033298

33043299
/*
33053300
* Initialize an empty (all zeroes) segment. NOTE: it is possible that
@@ -3412,12 +3407,9 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
34123407
errmsg("could not close file \"%s\": %m",tmppath)));
34133408

34143409
/*
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.
34213413
*/
34223414
installed_segno=logsegno;
34233415

@@ -3431,9 +3423,8 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent)
34313423
* CheckPointSegments.
34323424
*/
34333425
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;
34373428
else
34383429
{
34393430
/*
@@ -3918,18 +3909,17 @@ PreallocXlogFiles(XLogRecPtr endptr)
39183909
{
39193910
XLogSegNo_logSegNo;
39203911
intlf;
3921-
booluse_existent;
3912+
booladded;
39223913
uint64offset;
39233914

39243915
XLByteToPrevSeg(endptr,_logSegNo,wal_segment_size);
39253916
offset=XLogSegmentOffset(endptr-1,wal_segment_size);
39263917
if (offset >= (uint32) (0.75*wal_segment_size))
39273918
{
39283919
_logSegNo++;
3929-
use_existent= true;
3930-
lf=XLogFileInit(_logSegNo,&use_existent);
3920+
lf=XLogFileInit(_logSegNo,&added);
39313921
close(lf);
3932-
if (!use_existent)
3922+
if (added)
39333923
CheckpointStats.ckpt_segs_added++;
39343924
}
39353925
}
@@ -5224,7 +5214,7 @@ BootStrapXLOG(void)
52245214
XLogLongPageHeaderlongpage;
52255215
XLogRecord*record;
52265216
char*recptr;
5227-
booluse_existent;
5217+
booladded;
52285218
uint64sysidentifier;
52295219
structtimevaltv;
52305220
pg_crc32ccrc;
@@ -5321,8 +5311,7 @@ BootStrapXLOG(void)
53215311
record->xl_crc=crc;
53225312

53235313
/* Create first XLOG segment file */
5324-
use_existent= false;
5325-
openLogFile=XLogFileInit(1,&use_existent);
5314+
openLogFile=XLogFileInit(1,&added);
53265315

53275316
/*
53285317
* We needn't bother with Reserve/ReleaseExternalFD here, since we'll
@@ -5628,10 +5617,10 @@ exitArchiveRecovery(TimeLineID endTLI, XLogRecPtr endOfLog)
56285617
* The switch happened at a segment boundary, so just create the next
56295618
* segment on the new timeline.
56305619
*/
5631-
booluse_existent= true;
5620+
booladded;
56325621
intfd;
56335622

5634-
fd=XLogFileInit(startLogSegNo,&use_existent);
5623+
fd=XLogFileInit(startLogSegNo,&added);
56355624

56365625
if (close(fd)!=0)
56375626
{

‎src/backend/replication/walreceiver.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
885885

886886
if (recvFile<0|| !XLByteInSeg(recptr,recvSegNo,wal_segment_size))
887887
{
888-
booluse_existent;
888+
booladded;
889889

890890
/*
891891
* fsync() and close current file before we switch to next one. We
@@ -923,8 +923,7 @@ XLogWalRcvWrite(char *buf, Size nbytes, XLogRecPtr recptr)
923923

924924
/* Create/use new log file */
925925
XLByteToSeg(recptr,recvSegNo,wal_segment_size);
926-
use_existent= true;
927-
recvFile=XLogFileInit(recvSegNo,&use_existent);
926+
recvFile=XLogFileInit(recvSegNo,&added);
928927
recvFileTLI=ThisTimeLineID;
929928
}
930929

‎src/include/access/xlog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ extern XLogRecPtr XLogInsertRecord(struct XLogRecData *rdata,
296296
externvoidXLogFlush(XLogRecPtrRecPtr);
297297
externboolXLogBackgroundFlush(void);
298298
externboolXLogNeedsFlush(XLogRecPtrRecPtr);
299-
externintXLogFileInit(XLogSegNosegno,bool*use_existent);
299+
externintXLogFileInit(XLogSegNosegno,bool*added);
300300
externintXLogFileOpen(XLogSegNosegno);
301301

302302
externvoidCheckXLogRemoved(XLogSegNosegno,TimeLineIDtli);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp