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

Commit7fc0e7d

Browse files
committed
Revert the addition of GetMaxBackends() and related stuff.
This reverts commits0147fc7,4567596,aa64f23, and5ecd018.There is no longer agreement that introducing this functionwas the right way to address the problem. The consensus nowseems to favor trying to make a correct value for MaxBackendsavailable to mdules executing their _PG_init() functions.Nathan BossartDiscussion:http://postgr.es/m/20220323045229.i23skfscdbvrsuxa@jrouhaud
1 parent2c93818 commit7fc0e7d

File tree

19 files changed

+142
-227
lines changed

19 files changed

+142
-227
lines changed

‎src/backend/access/nbtree/nbtutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@ BTreeShmemSize(void)
20722072
Sizesize;
20732073

20742074
size= offsetof(BTVacInfo,vacuums);
2075-
size=add_size(size,mul_size(GetMaxBackends(),sizeof(BTOneVacInfo)));
2075+
size=add_size(size,mul_size(MaxBackends,sizeof(BTOneVacInfo)));
20762076
returnsize;
20772077
}
20782078

@@ -2101,7 +2101,7 @@ BTreeShmemInit(void)
21012101
btvacinfo->cycle_ctr= (BTCycleId)time(NULL);
21022102

21032103
btvacinfo->num_vacuums=0;
2104-
btvacinfo->max_vacuums=GetMaxBackends();
2104+
btvacinfo->max_vacuums=MaxBackends;
21052105
}
21062106
else
21072107
Assert(found);

‎src/backend/access/transam/multixact.c

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,12 @@ typedef struct MultiXactStateData
282282
}MultiXactStateData;
283283

284284
/*
285-
* Pointers to the state data in shared memory
286-
*
287-
* The index of the last element of the OldestMemberMXactId and
288-
* OldestVisibleMXactId arrays can be obtained with GetMaxOldestSlot().
285+
* Last element of OldestMemberMXactId and OldestVisibleMXactId arrays.
286+
* Valid elements are (1..MaxOldestSlot); element 0 is never used.
289287
*/
288+
#defineMaxOldestSlot(MaxBackends + max_prepared_xacts)
289+
290+
/* Pointers to the state data in shared memory */
290291
staticMultiXactStateData*MultiXactState;
291292
staticMultiXactId*OldestMemberMXactId;
292293
staticMultiXactId*OldestVisibleMXactId;
@@ -341,7 +342,6 @@ static void MultiXactIdSetOldestVisible(void);
341342
staticvoidRecordNewMultiXact(MultiXactIdmulti,MultiXactOffsetoffset,
342343
intnmembers,MultiXactMember*members);
343344
staticMultiXactIdGetNewMultiXactId(intnmembers,MultiXactOffset*offset);
344-
staticinlineintGetMaxOldestSlot(void);
345345

346346
/* MultiXact cache management */
347347
staticintmxactMemberComparator(constvoid*arg1,constvoid*arg2);
@@ -662,17 +662,6 @@ MultiXactIdSetOldestMember(void)
662662
}
663663
}
664664

665-
/*
666-
* Retrieve the index of the last element of the OldestMemberMXactId and
667-
* OldestVisibleMXactId arrays. Valid elements are (1..MaxOldestSlot); element
668-
* 0 is never used.
669-
*/
670-
staticinlineint
671-
GetMaxOldestSlot(void)
672-
{
673-
returnGetMaxBackends()+max_prepared_xacts;
674-
}
675-
676665
/*
677666
* MultiXactIdSetOldestVisible
678667
*Save the oldest MultiXactId this transaction considers possibly live.
@@ -695,7 +684,6 @@ MultiXactIdSetOldestVisible(void)
695684
if (!MultiXactIdIsValid(OldestVisibleMXactId[MyBackendId]))
696685
{
697686
MultiXactIdoldestMXact;
698-
intmaxOldestSlot=GetMaxOldestSlot();
699687
inti;
700688

701689
LWLockAcquire(MultiXactGenLock,LW_EXCLUSIVE);
@@ -709,7 +697,7 @@ MultiXactIdSetOldestVisible(void)
709697
if (oldestMXact<FirstMultiXactId)
710698
oldestMXact=FirstMultiXactId;
711699

712-
for (i=1;i <=maxOldestSlot;i++)
700+
for (i=1;i <=MaxOldestSlot;i++)
713701
{
714702
MultiXactIdthisoldest=OldestMemberMXactId[i];
715703

@@ -1843,7 +1831,7 @@ MultiXactShmemSize(void)
18431831
/* We need 2*MaxOldestSlot + 1 perBackendXactIds[] entries */
18441832
#defineSHARED_MULTIXACT_STATE_SIZE \
18451833
add_size(offsetof(MultiXactStateData, perBackendXactIds) + sizeof(MultiXactId), \
1846-
mul_size(sizeof(MultiXactId) * 2,GetMaxOldestSlot()))
1834+
mul_size(sizeof(MultiXactId) * 2,MaxOldestSlot))
18471835

