I recently noticed this in a customer log file:
ERROR: could not read from hash-join temporary file: Success
The problem is we're reporting with %m when the problem is a partial
read or write.
I propose the attached patch to solve it: report "wrote only X of X
bytes". This caused a lot of other trouble, the cause of which I've
been unable to pinpoint as yet. But in the meantime, this is already a
small improvement.
--
Álvaro Herrera
diff --git a/src/backend/executor/nodeHashjoin.c b/src/backend/executor/nodeHashjoin.c
index d13efc4d98..377554772b 100644
--- a/src/backend/executor/nodeHashjoin.c
+++ b/src/backend/executor/nodeHashjoin.c
@@ -882,16 +882,26 @@ ExecHashJoinSaveTuple(MinimalTuple tuple, uint32 hashvalue,
}
written = BufFileWrite(file, (void *) &hashvalue, sizeof(uint32));
+ if (written < 0)
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not write to hash-join temporary file: %m")));
if (written != sizeof(uint32))
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not write to hash-join temporary file: %m")));
+ errmsg("could not write to hash-join temporary file: wrote only %d of %d bytes",
+ (int) written, (int) sizeof(uint32))));
written = BufFileWrite(file, (void *) tuple, tuple->t_len);
- if (written != tuple->t_len)
+ if (written < 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not write to hash-join temporary file: %m")));
+ if (written != tuple->t_len)
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not write to hash-join temporary file: wrote only %d of %d bytes",
+ (int) written, (int) tuple->t_len)));
}
/*
@@ -929,20 +939,30 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
ExecClearTuple(tupleSlot);
return NULL;
}
- if (nread != sizeof(header))
+ if (nread < 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not read from hash-join temporary file: %m")));
+ if (nread != sizeof(header))
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not read from hash-join temporary file: read only %d of %d bytes",
+ (int) nread, (int) sizeof(header))));
*hashvalue = header[0];
tuple = (MinimalTuple) palloc(header[1]);
tuple->t_len = header[1];
nread = BufFileRead(file,
(void *) ((char *) tuple + sizeof(uint32)),
header[1] - sizeof(uint32));
- if (nread != header[1] - sizeof(uint32))
+ if (nread < 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not read from hash-join temporary file: %m")));
+ if (nread != header[1] - sizeof(uint32))
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not read from hash-join temporary file: read only %d of %d bytes",
+ (int) nread, (int) (header[1] - sizeof(uint32)))));
return ExecStoreMinimalTuple(tuple, tupleSlot, true);
}