Commit 4c8f8ffa authored by Tom Lane's avatar Tom Lane

Further code review for pg_stat_ssl patch.

Fix additional bogosity in commit 9029f4b3.  Include the
BackendSslStatusBuffer in the BackendStatusShmemSize calculation,
avoid ugly and error-prone casts to char* and back, put related
code stanzas into a consistent order (and fix a couple of previous
instances of that sin).  All cosmetic except for the size oversight.
parent 7d791ed4
...@@ -2478,8 +2478,8 @@ pgstat_fetch_global(void) ...@@ -2478,8 +2478,8 @@ pgstat_fetch_global(void)
static PgBackendStatus *BackendStatusArray = NULL; static PgBackendStatus *BackendStatusArray = NULL;
static PgBackendStatus *MyBEEntry = NULL; static PgBackendStatus *MyBEEntry = NULL;
static char *BackendClientHostnameBuffer = NULL;
static char *BackendAppnameBuffer = NULL; static char *BackendAppnameBuffer = NULL;
static char *BackendClientHostnameBuffer = NULL;
static char *BackendActivityBuffer = NULL; static char *BackendActivityBuffer = NULL;
static Size BackendActivityBufferSize = 0; static Size BackendActivityBufferSize = 0;
#ifdef USE_SSL #ifdef USE_SSL
...@@ -2495,13 +2495,22 @@ BackendStatusShmemSize(void) ...@@ -2495,13 +2495,22 @@ BackendStatusShmemSize(void)
{ {
Size size; Size size;
/* BackendStatusArray: */
size = mul_size(sizeof(PgBackendStatus), MaxBackends); size = mul_size(sizeof(PgBackendStatus), MaxBackends);
/* BackendAppnameBuffer: */
size = add_size(size,
mul_size(NAMEDATALEN, MaxBackends));
/* BackendClientHostnameBuffer: */
size = add_size(size, size = add_size(size,
mul_size(NAMEDATALEN, MaxBackends)); mul_size(NAMEDATALEN, MaxBackends));
/* BackendActivityBuffer: */
size = add_size(size, size = add_size(size,
mul_size(pgstat_track_activity_query_size, MaxBackends)); mul_size(pgstat_track_activity_query_size, MaxBackends));
#ifdef USE_SSL
/* BackendSslStatusBuffer: */
size = add_size(size, size = add_size(size,
mul_size(NAMEDATALEN, MaxBackends)); mul_size(sizeof(PgBackendSSLStatus), MaxBackends));
#endif
return size; return size;
} }
...@@ -2566,26 +2575,6 @@ CreateSharedBackendStatus(void) ...@@ -2566,26 +2575,6 @@ CreateSharedBackendStatus(void)
} }
} }
#ifdef USE_SSL
/* Create or attach to the shared SSL status buffer */
size = mul_size(sizeof(PgBackendSSLStatus), MaxBackends);
BackendSslStatusBuffer = (PgBackendSSLStatus *)
ShmemInitStruct("Backend SSL Status Buffer", size, &found);
if (!found)
{
MemSet(BackendSslStatusBuffer, 0, size);
/* Initialize st_sslstatus pointers. */
buffer = (char *) BackendSslStatusBuffer;
for (i = 0; i < MaxBackends; i++)
{
BackendStatusArray[i].st_sslstatus = (PgBackendSSLStatus *) buffer;
buffer += sizeof(PgBackendSSLStatus);
}
}
#endif
/* Create or attach to the shared activity buffer */ /* Create or attach to the shared activity buffer */
BackendActivityBufferSize = mul_size(pgstat_track_activity_query_size, BackendActivityBufferSize = mul_size(pgstat_track_activity_query_size,
MaxBackends); MaxBackends);
...@@ -2606,6 +2595,28 @@ CreateSharedBackendStatus(void) ...@@ -2606,6 +2595,28 @@ CreateSharedBackendStatus(void)
buffer += pgstat_track_activity_query_size; buffer += pgstat_track_activity_query_size;
} }
} }
#ifdef USE_SSL
/* Create or attach to the shared SSL status buffer */
size = mul_size(sizeof(PgBackendSSLStatus), MaxBackends);
BackendSslStatusBuffer = (PgBackendSSLStatus *)
ShmemInitStruct("Backend SSL Status Buffer", size, &found);
if (!found)
{
PgBackendSSLStatus *ptr;
MemSet(BackendSslStatusBuffer, 0, size);
/* Initialize st_sslstatus pointers. */
ptr = BackendSslStatusBuffer;
for (i = 0; i < MaxBackends; i++)
{
BackendStatusArray[i].st_sslstatus = ptr;
ptr++;
}
}
#endif
} }
...@@ -2932,11 +2943,11 @@ pgstat_read_current_status(void) ...@@ -2932,11 +2943,11 @@ pgstat_read_current_status(void)
volatile PgBackendStatus *beentry; volatile PgBackendStatus *beentry;
LocalPgBackendStatus *localtable; LocalPgBackendStatus *localtable;
LocalPgBackendStatus *localentry; LocalPgBackendStatus *localentry;
char *localappname,
*localactivity;
#ifdef USE_SSL #ifdef USE_SSL
PgBackendSSLStatus *localsslstatus; PgBackendSSLStatus *localsslstatus;
#endif #endif
char *localappname,
*localactivity;
int i; int i;
Assert(!pgStatRunningInCollector); Assert(!pgStatRunningInCollector);
...@@ -2951,15 +2962,15 @@ pgstat_read_current_status(void) ...@@ -2951,15 +2962,15 @@ pgstat_read_current_status(void)
localappname = (char *) localappname = (char *)
MemoryContextAlloc(pgStatLocalContext, MemoryContextAlloc(pgStatLocalContext,
NAMEDATALEN * MaxBackends); NAMEDATALEN * MaxBackends);
localactivity = (char *)
MemoryContextAlloc(pgStatLocalContext,
pgstat_track_activity_query_size * MaxBackends);
#ifdef USE_SSL #ifdef USE_SSL
localsslstatus = (PgBackendSSLStatus *) localsslstatus = (PgBackendSSLStatus *)
MemoryContextAlloc(pgStatLocalContext, MemoryContextAlloc(pgStatLocalContext,
sizeof(PgBackendSSLStatus) * MaxBackends); sizeof(PgBackendSSLStatus) * MaxBackends);
#endif #endif
localactivity = (char *)
MemoryContextAlloc(pgStatLocalContext,
pgstat_track_activity_query_size * MaxBackends);
localNumBackends = 0; localNumBackends = 0;
beentry = BackendStatusArray; beentry = BackendStatusArray;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment