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

Commit4c8f8ff

Browse files
committed
Further code review for pg_stat_ssl patch.
Fix additional bogosity in commit9029f4b. Include theBackendSslStatusBuffer in the BackendStatusShmemSize calculation,avoid ugly and error-prone casts to char* and back, put relatedcode stanzas into a consistent order (and fix a couple of previousinstances of that sin). All cosmetic except for the size oversight.
1 parent7d791ed commit4c8f8ff

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,8 +2478,8 @@ pgstat_fetch_global(void)
24782478

24792479
staticPgBackendStatus*BackendStatusArray=NULL;
24802480
staticPgBackendStatus*MyBEEntry=NULL;
2481-
staticchar*BackendClientHostnameBuffer=NULL;
24822481
staticchar*BackendAppnameBuffer=NULL;
2482+
staticchar*BackendClientHostnameBuffer=NULL;
24832483
staticchar*BackendActivityBuffer=NULL;
24842484
staticSizeBackendActivityBufferSize=0;
24852485
#ifdefUSE_SSL
@@ -2495,13 +2495,22 @@ BackendStatusShmemSize(void)
24952495
{
24962496
Sizesize;
24972497

2498+
/* BackendStatusArray: */
24982499
size=mul_size(sizeof(PgBackendStatus),MaxBackends);
2500+
/* BackendAppnameBuffer: */
2501+
size=add_size(size,
2502+
mul_size(NAMEDATALEN,MaxBackends));
2503+
/* BackendClientHostnameBuffer: */
24992504
size=add_size(size,
25002505
mul_size(NAMEDATALEN,MaxBackends));
2506+
/* BackendActivityBuffer: */
25012507
size=add_size(size,
25022508
mul_size(pgstat_track_activity_query_size,MaxBackends));
2509+
#ifdefUSE_SSL
2510+
/* BackendSslStatusBuffer: */
25032511
size=add_size(size,
2504-
mul_size(NAMEDATALEN,MaxBackends));
2512+
mul_size(sizeof(PgBackendSSLStatus),MaxBackends));
2513+
#endif
25052514
returnsize;
25062515
}
25072516

@@ -2566,26 +2575,6 @@ CreateSharedBackendStatus(void)
25662575
}
25672576
}
25682577

2569-
#ifdefUSE_SSL
2570-
/* Create or attach to the shared SSL status buffer */
2571-
size=mul_size(sizeof(PgBackendSSLStatus),MaxBackends);
2572-
BackendSslStatusBuffer= (PgBackendSSLStatus*)
2573-
ShmemInitStruct("Backend SSL Status Buffer",size,&found);
2574-
2575-
if (!found)
2576-
{
2577-
MemSet(BackendSslStatusBuffer,0,size);
2578-
2579-
/* Initialize st_sslstatus pointers. */
2580-
buffer= (char*)BackendSslStatusBuffer;
2581-
for (i=0;i<MaxBackends;i++)
2582-
{
2583-
BackendStatusArray[i].st_sslstatus= (PgBackendSSLStatus*)buffer;
2584-
buffer+=sizeof(PgBackendSSLStatus);
2585-
}
2586-
}
2587-
#endif
2588-
25892578
/* Create or attach to the shared activity buffer */
25902579
BackendActivityBufferSize=mul_size(pgstat_track_activity_query_size,
25912580
MaxBackends);
@@ -2606,6 +2595,28 @@ CreateSharedBackendStatus(void)
26062595
buffer+=pgstat_track_activity_query_size;
26072596
}
26082597
}
2598+
2599+
#ifdefUSE_SSL
2600+
/* Create or attach to the shared SSL status buffer */
2601+
size=mul_size(sizeof(PgBackendSSLStatus),MaxBackends);
2602+
BackendSslStatusBuffer= (PgBackendSSLStatus*)
2603+
ShmemInitStruct("Backend SSL Status Buffer",size,&found);
2604+
2605+
if (!found)
2606+
{
2607+
PgBackendSSLStatus*ptr;
2608+
2609+
MemSet(BackendSslStatusBuffer,0,size);
2610+
2611+
/* Initialize st_sslstatus pointers. */
2612+
ptr=BackendSslStatusBuffer;
2613+
for (i=0;i<MaxBackends;i++)
2614+
{
2615+
BackendStatusArray[i].st_sslstatus=ptr;
2616+
ptr++;
2617+
}
2618+
}
2619+
#endif
26092620
}
26102621

26112622

@@ -2932,11 +2943,11 @@ pgstat_read_current_status(void)
29322943
volatilePgBackendStatus*beentry;
29332944
LocalPgBackendStatus*localtable;
29342945
LocalPgBackendStatus*localentry;
2946+
char*localappname,
2947+
*localactivity;
29352948
#ifdefUSE_SSL
29362949
PgBackendSSLStatus*localsslstatus;
29372950
#endif
2938-
char*localappname,
2939-
*localactivity;
29402951
inti;
29412952

29422953
Assert(!pgStatRunningInCollector);
@@ -2951,15 +2962,15 @@ pgstat_read_current_status(void)
29512962
localappname= (char*)
29522963
MemoryContextAlloc(pgStatLocalContext,
29532964
NAMEDATALEN*MaxBackends);
2965+
localactivity= (char*)
2966+
MemoryContextAlloc(pgStatLocalContext,
2967+
pgstat_track_activity_query_size*MaxBackends);
29542968
#ifdefUSE_SSL
29552969
localsslstatus= (PgBackendSSLStatus*)
29562970
MemoryContextAlloc(pgStatLocalContext,
29572971
sizeof(PgBackendSSLStatus)*MaxBackends);
29582972
#endif
29592973

2960-
localactivity= (char*)
2961-
MemoryContextAlloc(pgStatLocalContext,
2962-
pgstat_track_activity_query_size*MaxBackends);
29632974
localNumBackends=0;
29642975

29652976
beentry=BackendStatusArray;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp