1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

In pg_upgrade, copy fsm, vm, and extent files by checking for file

existence via open(), rather than collecting a directory listing and
looking up matching relfilenode files with sequential scans of the
array.  This speeds up pg_upgrade by 2x for a large number of tables,
e.g. 16k.

Per observation by Ants Aasma.
This commit is contained in:
Bruce Momjian
2012-11-14 17:32:04 -05:00
parent a235b85a0b
commit 29add0de49
3 changed files with 82 additions and 183 deletions

View File

@ -221,61 +221,6 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
#endif
/*
* load_directory()
*
* Read all the file names in the specified directory, and return them as
* an array of "char *" pointers. The array address is returned in
* *namelist, and the function result is the count of file names.
*
* To free the result data, free each (char *) array member, then free the
* namelist array itself.
*/
int
load_directory(const char *dirname, char ***namelist)
{
DIR *dirdesc;
struct dirent *direntry;
int count = 0;
int allocsize = 64; /* initial array size */
*namelist = (char **) pg_malloc(allocsize * sizeof(char *));
if ((dirdesc = opendir(dirname)) == NULL)
pg_log(PG_FATAL, "could not open directory \"%s\": %s\n",
dirname, getErrorText(errno));
while (errno = 0, (direntry = readdir(dirdesc)) != NULL)
{
if (count >= allocsize)
{
allocsize *= 2;
*namelist = (char **)
pg_realloc(*namelist, allocsize * sizeof(char *));
}
(*namelist)[count++] = pg_strdup(direntry->d_name);
}
#ifdef WIN32
/*
* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
* released version
*/
if (GetLastError() == ERROR_NO_MORE_FILES)
errno = 0;
#endif
if (errno)
pg_log(PG_FATAL, "could not read directory \"%s\": %s\n",
dirname, getErrorText(errno));
closedir(dirdesc);
return count;
}
void
check_hard_link(void)
{