Better error messages for short reads/writes in SLRU

This avoids getting a

    Could not read from file ...: Success.

for a short read or write (since errno is not set in that case).
Instead, report a more specific error messages.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/flat/5de61b6b-8be9-7771-0048-860328efe027%402ndquadrant.com
This commit is contained in:
Peter Eisentraut 2019-09-03 08:26:55 +02:00
parent 5380719f93
commit 6ef121647f

View File

@ -920,18 +920,29 @@ SlruReportIOError(SlruCtl ctl, int pageno, TransactionId xid)
path, offset))); path, offset)));
break; break;
case SLRU_READ_FAILED: case SLRU_READ_FAILED:
ereport(ERROR, if (errno)
(errcode_for_file_access(), ereport(ERROR,
errmsg("could not access status of transaction %u", xid), (errcode_for_file_access(),
errdetail("Could not read from file \"%s\" at offset %u: %m.", errmsg("could not access status of transaction %u", xid),
path, offset))); errdetail("Could not read from file \"%s\" at offset %u: %m.",
path, offset)));
else
ereport(ERROR,
(errmsg("could not access status of transaction %u", xid),
errdetail("Could not read from file \"%s\" at offset %u: read too few bytes.", path, offset)));
break; break;
case SLRU_WRITE_FAILED: case SLRU_WRITE_FAILED:
ereport(ERROR, if (errno)
(errcode_for_file_access(), ereport(ERROR,
errmsg("could not access status of transaction %u", xid), (errcode_for_file_access(),
errdetail("Could not write to file \"%s\" at offset %u: %m.", errmsg("could not access status of transaction %u", xid),
path, offset))); errdetail("Could not write to file \"%s\" at offset %u: %m.",
path, offset)));
else
ereport(ERROR,
(errmsg("could not access status of transaction %u", xid),
errdetail("Could not write to file \"%s\" at offset %u: wrote too few bytes.",
path, offset)));
break; break;
case SLRU_FSYNC_FAILED: case SLRU_FSYNC_FAILED:
ereport(data_sync_elevel(ERROR), ereport(data_sync_elevel(ERROR),