aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/heap/rewriteheap.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2022-09-02 16:58:06 +0900
committerMichael Paquier <michael@paquier.xyz>2022-09-02 16:58:06 +0900
commitbfb9dfd93720098cf8f3e7d802df9b02ebe3dc20 (patch)
treeda8365df67d59ce2cc7271ffef54f53665bc0870 /src/backend/access/heap/rewriteheap.c
parent11e5f99d39ef58ce34c41f4163c1a3df2c639069 (diff)
downloadpostgresql-bfb9dfd93720098cf8f3e7d802df9b02ebe3dc20.tar.gz
postgresql-bfb9dfd93720098cf8f3e7d802df9b02ebe3dc20.zip
Expand the use of get_dirent_type(), shaving a few calls to stat()/lstat()
Several backend-side loops scanning one or more directories with ReadDir() (WAL segment recycle/removal in xlog.c, backend-side directory copy, temporary file removal, configuration file parsing, some logical decoding logic and some pgtz stuff) already know the type of the entry being scanned thanks to the dirent structure associated to the entry, on platforms where we know about DT_REG, DT_DIR and DT_LNK to make the difference between a regular file, a directory and a symbolic link. Relying on the direct structure of an entry saves a few system calls to stat() and lstat() in the loops updated here, shaving some code while on it. The logic of the code remains the same, calling stat() or lstat() depending on if it is necessary to look through symlinks. Authors: Nathan Bossart, Bharath Rupireddy Reviewed-by: Andres Freund, Thomas Munro, Michael Paquier Discussion: https://postgr.es/m/CALj2ACV8n-J-f=yiLUOx2=HrQGPSOZM3nWzyQQvLPcccPXxEdg@mail.gmail.com
Diffstat (limited to 'src/backend/access/heap/rewriteheap.c')
-rw-r--r--src/backend/access/heap/rewriteheap.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c
index 9dd885d936f..2f08fbe8d31 100644
--- a/src/backend/access/heap/rewriteheap.c
+++ b/src/backend/access/heap/rewriteheap.c
@@ -113,6 +113,7 @@
#include "access/xact.h"
#include "access/xloginsert.h"
#include "catalog/catalog.h"
+#include "common/file_utils.h"
#include "lib/ilist.h"
#include "miscadmin.h"
#include "pgstat.h"
@@ -1213,7 +1214,6 @@ CheckPointLogicalRewriteHeap(void)
mappings_dir = AllocateDir("pg_logical/mappings");
while ((mapping_de = ReadDir(mappings_dir, "pg_logical/mappings")) != NULL)
{
- struct stat statbuf;
Oid dboid;
Oid relid;
XLogRecPtr lsn;
@@ -1221,13 +1221,16 @@ CheckPointLogicalRewriteHeap(void)
TransactionId create_xid;
uint32 hi,
lo;
+ PGFileType de_type;
if (strcmp(mapping_de->d_name, ".") == 0 ||
strcmp(mapping_de->d_name, "..") == 0)
continue;
snprintf(path, sizeof(path), "pg_logical/mappings/%s", mapping_de->d_name);
- if (lstat(path, &statbuf) == 0 && !S_ISREG(statbuf.st_mode))
+ de_type = get_dirent_type(path, mapping_de, false, DEBUG1);
+
+ if (de_type != PGFILETYPE_ERROR && de_type != PGFILETYPE_REG)
continue;
/* Skip over files that cannot be ours. */