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

Commit2aeaf80

Browse files
committed
Refactor some code related to wait events "BufferPin" and "Extension"
The following changes are done:- Addition of WaitEventBufferPin and WaitEventExtension, that hold alist of wait events related to each category.- Addition of two functions that encapsulate the list of wait events foreach category.- Rename BUFFER_PIN to BUFFERPIN (only this wait event class used anunderscore, requiring a specific rule in the automation script).These changes make a bit easier the automatic generation of all the codeand documentation related to wait events, as all the wait eventcategories are now controlled by consistent structures and functions.Author: Bertrand DrouvotDiscussion:https://postgr.es/m/c6f35117-4b20-4c78-1df5-d3056010dcf5@gmail.comDiscussion:https://postgr.es/m/77a86b3a-c4a8-5f5d-69b9-d70bbf2e9b98@gmail.com
1 parent8c12838 commit2aeaf80

File tree

11 files changed

+93
-19
lines changed

11 files changed

+93
-19
lines changed

‎contrib/dblink/dblink.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ dblink_get_conn(char *conname_or_str,
203203
dblink_connstr_check(connstr);
204204

205205
/* OK to make connection */
206-
conn=libpqsrv_connect(connstr,PG_WAIT_EXTENSION);
206+
conn=libpqsrv_connect(connstr,WAIT_EVENT_EXTENSION);
207207

208208
if (PQstatus(conn)==CONNECTION_BAD)
209209
{
@@ -293,7 +293,7 @@ dblink_connect(PG_FUNCTION_ARGS)
293293
dblink_connstr_check(connstr);
294294

295295
/* OK to make connection */
296-
conn=libpqsrv_connect(connstr,PG_WAIT_EXTENSION);
296+
conn=libpqsrv_connect(connstr,WAIT_EVENT_EXTENSION);
297297

298298
if (PQstatus(conn)==CONNECTION_BAD)
299299
{

‎contrib/pg_prewarm/autoprewarm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ autoprewarm_main(Datum main_arg)
237237
(void)WaitLatch(MyLatch,
238238
WL_LATCH_SET |WL_EXIT_ON_PM_DEATH,
239239
-1L,
240-
PG_WAIT_EXTENSION);
240+
WAIT_EVENT_EXTENSION);
241241
}
242242
else
243243
{
@@ -264,7 +264,7 @@ autoprewarm_main(Datum main_arg)
264264
(void)WaitLatch(MyLatch,
265265
WL_LATCH_SET |WL_TIMEOUT |WL_EXIT_ON_PM_DEATH,
266266
delay_in_ms,
267-
PG_WAIT_EXTENSION);
267+
WAIT_EVENT_EXTENSION);
268268
}
269269

270270
/* Reset the latch, loop. */

‎contrib/postgres_fdw/connection.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
530530
/* OK to make connection */
531531
conn=libpqsrv_connect_params(keywords,values,
532532
false,/* expand_dbname */
533-
PG_WAIT_EXTENSION);
533+
WAIT_EVENT_EXTENSION);
534534

535535
if (!conn||PQstatus(conn)!=CONNECTION_OK)
536536
ereport(ERROR,
@@ -863,7 +863,7 @@ pgfdw_get_result(PGconn *conn, const char *query)
863863
WL_LATCH_SET |WL_SOCKET_READABLE |
864864
WL_EXIT_ON_PM_DEATH,
865865
PQsocket(conn),
866-
-1L,PG_WAIT_EXTENSION);
866+
-1L,WAIT_EVENT_EXTENSION);
867867
ResetLatch(MyLatch);
868868

869869
CHECK_FOR_INTERRUPTS();
@@ -1567,7 +1567,7 @@ pgfdw_get_cleanup_result(PGconn *conn, TimestampTz endtime, PGresult **result,
15671567
WL_LATCH_SET |WL_SOCKET_READABLE |
15681568
WL_TIMEOUT |WL_EXIT_ON_PM_DEATH,
15691569
PQsocket(conn),
1570-
cur_timeout,PG_WAIT_EXTENSION);
1570+
cur_timeout,WAIT_EVENT_EXTENSION);
15711571
ResetLatch(MyLatch);
15721572