18481836
size=SHARED_MULTIXACT_STATE_SIZE;
18491837
size=add_size(size,SimpleLruShmemSize(NUM_MULTIXACTOFFSET_BUFFERS,0));
@@ -1894,7 +1882,7 @@ MultiXactShmemInit(void)
18941882
* since we only use indexes 1..MaxOldestSlot in each array.
18951883
*/
18961884
OldestMemberMXactId=MultiXactState->perBackendXactIds;
1897-
OldestVisibleMXactId=OldestMemberMXactId+GetMaxOldestSlot();
1885+
OldestVisibleMXactId=OldestMemberMXactId+MaxOldestSlot;
18981886
}
18991887

19001888
/*
@@ -2519,7 +2507,6 @@ GetOldestMultiXactId(void)
25192507
{
25202508
MultiXactIdoldestMXact;
25212509
MultiXactIdnextMXact;
2522-
intmaxOldestSlot=GetMaxOldestSlot();
25232510
inti;
25242511

25252512
/*
@@ -2538,7 +2525,7 @@ GetOldestMultiXactId(void)
25382525
nextMXact=FirstMultiXactId;
25392526

25402527
oldestMXact=nextMXact;
2541-
for (i=1;i <=maxOldestSlot;i++)
2528+
for (i=1;i <=MaxOldestSlot;i++)
25422529
{
25432530
MultiXactIdthisoldest;
25442531

‎src/backend/access/transam/twophase.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ TwoPhaseShmemInit(void)
264264
{
265265
GlobalTransactiongxacts;
266266
inti;
267-
intmax_backends=GetMaxBackends();
268267

269268
Assert(!found);
270269
TwoPhaseState->freeGXacts=NULL;
@@ -298,7 +297,7 @@ TwoPhaseShmemInit(void)
298297
* prepared transaction. Currently multixact.c uses that
299298
* technique.
300299
*/
301-
gxacts[i].dummyBackendId=max_backends+1+i;
300+
gxacts[i].dummyBackendId=MaxBackends+1+i;
302301
}
303302
}
304303
else

‎src/backend/commands/async.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ AsyncShmemSize(void)
518518
Sizesize;
519519

520520
/* This had better match AsyncShmemInit */
521-
size=mul_size(GetMaxBackends()+1,sizeof(QueueBackendStatus));
521+
size=mul_size(MaxBackends+1,sizeof(QueueBackendStatus));
522522
size=add_size(size, offsetof(AsyncQueueControl,backend));
523523

