mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
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
This commit is contained in:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user