15731573
CHECK_FOR_INTERRUPTS();

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4901,7 +4901,7 @@ LockBufferForCleanup(Buffer buffer)
49014901
SetStartupBufferPinWaitBufId(-1);
49024902
}
49034903
else
4904-
ProcWaitForSignal(PG_WAIT_BUFFER_PIN);
4904+
ProcWaitForSignal(WAIT_EVENT_BUFFER_PIN);
49054905

49064906
/*
49074907
* Remove flag marking us as waiter. Normally this will not be set

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ ResolveRecoveryConflictWithBufferPin(void)
840840
* SIGHUP signal handler, etc cannot do that because it uses the different
841841
* latch from that ProcWaitForSignal() waits on.
842842
*/
843-
ProcWaitForSignal(PG_WAIT_BUFFER_PIN);
843+
ProcWaitForSignal(WAIT_EVENT_BUFFER_PIN);
844844

845845
if (got_standby_delay_timeout)
846846
SendRecoveryConflictWithBufferPin(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);

‎src/backend/utils/activity/wait_event.c

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929

3030
staticconstchar*pgstat_get_wait_activity(WaitEventActivityw);
31+
staticconstchar*pgstat_get_wait_bufferpin(WaitEventBufferPinw);
3132
staticconstchar*pgstat_get_wait_client(WaitEventClientw);
33+
staticconstchar*pgstat_get_wait_extension(WaitEventExtensionw);
3234
staticconstchar*pgstat_get_wait_ipc(WaitEventIPCw);
3335
staticconstchar*pgstat_get_wait_timeout(WaitEventTimeoutw);
3436
staticconstchar*pgstat_get_wait_io(WaitEventIOw);
@@ -90,7 +92,7 @@ pgstat_get_wait_event_type(uint32 wait_event_info)
9092
casePG_WAIT_LOCK:
9193
event_type="Lock";
9294
break;
93-
casePG_WAIT_BUFFER_PIN:
95+
casePG_WAIT_BUFFERPIN:
9496
event_type="BufferPin";
9597
break;
9698
casePG_WAIT_ACTIVITY:
@@ -147,9 +149,13 @@ pgstat_get_wait_event(uint32 wait_event_info)
147149
casePG_WAIT_LOCK:
148150
event_name=GetLockNameFromTagType(eventId);
149151
break;
150-
casePG_WAIT_BUFFER_PIN:
151-
event_name="BufferPin";
152-
break;
152+
casePG_WAIT_BUFFERPIN:
153+
{
154+
WaitEventBufferPinw= (WaitEventBufferPin)wait_event_info;
155+
156+
event_name=pgstat_get_wait_bufferpin(w);
157+
break;
158+
}
153159
casePG_WAIT_ACTIVITY:
154160
{
155161
WaitEventActivityw= (WaitEventActivity)wait_event_info;
@@ -165,8 +171,12 @@ pgstat_get_wait_event(uint32 wait_event_info)
165171
break;
166172
}
167173
casePG_WAIT_EXTENSION:
168-
event_name="Extension";
169-
break;
174+
{
175+
WaitEventExtensionw= (WaitEventExtension)wait_event_info;
176+
177+
event_name=pgstat_get_wait_extension(w);
178+
break;
179+
}
170180
casePG_WAIT_IPC:
171181
{
172182
WaitEventIPCw= (WaitEventIPC)wait_event_info;
@@ -254,6 +264,28 @@ pgstat_get_wait_activity(WaitEventActivity w)
254264
returnevent_name;
255265
}
256266

