mirror of
https://github.com/postgres/postgres.git
synced 2025-11-24 00:23:06 +03:00
Revert the addition of GetMaxBackends() and related stuff.
This reverts commits0147fc7,4567596,aa64f23, and5ecd018. There is no longer agreement that introducing this function was the right way to address the problem. The consensus now seems to favor trying to make a correct value for MaxBackends available to mdules executing their _PG_init() functions. Nathan Bossart Discussion: http://postgr.es/m/20220323045229.i23skfscdbvrsuxa@jrouhaud
This commit is contained in:
@@ -26,6 +26,18 @@
|
||||
#include "utils/memutils.h"
|
||||
|
||||
|
||||
/* ----------
|
||||
* Total number of backends including auxiliary
|
||||
*
|
||||
* We reserve a slot for each possible BackendId, plus one for each
|
||||
* possible auxiliary process type. (This scheme assumes there is not
|
||||
* more than one of any auxiliary process type at a time.) MaxBackends
|
||||
* includes autovacuum workers and background workers as well.
|
||||
* ----------
|
||||
*/
|
||||
#define NumBackendStatSlots (MaxBackends + NUM_AUXPROCTYPES)
|
||||
|
||||
|
||||
/* ----------
|
||||
* GUC parameters
|
||||
* ----------
|
||||
@@ -63,23 +75,8 @@ static MemoryContext backendStatusSnapContext;
|
||||
static void pgstat_beshutdown_hook(int code, Datum arg);
|
||||
static void pgstat_read_current_status(void);
|
||||
static void pgstat_setup_backend_status_context(void);
|
||||
static inline int GetNumBackendStatSlots(void);
|
||||
|
||||
|
||||
/*
|
||||
* Retrieve the total number of backends including auxiliary
|
||||
*
|
||||
* We reserve a slot for each possible BackendId, plus one for each possible
|
||||
* auxiliary process type. (This scheme assumes there is not more than one of
|
||||
* any auxiliary process type at a time.) MaxBackends includes autovacuum
|
||||
* workers and background workers as well.
|
||||
*/
|
||||
static inline int
|
||||
GetNumBackendStatSlots(void)
|
||||
{
|
||||
return GetMaxBackends() + NUM_AUXPROCTYPES;
|
||||
}
|
||||
|
||||
/*
|
||||
* Report shared-memory space needed by CreateSharedBackendStatus.
|
||||
*/
|
||||
@@ -87,28 +84,27 @@ Size
|
||||
BackendStatusShmemSize(void)
|
||||
{
|
||||
Size size;
|
||||
int numBackendStatSlots = GetNumBackendStatSlots();
|
||||
|
||||
/* BackendStatusArray: */
|
||||
size = mul_size(sizeof(PgBackendStatus), numBackendStatSlots);
|
||||
size = mul_size(sizeof(PgBackendStatus), NumBackendStatSlots);
|
||||
/* BackendAppnameBuffer: */
|
||||
size = add_size(size,
|
||||
mul_size(NAMEDATALEN, numBackendStatSlots));
|
||||
mul_size(NAMEDATALEN, NumBackendStatSlots));
|
||||
/* BackendClientHostnameBuffer: */
|
||||
size = add_size(size,
|
||||
mul_size(NAMEDATALEN, numBackendStatSlots));
|
||||
mul_size(NAMEDATALEN, NumBackendStatSlots));
|
||||
/* BackendActivityBuffer: */
|
||||
size = add_size(size,
|
||||
mul_size(pgstat_track_activity_query_size, numBackendStatSlots));
|
||||
mul_size(pgstat_track_activity_query_size, NumBackendStatSlots));
|
||||
#ifdef USE_SSL
|
||||
/* BackendSslStatusBuffer: */
|
||||
size = add_size(size,
|
||||
mul_size(sizeof(PgBackendSSLStatus), numBackendStatSlots));
|
||||
mul_size(sizeof(PgBackendSSLStatus), NumBackendStatSlots));
|
||||
#endif
|
||||
#ifdef ENABLE_GSS
|
||||
/* BackendGssStatusBuffer: */
|
||||
size = add_size(size,
|
||||
mul_size(sizeof(PgBackendGSSStatus), numBackendStatSlots));
|
||||
mul_size(sizeof(PgBackendGSSStatus), NumBackendStatSlots));
|
||||
#endif
|
||||
return size;
|
||||
}
|
||||
@@ -124,10 +120,9 @@ CreateSharedBackendStatus(void)
|
||||
bool found;
|
||||
int i;
|
||||
char *buffer;
|
||||
int numBackendStatSlots = GetNumBackendStatSlots();
|
||||
|
||||
/* Create or attach to the shared array */
|
||||
size = mul_size(sizeof(PgBackendStatus), numBackendStatSlots);
|
||||
size = mul_size(sizeof(PgBackendStatus), NumBackendStatSlots);
|
||||
BackendStatusArray = (PgBackendStatus *)
|
||||
ShmemInitStruct("Backend Status Array", size, &found);
|
||||
|
||||
@@ -140,7 +135,7 @@ CreateSharedBackendStatus(void)
|
||||
}
|
||||
|
||||
/* Create or attach to the shared appname buffer */
|
||||
size = mul_size(NAMEDATALEN, numBackendStatSlots);
|
||||
size = mul_size(NAMEDATALEN, NumBackendStatSlots);
|
||||
BackendAppnameBuffer = (char *)
|
||||
ShmemInitStruct("Backend Application Name Buffer", size, &found);
|
||||
|
||||
@@ -150,7 +145,7 @@ CreateSharedBackendStatus(void)
|
||||
|
||||
/* Initialize st_appname pointers. */
|
||||
buffer = BackendAppnameBuffer;
|
||||
for (i = 0; i < numBackendStatSlots; i++)
|
||||
for (i = 0; i < NumBackendStatSlots; i++)
|
||||
{
|
||||
BackendStatusArray[i].st_appname = buffer;
|
||||
buffer += NAMEDATALEN;
|
||||
@@ -158,7 +153,7 @@ CreateSharedBackendStatus(void)
|
||||
}
|
||||
|
||||
/* Create or attach to the shared client hostname buffer */
|
||||
size = mul_size(NAMEDATALEN, numBackendStatSlots);
|
||||
size = mul_size(NAMEDATALEN, NumBackendStatSlots);
|
||||
BackendClientHostnameBuffer = (char *)
|
||||
ShmemInitStruct("Backend Client Host Name Buffer", size, &found);
|
||||
|
||||
@@ -168,7 +163,7 @@ CreateSharedBackendStatus(void)
|
||||
|
||||
/* Initialize st_clienthostname pointers. */
|
||||
buffer = BackendClientHostnameBuffer;
|
||||
for (i = 0; i < numBackendStatSlots; i++)
|
||||
for (i = 0; i < NumBackendStatSlots; i++)
|
||||
{
|
||||
BackendStatusArray[i].st_clienthostname = buffer;
|
||||
buffer += NAMEDATALEN;
|
||||
@@ -177,7 +172,7 @@ CreateSharedBackendStatus(void)
|
||||
|
||||
/* Create or attach to the shared activity buffer */
|
||||
BackendActivityBufferSize = mul_size(pgstat_track_activity_query_size,
|
||||
numBackendStatSlots);
|
||||
NumBackendStatSlots);
|
||||
BackendActivityBuffer = (char *)
|
||||
ShmemInitStruct("Backend Activity Buffer",
|
||||
BackendActivityBufferSize,
|
||||
@@ -189,7 +184,7 @@ CreateSharedBackendStatus(void)
|
||||
|
||||
/* Initialize st_activity pointers. */
|
||||
buffer = BackendActivityBuffer;
|
||||
for (i = 0; i < numBackendStatSlots; i++)
|
||||
for (i = 0; i < NumBackendStatSlots; i++)
|
||||
{
|
||||
BackendStatusArray[i].st_activity_raw = buffer;
|
||||
buffer += pgstat_track_activity_query_size;
|
||||
@@ -198,7 +193,7 @@ CreateSharedBackendStatus(void)
|
||||
|
||||
#ifdef USE_SSL
|
||||
/* Create or attach to the shared SSL status buffer */
|
||||
size = mul_size(sizeof(PgBackendSSLStatus), numBackendStatSlots);
|
||||
size = mul_size(sizeof(PgBackendSSLStatus), NumBackendStatSlots);
|
||||
BackendSslStatusBuffer = (PgBackendSSLStatus *)
|
||||
ShmemInitStruct("Backend SSL Status Buffer", size, &found);
|
||||
|
||||
@@ -210,7 +205,7 @@ CreateSharedBackendStatus(void)
|
||||
|
||||
/* Initialize st_sslstatus pointers. */
|
||||
ptr = BackendSslStatusBuffer;
|
||||
for (i = 0; i < numBackendStatSlots; i++)
|
||||
for (i = 0; i < NumBackendStatSlots; i++)
|
||||
{
|
||||
BackendStatusArray[i].st_sslstatus = ptr;
|
||||
ptr++;
|
||||
@@ -220,7 +215,7 @@ CreateSharedBackendStatus(void)
|
||||
|
||||
#ifdef ENABLE_GSS
|
||||
/* Create or attach to the shared GSSAPI status buffer */
|
||||
size = mul_size(sizeof(PgBackendGSSStatus), numBackendStatSlots);
|
||||
size = mul_size(sizeof(PgBackendGSSStatus), NumBackendStatSlots);
|
||||
BackendGssStatusBuffer = (PgBackendGSSStatus *)
|
||||
ShmemInitStruct("Backend GSS Status Buffer", size, &found);
|
||||
|
||||
@@ -232,7 +227,7 @@ CreateSharedBackendStatus(void)
|
||||
|
||||
/* Initialize st_gssstatus pointers. */
|
||||
ptr = BackendGssStatusBuffer;
|
||||
for (i = 0; i < numBackendStatSlots; i++)
|
||||
for (i = 0; i < NumBackendStatSlots; i++)
|
||||
{
|
||||
BackendStatusArray[i].st_gssstatus = ptr;
|
||||
ptr++;
|
||||
@@ -256,7 +251,7 @@ pgstat_beinit(void)
|
||||
/* Initialize MyBEEntry */
|
||||
if (MyBackendId != InvalidBackendId)
|
||||
{
|
||||
Assert(MyBackendId >= 1 && MyBackendId <= GetMaxBackends());
|
||||
Assert(MyBackendId >= 1 && MyBackendId <= MaxBackends);
|
||||
MyBEEntry = &BackendStatusArray[MyBackendId - 1];
|
||||
}
|
||||
else
|
||||
@@ -272,7 +267,7 @@ pgstat_beinit(void)
|
||||
* MaxBackends + AuxBackendType + 1 as the index of the slot for an
|
||||
* auxiliary process.
|
||||
*/
|
||||
MyBEEntry = &BackendStatusArray[GetMaxBackends() + MyAuxProcType];
|
||||
MyBEEntry = &BackendStatusArray[MaxBackends + MyAuxProcType];
|
||||
}
|
||||
|
||||
/* Set up a process-exit hook to clean up */
|
||||
@@ -744,7 +739,6 @@ pgstat_read_current_status(void)
|
||||
PgBackendGSSStatus *localgssstatus;
|
||||
#endif
|
||||
int i;
|
||||
int numBackendStatSlots = GetNumBackendStatSlots();
|
||||
|
||||
if (localBackendStatusTable)
|
||||
return; /* already done */
|
||||
@@ -761,32 +755,32 @@ pgstat_read_current_status(void)
|
||||
*/
|
||||
localtable = (LocalPgBackendStatus *)
|
||||
MemoryContextAlloc(backendStatusSnapContext,
|
||||
sizeof(LocalPgBackendStatus) * numBackendStatSlots);
|
||||
sizeof(LocalPgBackendStatus) * NumBackendStatSlots);
|
||||
localappname = (char *)
|
||||
MemoryContextAlloc(backendStatusSnapContext,
|
||||
NAMEDATALEN * numBackendStatSlots);
|
||||
NAMEDATALEN * NumBackendStatSlots);
|
||||
localclienthostname = (char *)
|
||||
MemoryContextAlloc(backendStatusSnapContext,
|
||||
NAMEDATALEN * numBackendStatSlots);
|
||||
NAMEDATALEN * NumBackendStatSlots);
|
||||
localactivity = (char *)
|
||||
MemoryContextAllocHuge(backendStatusSnapContext,
|
||||
pgstat_track_activity_query_size * numBackendStatSlots);
|
||||
pgstat_track_activity_query_size * NumBackendStatSlots);
|
||||
#ifdef USE_SSL
|
||||
localsslstatus = (PgBackendSSLStatus *)
|
||||
MemoryContextAlloc(backendStatusSnapContext,
|
||||
sizeof(PgBackendSSLStatus) * numBackendStatSlots);
|
||||
sizeof(PgBackendSSLStatus) * NumBackendStatSlots);
|
||||
#endif
|
||||
#ifdef ENABLE_GSS
|
||||
localgssstatus = (PgBackendGSSStatus *)
|
||||
MemoryContextAlloc(backendStatusSnapContext,
|
||||
sizeof(PgBackendGSSStatus) * numBackendStatSlots);
|
||||
sizeof(PgBackendGSSStatus) * NumBackendStatSlots);
|
||||
#endif
|
||||
|
||||
localNumBackends = 0;
|
||||
|
||||
beentry = BackendStatusArray;
|
||||
localentry = localtable;
|
||||
for (i = 1; i <= numBackendStatSlots; i++)
|
||||
for (i = 1; i <= NumBackendStatSlots; i++)
|
||||
{
|
||||
/*
|
||||
* Follow the protocol of retrying if st_changecount changes while we
|
||||
@@ -899,10 +893,9 @@ pgstat_get_backend_current_activity(int pid, bool checkUser)
|
||||
{
|
||||
PgBackendStatus *beentry;
|
||||
int i;
|
||||
int max_backends = GetMaxBackends();
|
||||
|
||||
beentry = BackendStatusArray;
|
||||
for (i = 1; i <= max_backends; i++)
|
||||
for (i = 1; i <= MaxBackends; i++)
|
||||
{
|
||||
/*
|
||||
* Although we expect the target backend's entry to be stable, that
|
||||
@@ -978,7 +971,6 @@ pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen)
|
||||
{
|
||||
volatile PgBackendStatus *beentry;
|
||||
int i;
|
||||
int max_backends = GetMaxBackends();
|
||||
|
||||
beentry = BackendStatusArray;
|
||||
|
||||
@@ -989,7 +981,7 @@ pgstat_get_crashed_backend_activity(int pid, char *buffer, int buflen)
|
||||
if (beentry == NULL || BackendActivityBuffer == NULL)
|
||||
return NULL;
|
||||
|
||||
for (i = 1; i <= max_backends; i++)
|
||||
for (i = 1; i <= MaxBackends; i++)
|
||||
{
|
||||
if (beentry->st_procpid == pid)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user