Skip to content

Navigation Menu

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

Appearance settings

Commit 2aeaf80

Browse filesBrowse files
committed
Refactor some code related to wait events "BufferPin" and "Extension"
The following changes are done: - Addition of WaitEventBufferPin and WaitEventExtension, that hold a list of wait events related to each category. - Addition of two functions that encapsulate the list of wait events for each category. - Rename BUFFER_PIN to BUFFERPIN (only this wait event class used an underscore, requiring a specific rule in the automation script). These changes make a bit easier the automatic generation of all the code and documentation related to wait events, as all the wait event categories are now controlled by consistent structures and functions. Author: Bertrand Drouvot Discussion: https://postgr.es/m/c6f35117-4b20-4c78-1df5-d3056010dcf5@gmail.com Discussion: https://postgr.es/m/77a86b3a-c4a8-5f5d-69b9-d70bbf2e9b98@gmail.com
1 parent 8c12838 commit 2aeaf80
Copy full SHA for 2aeaf80

File tree

11 files changed

+93
-19
lines changed
Filter options

11 files changed

+93
-19
lines changed

‎contrib/dblink/dblink.c

Copy file name to clipboardExpand all lines: contrib/dblink/dblink.c
+2-2Lines 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

Copy file name to clipboardExpand all lines: contrib/pg_prewarm/autoprewarm.c
+2-2Lines 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

Copy file name to clipboardExpand all lines: contrib/postgres_fdw/connection.c
+3-3Lines 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

Copy file name to clipboardExpand all lines: src/backend/storage/buffer/bufmgr.c
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/backend/storage/ipc/standby.c
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/backend/utils/activity/wait_event.c
+60-6Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929

3030
static const char *pgstat_get_wait_activity(WaitEventActivity w);
31+
static const char *pgstat_get_wait_bufferpin(WaitEventBufferPin w);
3132
static const char *pgstat_get_wait_client(WaitEventClient w);
33+
static const char *pgstat_get_wait_extension(WaitEventExtension w);
3234
static const char *pgstat_get_wait_ipc(WaitEventIPC w);
3335
static const char *pgstat_get_wait_timeout(WaitEventTimeout w);
3436
static const char *pgstat_get_wait_io(WaitEventIO w);
@@ -90,7 +92,7 @@ pgstat_get_wait_event_type(uint32 wait_event_info)
9092
case PG_WAIT_LOCK:
9193
event_type = "Lock";
9294
break;
93-
case PG_WAIT_BUFFER_PIN:
95+
case PG_WAIT_BUFFERPIN:
9496
event_type = "BufferPin";
9597
break;
9698
case PG_WAIT_ACTIVITY:
@@ -147,9 +149,13 @@ pgstat_get_wait_event(uint32 wait_event_info)
147149
case PG_WAIT_LOCK:
148150
event_name = GetLockNameFromTagType(eventId);
149151
break;
150-
case PG_WAIT_BUFFER_PIN:
151-
event_name = "BufferPin";
152-
break;
152+
case PG_WAIT_BUFFERPIN:
153+
{
154+
WaitEventBufferPin w = (WaitEventBufferPin) wait_event_info;
155+
156+
event_name = pgstat_get_wait_bufferpin(w);
157+
break;
158+
}
153159
case PG_WAIT_ACTIVITY:
154160
{
155161
WaitEventActivity w = (WaitEventActivity) wait_event_info;
@@ -165,8 +171,12 @@ pgstat_get_wait_event(uint32 wait_event_info)
165171
break;
166172
}
167173
case PG_WAIT_EXTENSION:
168-
event_name = "Extension";
169-
break;
174+
{
175+
WaitEventExtension w = (WaitEventExtension) wait_event_info;
176+
177+
event_name = pgstat_get_wait_extension(w);
178+
break;
179+
}
170180
case PG_WAIT_IPC:
171181
{
172182
WaitEventIPC w = (WaitEventIPC) wait_event_info;
@@ -254,6 +264,28 @@ pgstat_get_wait_activity(WaitEventActivity w)
254264
return event_name;
255265
}
256266

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

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

‎src/include/utils/wait_event.h

Copy file name to clipboardExpand all lines: src/include/utils/wait_event.h
+19-1Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
#define PG_WAIT_LWLOCK 0x01000000U
1919
#define PG_WAIT_LOCK 0x03000000U
20-
#define PG_WAIT_BUFFER_PIN 0x04000000U
20+
#define PG_WAIT_BUFFERPIN 0x04000000U
2121
#define PG_WAIT_ACTIVITY 0x05000000U
2222
#define PG_WAIT_CLIENT 0x06000000U
2323
#define PG_WAIT_EXTENSION 0x07000000U
@@ -50,6 +50,15 @@ typedef enum
5050
WAIT_EVENT_WAL_WRITER_MAIN
5151
} WaitEventActivity;
5252

53+
/* ----------
54+
* Wait Events - BUFFERPIN
55+
* ----------
56+
*/
57+
typedef enum
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+
typedef enum
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

Copy file name to clipboardExpand all lines: src/test/modules/test_shm_mq/setup.c
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/test/modules/test_shm_mq/test.c
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/test/modules/worker_spi/worker_spi.c
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/tools/pgindent/typedefs.list
+2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.