267+
/* ----------
268+
* pgstat_get_wait_bufferpin() -
269+
*
270+
* Convert WaitEventBufferPin to string.
271+
* ----------
272+
*/
273+
staticconstchar*
274+
pgstat_get_wait_bufferpin(WaitEventBufferPinw)
275+
{
276+
constchar*event_name="unknown wait event";
277+
278+
switch (w)
279+
{
280+
caseWAIT_EVENT_BUFFER_PIN:
281+
event_name="BufferPin";
282+
break;
283+
/* no default case, so that compiler will warn */
284+
}
285+
286+
returnevent_name;
287+
}
288+
257289
/* ----------
258290
* pgstat_get_wait_client() -
259291
*
@@ -297,6 +329,28 @@ pgstat_get_wait_client(WaitEventClient w)
297329
returnevent_name;
298330
}
299331

332+
/* ----------
333+
* pgstat_get_wait_extension() -
334+
*
335+
* Convert WaitEventExtension to string.
336+
* ----------
337+
*/
338+
staticconstchar*
339+
pgstat_get_wait_extension(WaitEventExtensionw)
340+
{
341+
constchar*event_name="unknown wait event";
342+
343+
switch (w)
344+
{
345+
caseWAIT_EVENT_EXTENSION:
346+
event_name="Extension";
347+
break;
348+
/* no default case, so that compiler will warn */
349+
}
350+
351+
returnevent_name;
352+
}
353+
300354
/* ----------
301355
* pgstat_get_wait_ipc() -
302356
*

‎src/include/utils/wait_event.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
#definePG_WAIT_LWLOCK0x01000000U
1919
#definePG_WAIT_LOCK0x03000000U
20-
#definePG_WAIT_BUFFER_PIN0x04000000U
20+
#definePG_WAIT_BUFFERPIN0x04000000U
2121
#definePG_WAIT_ACTIVITY0x05000000U
2222
#definePG_WAIT_CLIENT0x06000000U
2323
#definePG_WAIT_EXTENSION0x07000000U
@@ -50,6 +50,15 @@ typedef enum
5050
WAIT_EVENT_WAL_WRITER_MAIN
5151
}WaitEventActivity;
5252

53+
/* ----------
54+
* Wait Events - BUFFERPIN
55+
* ----------
56+
*/
57+
typedefenum
58+
{
59+
WAIT_EVENT_BUFFER_PIN=PG_WAIT_BUFFERPIN
60+
}WaitEventBufferPin;
61+
5362
/* ----------
5463
* Wait Events - Client
5564
*
@@ -70,6 +79,15 @@ typedef enum
7079
WAIT_EVENT_WAL_SENDER_WRITE_DATA,
7180
}WaitEventClient;
7281

82+
/* ----------
83+
* Wait Events - EXTENSION
84+
* ----------
85+
*/
86+
typedefenum
87+
{
88+
WAIT_EVENT_EXTENSION=PG_WAIT_EXTENSION
89+
}WaitEventExtension;
90+
7391
/* ----------
7492
* Wait Events - IPC
7593
*

‎src/test/modules/test_shm_mq/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ wait_for_workers_to_become_ready(worker_state *wstate,
280280

281281
/* Wait to be signaled. */
282282
(void)WaitLatch(MyLatch,WL_LATCH_SET |WL_EXIT_ON_PM_DEATH,0,
283-
PG_WAIT_EXTENSION);
283+
WAIT_EVENT_EXTENSION);
284284

285285
/* Reset the latch so we don't spin. */
286286
ResetLatch(MyLatch);

‎src/test/modules/test_shm_mq/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
232232
* for us to do.
233233
*/
234234
(void)WaitLatch(MyLatch,WL_LATCH_SET |WL_EXIT_ON_PM_DEATH,0,
235-
PG_WAIT_EXTENSION);
235+
WAIT_EVENT_EXTENSION);
236236
ResetLatch(MyLatch);
237237
CHECK_FOR_INTERRUPTS();
238238
}

‎src/test/modules/worker_spi/worker_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ worker_spi_main(Datum main_arg)
199199
(void)WaitLatch(MyLatch,
200200
WL_LATCH_SET |WL_TIMEOUT |WL_EXIT_ON_PM_DEATH,
201201
worker_spi_naptime*1000L,
202-
PG_WAIT_EXTENSION);
202+
WAIT_EVENT_EXTENSION);
203203
ResetLatch(MyLatch);
204204

205205
CHECK_FOR_INTERRUPTS();

‎src/tools/pgindent/typedefs.list

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,7 +2986,9 @@ WSANETWORKEVENTS
29862986
WSAPROTOCOL_INFO
29872987
WaitEvent
29882988
WaitEventActivity
2989+
WaitEventBufferPin
29892990
WaitEventClient
2991+
WaitEventExtension
29902992
WaitEventIO
29912993
WaitEventIPC
29922994
WaitEventSet

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp