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

Commita7ef273

Browse files
committed
Fix calculation of maximum statistics-message size.
The PGSTAT_NUM_TABENTRIES macro should have been updated when new fieldswere added to struct PgStat_MsgTabstat in commit6448289, but it wasn't.Fix that.Also, add a static assertion that we didn't overrun the intended size limiton stats messages. This will not necessarily catch every mistake incomputing the maximum array size for stats messages, but it will catch onesthat have practical consequences. (The assertion in fact doesn't complainabout the aforementioned error in PGSTAT_NUM_TABENTRIES, because that wasnot big enough to cause the array length to increase.)No back-patch, as there's no actual bug in existing releases; this is justin the nature of future-proofing.Mark Dilger and Tom Lane
1 parent638cf09 commita7ef273

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ pgstat_init(void)
329329

330330
#defineTESTBYTEVAL ((char) 199)
331331

332+
/*
333+
* This static assertion verifies that we didn't mess up the calculations
334+
* involved in selecting maximum payload sizes for our UDP messages.
335+
* Because the only consequence of overrunning PGSTAT_MAX_MSG_SIZE would
336+
* be silent performance loss from fragmentation, it seems worth having a
337+
* compile-time cross-check that we didn't.
338+
*/
339+
StaticAssertStmt(sizeof(PgStat_Msg) <=PGSTAT_MAX_MSG_SIZE,
340+
'maximum stats message size exceeds PGSTAT_MAX_MSG_SIZE');
341+
332342
/*
333343
* Create the UDP socket for sending and receiving statistic messages
334344
*/

‎src/include/pgstat.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,13 @@ typedef struct PgStat_MsgHdr
177177

178178
/* ----------
179179
* Space available in a message. This will keep the UDP packets below 1K,
180-
* which should fit unfragmented into the MTU of the lo interface on most
181-
* platforms. Does anybody care for platforms where it doesn't?
180+
* which should fit unfragmented into the MTU of the loopback interface.
181+
* (Larger values of PGSTAT_MAX_MSG_SIZE would work for that on most
182+
* platforms, but we're being conservative here.)
182183
* ----------
183184
*/
184-
#definePGSTAT_MSG_PAYLOAD(1000 - sizeof(PgStat_MsgHdr))
185+
#definePGSTAT_MAX_MSG_SIZE 1000
186+
#definePGSTAT_MSG_PAYLOAD(PGSTAT_MAX_MSG_SIZE - sizeof(PgStat_MsgHdr))
185187

186188

187189
/* ----------
@@ -225,7 +227,7 @@ typedef struct PgStat_TableEntry
225227
* ----------
226228
*/
227229
#definePGSTAT_NUM_TABENTRIES \
228-
((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - 3 * sizeof(int))\
230+
((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - 3 * sizeof(int) - 2 * sizeof(PgStat_Counter))\
229231
/ sizeof(PgStat_TableEntry))
230232

231233
typedefstructPgStat_MsgTabstat

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp