Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c94e90

Browse filesBrowse files
author
Daniel Shelepanov
committed
[PBCKP-563] lstat optimized
in case DT_REG is defined and the PG_VERSION_NUM is less than 13 it is possible to replace lstat call with DT_REG check (readdir call is required) and state that it is either a regular file or a directory. Symlinks to tablespaces assumed to be dirs.
1 parent f4c24d6 commit 9c94e90
Copy full SHA for 9c94e90

File tree

3 files changed

+46
-3
lines changed
Filter options

3 files changed

+46
-3
lines changed

‎engine.c

Copy file name to clipboardExpand all lines: engine.c
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,10 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)
641641
{
642642
char subpath[MAXPGPATH * 2];
643643
struct stat fst;
644-
int sret;
644+
int sret = 0;
645+
#if SIMPLE_STAT
646+
bool assumeDir = false;
647+
#endif
645648

646649
CHECK_FOR_INTERRUPTS();
647650

@@ -651,7 +654,14 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)
651654

652655
snprintf(subpath, sizeof(subpath), "%s/%s", path, de->d_name);
653656

657+
#if SIMPLE_STAT
658+
if (de->d_type == DT_REG)
659+
sret = stat(subpath, &fst);
660+
else
661+
assumeDir = true;
662+
#else
654663
sret = lstat(subpath, &fst);
664+
#endif
655665

656666
if (sret < 0)
657667
{
@@ -661,7 +671,11 @@ ptrack_walkdir(const char *path, Oid tablespaceOid, Oid dbOid)
661671
continue;
662672
}
663673

674+
#if SIMPLE_STAT
675+
if (!assumeDir)
676+
#else
664677
if (S_ISREG(fst.st_mode))
678+
#endif
665679
#if CFS_SUPPORT
666680
ptrack_mark_file(dbOid, tablespaceOid, subpath, de->d_name, is_cfs);
667681
#else

‎engine.h

Copy file name to clipboardExpand all lines: engine.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
#define CFS_SUPPORT 1
5050
#endif
5151

52+
/* lstat optimization */
53+
#if defined(DT_REG) && PG_VERSION_NUM < 130000
54+
#define SIMPLE_STAT 1
55+
#endif
56+
5257
/*
5358
* Header of ptrack map.
5459
*/

‎ptrack.c

Copy file name to clipboardExpand all lines: ptrack.c
+26-2Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid)
306306
{
307307
char subpath[MAXPGPATH * 2];
308308
struct stat fst;
309-
int sret;
309+
int sret = 0;
310+
#if SIMPLE_STAT
311+
bool assumeDir = false;
312+
#endif
310313

311314
CHECK_FOR_INTERRUPTS();
312315

@@ -317,8 +320,15 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid)
317320
continue;
318321

319322
snprintf(subpath, sizeof(subpath), "%s/%s", path, de->d_name);
320-
323+
#if SIMPLE_STAT
324+
if (de->d_type == DT_REG)
325+
sret = stat(subpath, &fst);
326+
else
327+
assumeDir = true;
328+
#else
321329
sret = lstat(subpath, &fst);
330+
#endif
331+
322332

323333
if (sret < 0)
324334
{
@@ -328,7 +338,11 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid)
328338
continue;
329339
}
330340

341+
#if SIMPLE_STAT
342+
if (!assumeDir)
343+
#else
331344
if (S_ISREG(fst.st_mode))
345+
#endif
332346
{
333347
if (fst.st_size == 0)
334348
{
@@ -375,7 +389,12 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid)
375389
pfl->path, nodeRel(pfl->relnode));
376390
}
377391
}
392+
#if SIMPLE_STAT
393+
else
394+
{
395+
#else
378396
else if (S_ISDIR(fst.st_mode))
397+
#endif
379398
{
380399
if (strspn(de->d_name + 1, "0123456789") == strlen(de->d_name + 1)
381400
&& dbOid == InvalidOid)
@@ -384,10 +403,12 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid)
384403
ptrack_gather_filelist(filelist, subpath, spcOid, InvalidOid);
385404
}
386405
/* TODO: is it enough to properly check symlink support? */
406+
#if !SIMPLE_STAT
387407
#if !defined(WIN32) || (PG_VERSION_NUM >= 160000)
388408
else if (S_ISLNK(fst.st_mode))
389409
#else
390410
else if (pgwin32_is_junction(subpath))
411+
#endif
391412
#endif
392413
{
393414
/*
@@ -397,6 +418,9 @@ ptrack_gather_filelist(List **filelist, char *path, Oid spcOid, Oid dbOid)
397418
if (strspn(de->d_name + 1, "0123456789") == strlen(de->d_name + 1))
398419
ptrack_gather_filelist(filelist, subpath, atooid(de->d_name), InvalidOid);
399420
}
421+
#if SIMPLE_STAT
422+
}
423+
#endif
400424
}
401425

402426
FreeDir(dir); /* we ignore any error here */

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.