Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9473bb9

Browse files
committed
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.
1 parent 23e5b16 commit 9473bb9

File tree

1 file changed

+13
-4
lines changed
  • src/backend/storage/file

1 file changed

+13
-4
lines changed

src/backend/storage/file/fd.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,10 @@ FileClose(File file)
10971097
*/
10981098
vfdP->fdstate &= ~FD_TEMPORARY;
10991099

1100+
/* Subtract its size from current usage (do first in case of error) */
1101+
temporary_files_size -= vfdP->fileSize;
1102+
vfdP->fileSize = 0;
1103+
11001104
if (log_temp_files >= 0)
11011105
{
11021106
struct stat filestats;
@@ -1133,10 +1137,6 @@ FileClose(File file)
11331137
if (unlink(vfdP->fileName))
11341138
elog(LOG, "could not unlink file \"%s\": %m", vfdP->fileName);
11351139
}
1136-
1137-
/* Subtract its size from current usage */
1138-
temporary_files_size -= vfdP->fileSize;
1139-
vfdP->fileSize = 0;
11401140
}
11411141

11421142
/* Unregister it from the resource owner */
@@ -1447,6 +1447,15 @@ FileTruncate(File file, off_t offset)
14471447
return returnCode;
14481448

14491449
returnCode = ftruncate(VfdCache[file].fd, offset);
1450+
1451+
if (returnCode == 0 && VfdCache[file].fileSize > offset)
1452+
{
1453+
/* adjust our state for truncation of a temp file */
1454+
Assert(VfdCache[file].fdstate & FD_TEMPORARY);
1455+
temporary_files_size -= VfdCache[file].fileSize - offset;
1456+
VfdCache[file].fileSize = offset;
1457+
}
1458+
14501459
return returnCode;
14511460
}
14521461

0 commit comments

Comments
 (0)