1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Add proper errcodes to new error messages for read() failures

Those would use the default ERRCODE_INTERNAL_ERROR, but for foreseeable
failures an errcode ought to be set, ERRCODE_DATA_CORRUPTED making the
most sense here.

While on the way, fix one errcode_for_file_access missing in origin.c
since the code has been created, and remove one assignment of errno to 0
before calling read(), as this was around to fit with what was present
before 811b6e36 where errno would not be set when not enough bytes are
read.  I have noticed the first one, and Tom has pinged me about the
second one.

Author: Michael Paquier
Reported-by: Tom Lane
Discussion: https://postgr.es/m/27265.1531925836@sss.pgh.pa.us
This commit is contained in:
Michael Paquier
2018-07-23 09:37:36 +09:00
parent 56df07bb9e
commit e41d0a1090
7 changed files with 30 additions and 16 deletions

View File

@ -1736,7 +1736,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
}
else
ereport(ERROR,
(errmsg("could not read file \"%s\": read %d of %zu",
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("could not read file \"%s\": read %d of %zu",
path, readBytes,
(Size) SnapBuildOnDiskConstantSize)));
}
@ -1775,7 +1776,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
}
else
ereport(ERROR,
(errmsg("could not read file \"%s\": read %d of %zu",
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("could not read file \"%s\": read %d of %zu",
path, readBytes, sizeof(SnapBuild))));
}
COMP_CRC32C(checksum, &ondisk.builder, sizeof(SnapBuild));
@ -1802,7 +1804,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
}
else
ereport(ERROR,
(errmsg("could not read file \"%s\": read %d of %zu",
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("could not read file \"%s\": read %d of %zu",
path, readBytes, sz)));
}
COMP_CRC32C(checksum, ondisk.builder.was_running.was_xip, sz);
@ -1828,7 +1831,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
}
else
ereport(ERROR,
(errmsg("could not read file \"%s\": read %d of %zu",
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("could not read file \"%s\": read %d of %zu",
path, readBytes, sz)));
}
COMP_CRC32C(checksum, ondisk.builder.committed.xip, sz);