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

Commit71d84ef

Browse files
committed
Fix error handling of vacuumdb and reindexdb when running out of fds
When trying to use a high number of jobs, vacuumdb (and more recentlyreindexdb) has only checked for a maximum number of jobs used, causingconfusing failures when running out of file descriptors when the jobsopen connections to Postgres. This commit changes the error handling soas we do not check anymore for a maximum number of allowed jobs whenparsing the option value with FD_SETSIZE, but check instead if a filedescriptor is within the supported range when opening the connectionsfor the jobs so as this is detected at the earliest time possible.Also, improve the error message to give a hint about the number of jobsrecommended, using a wording given by the reviewers of the patch.Reported-by: Andres FreundAuthor: Michael PaquierReviewed-by: Andres Freund, Álvaro Herrera, Tom LaneDiscussion:https://postgr.es/m/20190818001858.ho3ev4z57fqhs7a5@alap3.anarazel.deBackpatch-through: 9.5
1 parent6338fa3 commit71d84ef

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

‎src/bin/scripts/reindexdb.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ main(int argc, char *argv[])
153153
pg_log_error("number of parallel jobs must be at least 1");
154154
exit(1);
155155
}
156-
if (concurrentCons>ParallelSlotsMax())
157-
{
158-
pg_log_error("too many parallel jobs requested (maximum: %d)",
159-
ParallelSlotsMax());
160-
exit(1);
161-
}
162156
break;
163157
case'v':
164158
verbose= true;

‎src/bin/scripts/scripts_parallel.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,6 @@ select_loop(int maxFd, fd_set *workerset, bool *aborting)
9494
returni;
9595
}
9696

97-
/*
98-
* ParallelSlotsMax
99-
*Returns the maximum number of parallel slots supported.
100-
*
101-
* Note that this is included here as FD_SETSIZE is declared in sys/select.h
102-
* per POSIX.
103-
*/
104-
int
105-
ParallelSlotsMax(void)
106-
{
107-
/* leave some room for pre-existing fds */
108-
returnFD_SETSIZE-10;
109-
}
110-
11197
/*
11298
* ParallelSlotsGetIdle
11399
*Return a connection slot that is ready to execute a command.
@@ -246,6 +232,18 @@ ParallelSlotsSetup(const char *dbname, const char *host, const char *port,
246232
{
247233
conn=connectDatabase(dbname,host,port,username,prompt_password,
248234
progname,echo, false, true);
235+
236+
/*
237+
* Fail and exit immediately if trying to use a socket in an
238+
* unsupported range. POSIX requires open(2) to use the lowest
239+
* unused file descriptor and the hint given relies on that.
240+
*/
241+
if (PQsocket(conn) >=FD_SETSIZE)
242+
{
243+
pg_log_fatal("too many jobs for this platform -- try %d",i);
244+
exit(1);
245+
}
246+
249247
init_slot(slots+i,conn);
250248
}
251249
}

‎src/bin/scripts/scripts_parallel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ typedef struct ParallelSlot
2121
boolisFree;/* Is it known to be idle? */
2222
}ParallelSlot;
2323

24-
externintParallelSlotsMax(void);
25-
2624
externParallelSlot*ParallelSlotsGetIdle(ParallelSlot*slots,intnumslots);
2725

2826
externParallelSlot*ParallelSlotsSetup(constchar*dbname,constchar*host,

‎src/bin/scripts/vacuumdb.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,6 @@ main(int argc, char *argv[])
181181
pg_log_error("number of parallel jobs must be at least 1");
182182
exit(1);
183183
}
184-
if (concurrentCons>ParallelSlotsMax())
185-
{
186-
pg_log_error("too many parallel jobs requested (maximum: %d)",
187-
ParallelSlotsMax());
188-
exit(1);
189-
}
190184
break;
191185
case2:
192186
maintenance_db=pg_strdup(optarg);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp