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

Commite41d0a1

Browse files
committed
Add proper errcodes to new error messages for read() failures
Those would use the default ERRCODE_INTERNAL_ERROR, but for foreseeablefailures an errcode ought to be set, ERRCODE_DATA_CORRUPTED making themost sense here.While on the way, fix one errcode_for_file_access missing in origin.csince the code has been created, and remove one assignment of errno to 0before calling read(), as this was around to fit with what was presentbefore811b6e3 where errno would not be set when not enough bytes areread. I have noticed the first one, and Tom has pinged me about thesecond one.Author: Michael PaquierReported-by: Tom LaneDiscussion:https://postgr.es/m/27265.1531925836@sss.pgh.pa.us
1 parent56df07b commite41d0a1

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,7 +3412,6 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
34123412

34133413
if (nread>sizeof(buffer))
34143414
nread=sizeof(buffer);
3415-
errno=0;
34163415
pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_READ);
34173416
r=read(srcfd,buffer,nread);
34183417
if (r!=nread)
@@ -3424,7 +3423,8 @@ XLogFileCopy(XLogSegNo destsegno, TimeLineID srcTLI, XLogSegNo srcsegno,
34243423
path)));
34253424
else
34263425
ereport(ERROR,
3427-
(errmsg("could not read file \"%s\": read %d of %zu",
3426+
(errcode(ERRCODE_DATA_CORRUPTED),
3427+
errmsg("could not read file \"%s\": read %d of %zu",
34283428
path,r, (Size)nread)));
34293429
}
34303430
pgstat_report_wait_end();
@@ -4564,7 +4564,8 @@ ReadControlFile(void)
45644564
XLOG_CONTROL_FILE)));
45654565
else
45664566
ereport(PANIC,
4567-
(errmsg("could not read file \"%s\": read %d of %zu",
4567+
(errcode(ERRCODE_DATA_CORRUPTED),
4568+
errmsg("could not read file \"%s\": read %d of %zu",
45684569
XLOG_CONTROL_FILE,r,sizeof(ControlFileData))));
45694570
}
45704571
pgstat_report_wait_end();
@@ -11829,7 +11830,8 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
1182911830
}
1183011831
else
1183111832
ereport(emode_for_corrupt_record(emode,targetPagePtr+reqLen),
11832-
(errmsg("could not read from log segment %s, offset %u: read %d of %zu",
11833+
(errcode(ERRCODE_DATA_CORRUPTED),
11834+
errmsg("could not read from log segment %s, offset %u: read %d of %zu",
1183311835
fname,readOff,r, (Size)XLOG_BLCKSZ)));
1183411836
gotonext_record_is_invalid;
1183511837
}

‎src/backend/replication/logical/origin.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,13 @@ StartupReplicationOrigin(void)
715715
{
716716
if (readBytes<0)
717717
ereport(PANIC,
718-
(errmsg("could not read file \"%s\": %m",
718+
(errcode_for_file_access(),
719+
errmsg("could not read file \"%s\": %m",
719720
path)));
720721
else
721722
ereport(PANIC,
722-
(errmsg("could not read file \"%s\": read %d of %zu",
723+
(errcode(ERRCODE_DATA_CORRUPTED),
724+
errmsg("could not read file \"%s\": read %d of %zu",
723725
path,readBytes,sizeof(magic))));
724726
}
725727
COMP_CRC32C(crc,&magic,sizeof(magic));

‎src/backend/replication/logical/snapbuild.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
17361736
}
17371737
else
17381738
ereport(ERROR,
1739-
(errmsg("could not read file \"%s\": read %d of %zu",
1739+
(errcode(ERRCODE_DATA_CORRUPTED),
1740+
errmsg("could not read file \"%s\": read %d of %zu",
17401741
path,readBytes,
17411742
(Size)SnapBuildOnDiskConstantSize)));
17421743
}
@@ -1775,7 +1776,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
17751776
}
17761777
else
17771778
ereport(ERROR,
1778-
(errmsg("could not read file \"%s\": read %d of %zu",
1779+
(errcode(ERRCODE_DATA_CORRUPTED),
1780+
errmsg("could not read file \"%s\": read %d of %zu",
17791781
path,readBytes,sizeof(SnapBuild))));
17801782
}
17811783
COMP_CRC32C(checksum,&ondisk.builder,sizeof(SnapBuild));
@@ -1802,7 +1804,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
18021804
}
18031805
else
18041806
ereport(ERROR,
1805-
(errmsg("could not read file \"%s\": read %d of %zu",
1807+
(errcode(ERRCODE_DATA_CORRUPTED),
1808+
errmsg("could not read file \"%s\": read %d of %zu",
18061809
path,readBytes,sz)));
18071810
}
18081811
COMP_CRC32C(checksum,ondisk.builder.was_running.was_xip,sz);
@@ -1828,7 +1831,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
18281831
}
18291832
else
18301833
ereport(ERROR,
1831-
(errmsg("could not read file \"%s\": read %d of %zu",
1834+
(errcode(ERRCODE_DATA_CORRUPTED),
1835+
errmsg("could not read file \"%s\": read %d of %zu",
18321836
path,readBytes,sz)));
18331837
}
18341838
COMP_CRC32C(checksum,ondisk.builder.committed.xip,sz);

‎src/backend/replication/slot.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,8 @@ RestoreSlotFromDisk(const char *name)
14201420
errmsg("could not read file \"%s\": %m",path)));
14211421
else
14221422
ereport(PANIC,
1423-
(errmsg("could not read file \"%s\": read %d of %zu",
1423+
(errcode(ERRCODE_DATA_CORRUPTED),
1424+
errmsg("could not read file \"%s\": read %d of %zu",
14241425
path,readBytes,
14251426
(Size)ReplicationSlotOnDiskConstantSize)));
14261427
}
@@ -1464,7 +1465,8 @@ RestoreSlotFromDisk(const char *name)
14641465
errmsg("could not read file \"%s\": %m",path)));
14651466
else
14661467
ereport(PANIC,
1467-
(errmsg("could not read file \"%s\": read %d of %zu",
1468+
(errcode(ERRCODE_DATA_CORRUPTED),
1469+
errmsg("could not read file \"%s\": read %d of %zu",
14681470
path,readBytes, (Size)cp.length)));
14691471
}
14701472

‎src/backend/replication/walsender.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
509509
path)));
510510
elseif (nread==0)
511511
ereport(ERROR,
512-
(errmsg("could not read file \"%s\": read %d of %zu",
512+
(errcode(ERRCODE_DATA_CORRUPTED),
513+
errmsg("could not read file \"%s\": read %d of %zu",
513514
path,nread, (Size)bytesleft)));
514515

515516
pq_sendbytes(&buf,rbuf,nread);
@@ -2442,7 +2443,8 @@ XLogRead(char *buf, XLogRecPtr startptr, Size count)
24422443
elseif (readbytes==0)
24432444
{
24442445
ereport(ERROR,
2445-
(errmsg("could not read from log segment %s, offset %u: read %d of %zu",
2446+
(errcode(ERRCODE_DATA_CORRUPTED),
2447+
errmsg("could not read from log segment %s, offset %u: read %d of %zu",
24462448
XLogFileNameP(curFileTimeLine,sendSegNo),
24472449
sendOff,readbytes, (Size)segbytes)));
24482450
}

‎src/backend/utils/cache/relmapper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,8 @@ load_relmap_file(bool shared)
669669
errmsg("could not read file \"%s\": %m",mapfilename)));
670670
else
671671
ereport(FATAL,
672-
(errmsg("could not read file \"%s\": read %d of %zu",
672+
(errcode(ERRCODE_DATA_CORRUPTED),
673+
errmsg("could not read file \"%s\": read %d of %zu",
673674
mapfilename,r,sizeof(RelMapFile))));
674675
}
675676
pgstat_report_wait_end();

‎src/common/controldata_utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ get_controlfile(const char *DataDir, const char *progname, bool *crc_ok_p)
8383
else
8484
#ifndefFRONTEND
8585
ereport(ERROR,
86-
(errmsg("could not read file \"%s\": read %d of %zu",
86+
(errcode(ERRCODE_DATA_CORRUPTED),
87+
errmsg("could not read file \"%s\": read %d of %zu",
8788
ControlFilePath,r,sizeof(ControlFileData))));
8889
#else
8990
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp