Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Better error messages for short reads/writes in SLRU
authorPeter Eisentraut <peter@eisentraut.org>
Tue, 3 Sep 2019 06:26:55 +0000 (08:26 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Tue, 3 Sep 2019 06:34:59 +0000 (08:34 +0200)
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

src/backend/access/transam/slru.c

index 2dbc65b125ba8d4adfbf08aa2e40176e8463ddc3..3903a130a1f9446328cd55d37d8fce68696de8b1 100644 (file)
@@ -920,18 +920,29 @@ SlruReportIOError(SlruCtl ctl, int pageno, TransactionId xid)
                               path, offset)));
            break;
        case SLRU_READ_FAILED:
-           ereport(ERROR,
-                   (errcode_for_file_access(),
-                    errmsg("could not access status of transaction %u", xid),
-                    errdetail("Could not read from file \"%s\" at offset %u: %m.",
-                              path, offset)));
+           if (errno)
+               ereport(ERROR,
+                       (errcode_for_file_access(),
+                        errmsg("could not access status of transaction %u", xid),
+                        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;
        case SLRU_WRITE_FAILED:
-           ereport(ERROR,
-                   (errcode_for_file_access(),
-                    errmsg("could not access status of transaction %u", xid),
-                    errdetail("Could not write to file \"%s\" at offset %u: %m.",
-                              path, offset)));
+           if (errno)
+               ereport(ERROR,
+                       (errcode_for_file_access(),
+                        errmsg("could not access status of transaction %u", xid),
+                        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;
        case SLRU_FSYNC_FAILED:
            ereport(data_sync_elevel(ERROR),