v20250930-0006-simplify-BufFileCreateTemp-interface.patch
text/x-patch
Filename: v20250930-0006-simplify-BufFileCreateTemp-interface.patch
Type: text/x-patch
Part: 5
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 v20250930-0006
Subject: simplify BufFileCreateTemp interface
| File | + | − |
|---|---|---|
| src/backend/access/gist/gistbuildbuffers.c | 1 | 1 |
| src/backend/backup/backup_manifest.c | 1 | 1 |
| src/backend/storage/file/buffile.c | 7 | 8 |
| src/backend/utils/sort/logtape.c | 1 | 1 |
| src/backend/utils/sort/tuplestore.c | 1 | 1 |
| src/include/storage/buffile.h | 1 | 1 |
From 2bfead57cd8c67e4269da27f4f5e77a9bd52e053 Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tomas@vondra.me>
Date: Mon, 29 Sep 2025 21:10:37 +0200
Subject: [PATCH v20250930 06/22] simplify BufFileCreateTemp interface
Having BufFileCreateTemp(interXact,compress) seems unnecessary, when
everyone calls it with compress=false, with the exception of
BufFileCreateCompressTemp.
In fact, it seems fragile, because what if someone happens to call it
with true, without initializing the buffer?
---
src/backend/access/gist/gistbuildbuffers.c | 2 +-
src/backend/backup/backup_manifest.c | 2 +-
src/backend/storage/file/buffile.c | 15 +++++++--------
src/backend/utils/sort/logtape.c | 2 +-
src/backend/utils/sort/tuplestore.c | 2 +-
src/include/storage/buffile.h | 2 +-
6 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/src/backend/access/gist/gistbuildbuffers.c b/src/backend/access/gist/gistbuildbuffers.c
index 9cc371f47fe..0707254d18e 100644
--- a/src/backend/access/gist/gistbuildbuffers.c
+++ b/src/backend/access/gist/gistbuildbuffers.c
@@ -54,7 +54,7 @@ gistInitBuildBuffers(int pagesPerBuffer, int levelStep, int maxLevel)
* Create a temporary file to hold buffer pages that are swapped out of
* memory.
*/
- gfbb->pfile = BufFileCreateTemp(false, false);
+ gfbb->pfile = BufFileCreateTemp(false);
gfbb->nFileBlocks = 0;
/* Initialize free page management. */
diff --git a/src/backend/backup/backup_manifest.c b/src/backend/backup/backup_manifest.c
index 35d088db0f3..d05252f383c 100644
--- a/src/backend/backup/backup_manifest.c
+++ b/src/backend/backup/backup_manifest.c
@@ -65,7 +65,7 @@ InitializeBackupManifest(backup_manifest_info *manifest,
manifest->buffile = NULL;
else
{
- manifest->buffile = BufFileCreateTemp(false, false);
+ manifest->buffile = BufFileCreateTemp(false);
manifest->manifest_ctx = pg_cryptohash_create(PG_SHA256);
if (pg_cryptohash_init(manifest->manifest_ctx) < 0)
elog(ERROR, "failed to initialize checksum of backup manifest: %s",
diff --git a/src/backend/storage/file/buffile.c b/src/backend/storage/file/buffile.c
index 9f466e92fa2..88a1a30e418 100644
--- a/src/backend/storage/file/buffile.c
+++ b/src/backend/storage/file/buffile.c
@@ -215,7 +215,7 @@ extendBufFile(BufFile *file)
* buffile will corrupt temporary data offsets.
*/
BufFile *
-BufFileCreateTemp(bool interXact, bool compress)
+BufFileCreateTemp(bool interXact)
{
BufFile *file;
File pfile;
@@ -237,11 +237,6 @@ BufFileCreateTemp(bool interXact, bool compress)
file = makeBufFile(pfile);
file->isInterXact = interXact;
- if (temp_file_compression != TEMP_NONE_COMPRESSION)
- {
- file->compress = compress;
- }
-
return file;
}
@@ -256,12 +251,14 @@ BufFileCreateCompressTemp(bool interXact)
static char *buff = NULL;
static int allocated_for_compression = TEMP_NONE_COMPRESSION;
static int allocated_size = 0;
- BufFile *tmpBufFile = BufFileCreateTemp(interXact, true);
+ BufFile *tmpBufFile = BufFileCreateTemp(interXact);
if (temp_file_compression != TEMP_NONE_COMPRESSION)
{
int size = 0;
+ tmpBufFile->compress = true;
+
switch (temp_file_compression)
{
case TEMP_LZ4_COMPRESSION:
@@ -292,8 +289,10 @@ BufFileCreateCompressTemp(bool interXact)
allocated_for_compression = temp_file_compression;
allocated_size = size;
}
+
+ tmpBufFile->cBuffer = buff;
}
- tmpBufFile->cBuffer = buff;
+
return tmpBufFile;
}
diff --git a/src/backend/utils/sort/logtape.c b/src/backend/utils/sort/logtape.c
index d862e22ef18..e529ceb8260 100644
--- a/src/backend/utils/sort/logtape.c
+++ b/src/backend/utils/sort/logtape.c
@@ -592,7 +592,7 @@ LogicalTapeSetCreate(bool preallocate, SharedFileSet *fileset, int worker)
lts->pfile = BufFileCreateFileSet(&fileset->fs, filename);
}
else
- lts->pfile = BufFileCreateTemp(false, false);
+ lts->pfile = BufFileCreateTemp(false);
return lts;
}
diff --git a/src/backend/utils/sort/tuplestore.c b/src/backend/utils/sort/tuplestore.c
index ef85924cd21..c9aecab8d66 100644
--- a/src/backend/utils/sort/tuplestore.c
+++ b/src/backend/utils/sort/tuplestore.c
@@ -860,7 +860,7 @@ tuplestore_puttuple_common(Tuplestorestate *state, void *tuple)
*/
oldcxt = MemoryContextSwitchTo(state->context->parent);
- state->myfile = BufFileCreateTemp(state->interXact, false);
+ state->myfile = BufFileCreateTemp(state->interXact);
MemoryContextSwitchTo(oldcxt);
diff --git a/src/include/storage/buffile.h b/src/include/storage/buffile.h
index 57908dd5462..49594f1948e 100644
--- a/src/include/storage/buffile.h
+++ b/src/include/storage/buffile.h
@@ -45,7 +45,7 @@ extern PGDLLIMPORT int temp_file_compression;
* prototypes for functions in buffile.c
*/
-extern BufFile *BufFileCreateTemp(bool interXact, bool compress);
+extern BufFile *BufFileCreateTemp(bool interXact);
extern BufFile *BufFileCreateCompressTemp(bool interXact);
extern void BufFileClose(BufFile *file);
pg_nodiscard extern size_t BufFileRead(BufFile *file, void *ptr, size_t size);
--
2.51.0