Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9c94e90

Browse 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 ispossible to replace lstat call with DT_REG check (readdir call isrequired) and state that it is either a regular file or a directory.Symlinks to tablespaces assumed to be dirs.
1 parentf4c24d6 commit9c94e90

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

‎engine.c

Lines 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
charsubpath[MAXPGPATH*2];
643643
structstatfst;
644-
intsret;
644+
intsret=0;
645+
#ifSIMPLE_STAT
646+
boolassumeDir= 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+
#ifSIMPLE_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+
#ifSIMPLE_STAT
675+
if (!assumeDir)
676+
#else
664677
if (S_ISREG(fst.st_mode))
678+
#endif
665679
#ifCFS_SUPPORT
666680
ptrack_mark_file(dbOid,tablespaceOid,subpath,de->d_name,is_cfs);
667681
#else

‎engine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
#defineCFS_SUPPORT 1
5050
#endif
5151

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

‎ptrack.c

Lines 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
charsubpath[MAXPGPATH*2];
308308
structstatfst;
309-
intsret;
309+
intsret=0;
310+
#ifSIMPLE_STAT
311+
boolassumeDir= 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+
#ifSIMPLE_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+
#ifSIMPLE_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+
#ifSIMPLE_STAT
393+
else
394+
{
395+
#else
378396
elseif (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
elseif (S_ISLNK(fst.st_mode))
389409
#else
390410
elseif (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+
#ifSIMPLE_STAT
422+
}
423+
#endif
400424
}
401425

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp