v20251001-0008-BufFileCreateCompressTemp-cleanup-and-comm.patch
text/x-patch
Filename: v20251001-0008-BufFileCreateCompressTemp-cleanup-and-comm.patch
Type: text/x-patch
Part: 7
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v20251001-0008
Subject: BufFileCreateCompressTemp - cleanup and comments
| File | + | − |
|---|---|---|
| src/backend/storage/file/buffile.c | 21 | 11 |
From 2b0d51f4e80c3b84f0a492f9b8be718a3047161c Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@vondra.me>
Date: Mon, 29 Sep 2025 21:21:37 +0200
Subject: [PATCH v20251001 08/25] BufFileCreateCompressTemp - cleanup and
comments
---
src/backend/storage/file/buffile.c | 32 ++++++++++++++++++++----------
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
index 6a43ad1ee38..7cfca79ab5c 100644
--- a/src/backend/storage/file/buffile.c
+++ b/src/backend/storage/file/buffile.c
@@ -261,14 +261,12 @@ BufFileCreateCompressTemp(bool interXact)
static char *buff = NULL;
static int allocated_for_compression = TEMP_NONE_COMPRESSION;
static int allocated_size = 0;
- BufFile *tmpBufFile = BufFileCreateTemp(interXact);
+ BufFile *file = BufFileCreateTemp(interXact);
if (temp_file_compression != TEMP_NONE_COMPRESSION)
{
int size = 0;
- tmpBufFile->compress = true;
-
switch (temp_file_compression)
{
case TEMP_LZ4_COMPRESSION:
@@ -282,28 +280,40 @@ BufFileCreateCompressTemp(bool interXact)
}
/*
- * Allocate or reallocate buffer if needed: - Buffer is NULL (first
- * time) - Compression type changed - Current buffer is too small
+ * Allocate or reallocate buffer if needed - first call, compression
+ * method changed, or the buffer is too small.
+ *
+ * XXX Can the buffer be too small if the method did not change? Does the
+ * method matter, or just the size?
*/
- if (buff == NULL ||
- allocated_for_compression != temp_file_compression ||
- allocated_size < size)
+ if ((buff == NULL) ||
+ (allocated_for_compression != temp_file_compression) ||
+ (allocated_size < size))
{
+ /*
+ * FIXME Isn't this pfree wrong? How do we know the buffer is not
+ * used by some existing temp file?
+ */
if (buff != NULL)
pfree(buff);
/*
- * Persistent buffer for all temporary file compressions
+ * Persistent buffer for all temporary file compressions.
*/
buff = MemoryContextAlloc(TopMemoryContext, size);
allocated_for_compression = temp_file_compression;
allocated_size = size;
}
- tmpBufFile->cBuffer = buff;
+ file->compress = true;
+ file->cBuffer = buff;
}
- return tmpBufFile;
+ /* compression with buffer, or no compression and no buffer */
+ Assert((!file->compress && file->cBuffer == NULL) ||
+ (file->compress && file->cBuffer != NULL));
+
+ return file;
}
/*
--
2.51.0