524524
size=add_size(size,SimpleLruShmemSize(NUM_NOTIFY_BUFFERS,0));
@@ -534,15 +534,14 @@ AsyncShmemInit(void)
534534
{
535535
boolfound;
536536
Sizesize;
537-
intmax_backends=GetMaxBackends();
538537

539538
/*
540539
* Create or attach to the AsyncQueueControl structure.
541540
*
542541
* The used entries in the backend[] array run from 1 to MaxBackends; the
543542
* zero'th entry is unused but must be allocated.
544543
*/
545-
size=mul_size(max_backends+1,sizeof(QueueBackendStatus));
544+
size=mul_size(MaxBackends+1,sizeof(QueueBackendStatus));
546545
size=add_size(size, offsetof(AsyncQueueControl,backend));
547546

548547
asyncQueueControl= (AsyncQueueControl*)
@@ -557,7 +556,7 @@ AsyncShmemInit(void)
557556
QUEUE_FIRST_LISTENER=InvalidBackendId;
558557
asyncQueueControl->lastQueueFillWarn=0;
559558
/* zero'th entry won't be used, but let's initialize it anyway */
560-
for (inti=0;i <=max_backends;i++)
559+
for (inti=0;i <=MaxBackends;i++)
561560
{
562561
QUEUE_BACKEND_PID(i)=InvalidPid;
563562
QUEUE_BACKEND_DBOID(i)=InvalidOid;
@@ -1633,7 +1632,6 @@ SignalBackends(void)
16331632
int32*pids;
16341633
BackendId*ids;
16351634
intcount;
1636-
intmax_backends=GetMaxBackends();
16371635

16381636
/*
16391637
* Identify backends that we need to signal. We don't want to send
@@ -1643,8 +1641,8 @@ SignalBackends(void)
16431641
* XXX in principle these pallocs could fail, which would be bad. Maybe
16441642
* preallocate the arrays? They're not that large, though.
16451643
*/
1646-
pids= (int32*)palloc(max_backends*sizeof(int32));
1647-
ids= (BackendId*)palloc(max_backends*sizeof(BackendId));
1644+
pids= (int32*)palloc(MaxBackends*sizeof(int32));
1645+
ids= (BackendId*)palloc(MaxBackends*sizeof(BackendId));
16481646
count=0;
16491647

16501648
LWLockAcquire(NotifyQueueLock,LW_EXCLUSIVE);

‎src/backend/libpq/pqcomm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
334334
structaddrinfohint;
335335
intlisten_index=0;
336336
intadded=0;
337-
intmax_backends=GetMaxBackends();
338337

339338
#ifdefHAVE_UNIX_SOCKETS
340339
charunixSocketPath[MAXPGPATH];
@@ -557,7 +556,7 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
557556
* intended to provide a clamp on the request on platforms where an
558557
* overly large request provokes a kernel error (are there any?).
559558
*/
560-
maxconn=max_backends*2;
559+
maxconn=MaxBackends*2;
561560
if (maxconn>PG_SOMAXCONN)
562561
maxconn=PG_SOMAXCONN;
563562

‎src/backend/postmaster/auxprocess.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ AuxiliaryProcessMain(AuxProcType auxtype)
116116
* This will need rethinking if we ever want more than one of a particular
117117
* auxiliary process type.
118118
*/
119-
ProcSignalInit(GetMaxBackends()+MyAuxProcType+1);
119+
ProcSignalInit(MaxBackends+MyAuxProcType+1);
120120

121121
/*
122122
* Auxiliary processes don't run transactions, but they may need a

‎src/backend/postmaster/postmaster.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,10 @@ PostmasterMain(int argc, char *argv[])
10051005
LocalProcessControlFile(false);
10061006

10071007
/*
1008-
* Register the apply launcher. It's probably a good idea to call this
1009-
* before any modules had a chance to take the background worker slots.
1008+
* Register the apply launcher. Since it registers a background worker,
1009+
* it needs to be called before InitializeMaxBackends(), and it's probably
1010+
* a good idea to call it before any modules had chance to take the
1011+
* background worker slots.
10101012
*/
10111013
ApplyLauncherRegister();
10121014

@@ -1027,8 +1029,8 @@ PostmasterMain(int argc, char *argv[])
10271029
#endif
10281030

10291031
/*
1030-
* Now that loadable modules have had their chance toalter any GUCs,
1031-
* calculate MaxBackends.
1032+
* Now that loadable modules have had their chance toregister background
1033+
*workers,calculate MaxBackends.
10321034
*/
10331035
InitializeMaxBackends();
10341036

@@ -6142,7 +6144,7 @@ save_backend_variables(BackendParameters *param, Port *port,
61426144
param->query_id_enabled=query_id_enabled;
61436145
param->max_safe_fds=max_safe_fds;
61446146

6145-
param->MaxBackends=GetMaxBackends();
6147+
param->MaxBackends=MaxBackends;
61466148

61476149
#ifdefWIN32
61486150
param->PostmasterHandle=PostmasterHandle;
@@ -6375,7 +6377,7 @@ restore_backend_variables(BackendParameters *param, Port *port)
63756377
query_id_enabled=param->query_id_enabled;
63766378
max_safe_fds=param->max_safe_fds;
63776379

6378-
SetMaxBackends(param->MaxBackends);
6380+
MaxBackends=param->MaxBackends;
63796381

63806382
#ifdefWIN32
63816383
PostmasterHandle=param->PostmasterHandle;

‎src/backend/storage/ipc/dsm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ dsm_postmaster_startup(PGShmemHeader *shim)
166166

167167
/* Determine size for new control segment. */
168168
maxitems=PG_DYNSHMEM_FIXED_SLOTS
169-
+PG_DYNSHMEM_SLOTS_PER_BACKEND*GetMaxBackends();
169+
+PG_DYNSHMEM_SLOTS_PER_BACKEND*MaxBackends;
170170
elog(DEBUG2,"dynamic shared memory system will support %u segments",
171171
maxitems);
172172
segsize=dsm_control_bytes_needed(maxitems);

‎src/backend/storage/ipc/procarray.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ typedef struct ProcArrayStruct
9797
/* oldest catalog xmin of any replication slot */
9898
TransactionIdreplication_slot_catalog_xmin;
9999

100-
/* indexes into allProcs[], hasProcArrayMaxProcs entries */
100+
/* indexes into allProcs[], hasPROCARRAY_MAXPROCS entries */
101101
intpgprocnos[FLEXIBLE_ARRAY_MEMBER];
102102
}ProcArrayStruct;
103103

@@ -355,17 +355,6 @@ static void MaintainLatestCompletedXidRecovery(TransactionId latestXid);
355355
staticinlineFullTransactionIdFullXidRelativeTo(FullTransactionIdrel,
356356
TransactionIdxid);
357357
staticvoidGlobalVisUpdateApply(ComputeXidHorizonsResult*horizons);
358-
staticinlineintGetProcArrayMaxProcs(void);
359-
360-
361-
/*
362-
* Retrieve the number of slots in the ProcArray structure.
363-
*/
364-
staticinlineint
365-
GetProcArrayMaxProcs(void)
366-
{
367-
returnGetMaxBackends()+max_prepared_xacts;
368-
}
369358

370359
/*
371360
* Report shared-memory space needed by CreateSharedProcArray.
@@ -376,8 +365,10 @@ ProcArrayShmemSize(void)
376365
Sizesize;
377366

378367
/* Size of the ProcArray structure itself */
368+
#definePROCARRAY_MAXPROCS(MaxBackends + max_prepared_xacts)
369+
379370
size= offsetof(ProcArrayStruct,pgprocnos);
380-
size=add_size(size,mul_size(sizeof(int),GetProcArrayMaxProcs()));
371+
size=add_size(size,mul_size(sizeof(int),PROCARRAY_MAXPROCS));
381372

382373
/*
383374
* During Hot Standby processing we have a data structure called
@@ -393,7 +384,7 @@ ProcArrayShmemSize(void)
393384
* shared memory is being set up.
394385
*/
395386
#defineTOTAL_MAX_CACHED_SUBXIDS \
396-
((PGPROC_MAX_CACHED_SUBXIDS + 1) *GetProcArrayMaxProcs())
387+
((PGPROC_MAX_CACHED_SUBXIDS + 1) *PROCARRAY_MAXPROCS)
397388

398389
if (EnableHotStandby)
399390
{
@@ -420,7 +411,7 @@ CreateSharedProcArray(void)
420411
ShmemInitStruct("Proc Array",
421412
add_size(offsetof(ProcArrayStruct,pgprocnos),
422413
mul_size(sizeof(int),
423-
GetProcArrayMaxProcs())),
414+
PROCARRAY_MAXPROCS)),
424415
&found);
425416

426417
if (!found)
@@ -429,7 +420,7 @@ CreateSharedProcArray(void)
429420
* We're the first - initialize.
430421
*/
431422
procArray->numProcs=0;
432-
procArray->maxProcs=GetProcArrayMaxProcs();
423+
procArray->maxProcs=PROCARRAY_MAXPROCS;
433424
procArray->maxKnownAssignedXids=TOTAL_MAX_CACHED_SUBXIDS;
434425
procArray->numKnownAssignedXids=0;
435426
procArray->tailKnownAssignedXids=0;
@@ -4645,7 +4636,7 @@ KnownAssignedXidsCompress(bool force)
46454636
*/
46464637
intnelements=head-tail;
46474638

4648-
if (nelements<4*GetProcArrayMaxProcs()||
4639+
if (nelements<4*PROCARRAY_MAXPROCS||
46494640
nelements<2*pArray->numKnownAssignedXids)
46504641
return;
46514642
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp