aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/file/fd.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-07-17 15:05:44 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-07-17 15:05:44 -0400
commit9473bb96d0eb7ed73f1bf5269613e6266f64ad85 (patch)
treeb2ff4fa57ed570ff1caddfed70ad5ba03fc54e61 /src/backend/storage/file/fd.c
parent23e5b16c71f2706978c5f54aabd28ed23a54b6a5 (diff)
downloadpostgresql-9473bb96d0eb7ed73f1bf5269613e6266f64ad85.tar.gz
postgresql-9473bb96d0eb7ed73f1bf5269613e6266f64ad85.zip
Further thoughts about temp_file_limit patch.
Move FileClose's decrement of temporary_files_size up, so that it will be executed even if elog() throws an error. This is reasonable since if the unlink() fails, the fact the file is still there is not our fault, and we are going to forget about it anyhow. So we won't count it against temp_file_limit anymore. Update fileSize and temporary_files_size correctly in FileTruncate. We probably don't have any places that truncate temp files, but fd.c surely should not assume that.
Diffstat (limited to 'src/backend/storage/file/fd.c')
-rw-r--r--src/backend/storage/file/fd.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 884d9151278..95402794b47 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -1097,6 +1097,10 @@ FileClose(File file)
*/
vfdP->fdstate &= ~FD_TEMPORARY;
+ /* Subtract its size from current usage (do first in case of error) */
+ temporary_files_size -= vfdP->fileSize;
+ vfdP->fileSize = 0;
+
if (log_temp_files >= 0)
{
struct stat filestats;
@@ -1133,10 +1137,6 @@ FileClose(File file)
if (unlink(vfdP->fileName))
elog(LOG, "could not unlink file \"%s\": %m", vfdP->fileName);
}
-
- /* Subtract its size from current usage */
- temporary_files_size -= vfdP->fileSize;
- vfdP->fileSize = 0;
}
/* Unregister it from the resource owner */
@@ -1447,6 +1447,15 @@ FileTruncate(File file, off_t offset)
return returnCode;
returnCode = ftruncate(VfdCache[file].fd, offset);
+
+ if (returnCode == 0 && VfdCache[file].fileSize > offset)
+ {
+ /* adjust our state for truncation of a temp file */
+ Assert(VfdCache[file].fdstate & FD_TEMPORARY);
+ temporary_files_size -= VfdCache[file].fileSize - offset;
+ VfdCache[file].fileSize = offset;
+ }
+
return returnCode;
}