aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-04-11 13:03:44 -0400
committerRobert Haas <rhaas@postgresql.org>2017-04-11 13:03:44 -0400
commit6599c9ac3340b6cd3d86a0a7f866b80a009fecab (patch)
tree56403ac7f0c62a1ba37390c3b9b64d44d4a32340 /src
parent8ff518699f19dd0a5076f5090bac8400b8233f7f (diff)
downloadpostgresql-6599c9ac3340b6cd3d86a0a7f866b80a009fecab.tar.gz
postgresql-6599c9ac3340b6cd3d86a0a7f866b80a009fecab.zip
Add an Assert() to max_parallel_workers enforcement.
To prevent future bugs along the lines of the one corrected by commit 8ff518699f19dd0a5076f5090bac8400b8233f7f, 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
Diffstat (limited to 'src')
-rw-r--r--src/backend/postmaster/bgworker.c3
-rw-r--r--src/backend/utils/misc/guc.c6
-rw-r--r--src/include/postmaster/bgworker_internals.h7
3 files changed, 13 insertions, 3 deletions
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index 6b2385c4711..9ad3e915db3 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -971,6 +971,9 @@ RegisterDynamicBackgroundWorker(BackgroundWorker *worker,
BackgroundWorkerData->parallel_terminate_count) >=
max_parallel_workers)
{
+ Assert(BackgroundWorkerData->parallel_register_count -
+ BackgroundWorkerData->parallel_terminate_count <=
+ MAX_PARALLEL_WORKER_LIMIT);
LWLockRelease(BackgroundWorkerLock);
return false;
}
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 6e39a676094..9ad8361a9bd 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -57,7 +57,7 @@
#include "parser/scansup.h"
#include "pgstat.h"
#include "postmaster/autovacuum.h"
-#include "postmaster/bgworker.h"
+#include "postmaster/bgworker_internals.h"
#include "postmaster/bgwriter.h"
#include "postmaster/postmaster.h"
#include "postmaster/syslogger.h"
@@ -2713,7 +2713,7 @@ static struct config_int ConfigureNamesInt[] =
NULL
},
&max_parallel_workers_per_gather,
- 2, 0, 1024,
+ 2, 0, MAX_PARALLEL_WORKER_LIMIT,
NULL, NULL, NULL
},
@@ -2723,7 +2723,7 @@ static struct config_int ConfigureNamesInt[] =
NULL
},
&max_parallel_workers,
- 8, 0, 1024,
+ 8, 0, MAX_PARALLEL_WORKER_LIMIT,
NULL, NULL, NULL
},
diff --git a/src/include/postmaster/bgworker_internals.h b/src/include/postmaster/bgworker_internals.h
index 9a2de4f4d04..9e0b0621cf4 100644
--- a/src/include/postmaster/bgworker_internals.h
+++ b/src/include/postmaster/bgworker_internals.h
@@ -16,6 +16,13 @@
#include "lib/ilist.h"
#include "postmaster/bgworker.h"
+/* GUC options */
+
+/*
+ * Maximum possible value of parallel workers.
+ */
+#define MAX_PARALLEL_WORKER_LIMIT 1024
+
/*
* List of background workers, private to postmaster.
*