Skip to content

Commit 6599c9a

Browse files
committed
Add an Assert() to max_parallel_workers enforcement.
To prevent future bugs along the lines of the one corrected by commit 8ff5186, or find any that remain in the current code, add an Assert() that the difference between parallel_register_count and parallel_terminate_count is in a sane range. Kuntal Ghosh, with considerable tidying-up by me, per a suggestion from Neha Khatri. Reviewed by Tomas Vondra. Discussion: http://postgr.es/m/CAFO0U+-E8yzchwVnvn5BeRDPgX2z9vZUxQ8dxx9c0XFGBC7N1Q@mail.gmail.com
1 parent 8ff5186 commit 6599c9a

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/backend/postmaster/bgworker.c

+3
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,9 @@ RegisterDynamicBackgroundWorker(BackgroundWorker *worker,
971971
BackgroundWorkerData->parallel_terminate_count) >=
972972
max_parallel_workers)
973973
{
974+
Assert(BackgroundWorkerData->parallel_register_count -
975+
BackgroundWorkerData->parallel_terminate_count <=
976+
MAX_PARALLEL_WORKER_LIMIT);
974977
LWLockRelease(BackgroundWorkerLock);
975978
return false;
976979
}

src/backend/utils/misc/guc.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#include "parser/scansup.h"
5858
#include "pgstat.h"
5959
#include "postmaster/autovacuum.h"
60-
#include "postmaster/bgworker.h"
60+
#include "postmaster/bgworker_internals.h"
6161
#include "postmaster/bgwriter.h"
6262
#include "postmaster/postmaster.h"
6363
#include "postmaster/syslogger.h"
@@ -2713,7 +2713,7 @@ static struct config_int ConfigureNamesInt[] =
27132713
NULL
27142714
},
27152715
&max_parallel_workers_per_gather,
2716-
2, 0, 1024,
2716+
2, 0, MAX_PARALLEL_WORKER_LIMIT,
27172717
NULL, NULL, NULL
27182718
},
27192719

@@ -2723,7 +2723,7 @@ static struct config_int ConfigureNamesInt[] =
27232723
NULL
27242724
},
27252725
&max_parallel_workers,
2726-
8, 0, 1024,
2726+
8, 0, MAX_PARALLEL_WORKER_LIMIT,
27272727
NULL, NULL, NULL
27282728
},
27292729

src/include/postmaster/bgworker_internals.h

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
#include "lib/ilist.h"
1717
#include "postmaster/bgworker.h"
1818

19+
/* GUC options */
20+
21+
/*
22+
* Maximum possible value of parallel workers.
23+
*/
24+
#define MAX_PARALLEL_WORKER_LIMIT 1024
25+
1926
/*
2027
* List of background workers, private to postmaster.
2128
*

0 commit comments

Comments
 (0)