From aa64f23b02924724eafbd9eadbf26d85df30a12b Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 8 Feb 2022 15:52:40 -0500 Subject: Remove MaxBackends variable in favor of GetMaxBackends() function. Previously, it was really easy to write code that accessed MaxBackends before we'd actually initialized it, especially when coding up an extension. To make this less error-prune, introduce a new function GetMaxBackends() which should be used to obtain the correct value. This will ERROR if called too early. Demote the global variable to a file-level static, so that nobody can peak at it directly. Nathan Bossart. Idea by Andres Freund. Review by Greg Sabino Mullane, by Michael Paquier (who had doubts about the approach), and by me. Discussion: http://postgr.es/m/20210802224204.bckcikl45uezv5e4@alap3.anarazel.de --- src/backend/access/nbtree/nbtutils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/backend/access/nbtree/nbtutils.c') diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c index 6a651d8397b..84164748b3e 100644 --- a/src/backend/access/nbtree/nbtutils.c +++ b/src/backend/access/nbtree/nbtutils.c @@ -2072,7 +2072,7 @@ BTreeShmemSize(void) Size size; size = offsetof(BTVacInfo, vacuums); - size = add_size(size, mul_size(MaxBackends, sizeof(BTOneVacInfo))); + size = add_size(size, mul_size(GetMaxBackends(), sizeof(BTOneVacInfo))); return size; } @@ -2101,7 +2101,7 @@ BTreeShmemInit(void) btvacinfo->cycle_ctr = (BTCycleId) time(NULL); btvacinfo->num_vacuums = 0; - btvacinfo->max_vacuums = MaxBackends; + btvacinfo->max_vacuums = GetMaxBackends(); } else Assert(found); -- cgit v1.2.3