diff options
author | Robert Haas <rhaas@postgresql.org> | 2022-02-08 15:52:40 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2022-02-08 15:53:19 -0500 |
commit | aa64f23b02924724eafbd9eadbf26d85df30a12b (patch) | |
tree | 54f72bfd7e36c2e879dc87149eb94db220d1cae3 /src/backend/storage/lmgr/predicate.c | |
parent | 2da896182ce11240774af6c4d769777f90a09536 (diff) |
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
Diffstat (limited to 'src/backend/storage/lmgr/predicate.c')
-rw-r--r-- | src/backend/storage/lmgr/predicate.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c index 25e7e4e37bf..e337aad5b24 100644 --- a/src/backend/storage/lmgr/predicate.c +++ b/src/backend/storage/lmgr/predicate.c @@ -257,7 +257,7 @@ (&MainLWLockArray[PREDICATELOCK_MANAGER_LWLOCK_OFFSET + (i)].lock) #define NPREDICATELOCKTARGETENTS() \ - mul_size(max_predicate_locks_per_xact, add_size(MaxBackends, max_prepared_xacts)) + mul_size(max_predicate_locks_per_xact, add_size(GetMaxBackends(), max_prepared_xacts)) #define SxactIsOnFinishedList(sxact) (!SHMQueueIsDetached(&((sxact)->finishedLink))) @@ -1222,7 +1222,7 @@ InitPredicateLocks(void) * Compute size for serializable transaction hashtable. Note these * calculations must agree with PredicateLockShmemSize! */ - max_table_size = (MaxBackends + max_prepared_xacts); + max_table_size = (GetMaxBackends() + max_prepared_xacts); /* * Allocate a list to hold information on transactions participating in @@ -1375,7 +1375,7 @@ PredicateLockShmemSize(void) size = add_size(size, size / 10); /* transaction list */ - max_table_size = MaxBackends + max_prepared_xacts; + max_table_size = GetMaxBackends() + max_prepared_xacts; max_table_size *= 10; size = add_size(size, PredXactListDataSize); size = add_size(size, mul_size((Size) max_table_size, @@ -1907,7 +1907,7 @@ GetSerializableTransactionSnapshotInt(Snapshot snapshot, { ++(PredXact->WritableSxactCount); Assert(PredXact->WritableSxactCount <= - (MaxBackends + max_prepared_xacts)); + (GetMaxBackends() + max_prepared_xacts)); } MySerializableXact = sxact; @@ -5111,7 +5111,7 @@ predicatelock_twophase_recover(TransactionId xid, uint16 info, { ++(PredXact->WritableSxactCount); Assert(PredXact->WritableSxactCount <= - (MaxBackends + max_prepared_xacts)); + (GetMaxBackends() + max_prepared_xacts)); } /* |