diff options
author | Michael Paquier <michael@paquier.xyz> | 2022-09-02 16:58:06 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2022-09-02 16:58:06 +0900 |
commit | bfb9dfd93720098cf8f3e7d802df9b02ebe3dc20 (patch) | |
tree | da8365df67d59ce2cc7271ffef54f53665bc0870 /src/backend/access/transam/xlog.c | |
parent | 11e5f99d39ef58ce34c41f4163c1a3df2c639069 (diff) | |
download | postgresql-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/transam/xlog.c')
-rw-r--r-- | src/backend/access/transam/xlog.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index fbf2d34eef9..7a710e6490d 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -657,8 +657,9 @@ static void PreallocXlogFiles(XLogRecPtr endptr, TimeLineID tli); static void RemoveTempXlogFiles(void); static void RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr lastredoptr, XLogRecPtr endptr, TimeLineID insertTLI); -static void RemoveXlogFile(const char *segname, XLogSegNo recycleSegNo, - XLogSegNo *endlogSegNo, TimeLineID insertTLI); +static void RemoveXlogFile(const struct dirent *segment_de, + XLogSegNo recycleSegNo, XLogSegNo *endlogSegNo, + TimeLineID insertTLI); static void UpdateLastRemovedPtr(char *filename); static void ValidateXLOGDirectoryStructure(void); static void CleanupBackupHistory(void); @@ -3596,8 +3597,7 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr lastredoptr, XLogRecPtr endptr, /* Update the last removed location in shared memory first */ UpdateLastRemovedPtr(xlde->d_name); - RemoveXlogFile(xlde->d_name, recycleSegNo, &endlogSegNo, - insertTLI); + RemoveXlogFile(xlde, recycleSegNo, &endlogSegNo, insertTLI); } } } @@ -3669,8 +3669,7 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI) * - but seems safer to let them be archived and removed later. */ if (!XLogArchiveIsReady(xlde->d_name)) - RemoveXlogFile(xlde->d_name, recycleSegNo, &endLogSegNo, - newTLI); + RemoveXlogFile(xlde, recycleSegNo, &endLogSegNo, newTLI); } } @@ -3680,9 +3679,9 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI) /* * Recycle or remove a log file that's no longer needed. * - * segname is the name of the segment to recycle or remove. recycleSegNo - * is the segment number to recycle up to. endlogSegNo is the segment - * number of the current (or recent) end of WAL. + * segment_de is the dirent structure of the segment to recycle or remove. + * recycleSegNo is the segment number to recycle up to. endlogSegNo is + * the segment number of the current (or recent) end of WAL. * * endlogSegNo gets incremented if the segment is recycled so as it is not * checked again with future callers of this function. @@ -3691,14 +3690,15 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI) * should be used for this timeline. */ static void -RemoveXlogFile(const char *segname, XLogSegNo recycleSegNo, - XLogSegNo *endlogSegNo, TimeLineID insertTLI) +RemoveXlogFile(const struct dirent *segment_de, + XLogSegNo recycleSegNo, XLogSegNo *endlogSegNo, + TimeLineID insertTLI) { char path[MAXPGPATH]; #ifdef WIN32 char newpath[MAXPGPATH]; #endif - struct stat statbuf; + const char *segname = segment_de->d_name; snprintf(path, MAXPGPATH, XLOGDIR "/%s", segname); @@ -3710,7 +3710,7 @@ RemoveXlogFile(const char *segname, XLogSegNo recycleSegNo, if (wal_recycle && *endlogSegNo <= recycleSegNo && XLogCtl->InstallXLogFileSegmentActive && /* callee rechecks this */ - lstat(path, &statbuf) == 0 && S_ISREG(statbuf.st_mode) && + get_dirent_type(path, segment_de, false, DEBUG2) == PGFILETYPE_REG && InstallXLogFileSegment(endlogSegNo, path, true, recycleSegNo, insertTLI)) { |