aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-07-03 11:01:02 +0900
committerMichael Paquier <michael@paquier.xyz>2023-07-03 11:01:02 +0900
commit2aeaf80e578ed48af88d54caf2ffcf7ca62617e8 (patch)
treea322df445b8663e7e6dbbaa970ae856d40d36902 /src
parent8c12838001c2d974d3608fe55c228f601818a729 (diff)
downloadpostgresql-2aeaf80e578ed48af88d54caf2ffcf7ca62617e8.tar.gz
postgresql-2aeaf80e578ed48af88d54caf2ffcf7ca62617e8.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/buffer/bufmgr.c2
-rw-r--r--src/backend/storage/ipc/standby.c2
-rw-r--r--src/backend/utils/activity/wait_event.c66
-rw-r--r--src/include/utils/wait_event.h20
-rw-r--r--src/test/modules/test_shm_mq/setup.c2
-rw-r--r--src/test/modules/test_shm_mq/test.c2
-rw-r--r--src/test/modules/worker_spi/worker_spi.c2
-rw-r--r--src/tools/pgindent/typedefs.list2
8 files changed, 86 insertions, 12 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 3c59bbd04ea..a7e3b9bb1d3 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -4901,7 +4901,7 @@ LockBufferForCleanup(Buffer buffer)
SetStartupBufferPinWaitBufId(-1);
}
else
- ProcWaitForSignal(PG_WAIT_BUFFER_PIN);
+ ProcWaitForSignal(WAIT_EVENT_BUFFER_PIN);
/*
* Remove flag marking us as waiter. Normally this will not be set
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index 4c06741a69f..cc22d2e87cc 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -840,7 +840,7 @@ ResolveRecoveryConflictWithBufferPin(void)
* SIGHUP signal handler, etc cannot do that because it uses the different
* latch from that ProcWaitForSignal() waits on.
*/
- ProcWaitForSignal(PG_WAIT_BUFFER_PIN);
+ ProcWaitForSignal(WAIT_EVENT_BUFFER_PIN);
if (got_standby_delay_timeout)
SendRecoveryConflictWithBufferPin(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
diff --git a/src/backend/utils/activity/wait_event.c b/src/backend/utils/activity/wait_event.c
index 7940d646392..8572cf169ea 100644
--- a/src/backend/utils/activity/wait_event.c
+++ b/src/backend/utils/activity/wait_event.c
@@ -28,7 +28,9 @@
static const char *pgstat_get_wait_activity(WaitEventActivity w);
+static const char *pgstat_get_wait_bufferpin(WaitEventBufferPin w);
static const char *pgstat_get_wait_client(WaitEventClient w);
+static const char *pgstat_get_wait_extension(WaitEventExtension w);
static const char *pgstat_get_wait_ipc(WaitEventIPC w);
static const char *pgstat_get_wait_timeout(WaitEventTimeout w);
static const char *pgstat_get_wait_io(WaitEventIO w);
@@ -90,7 +92,7 @@ pgstat_get_wait_event_type(uint32 wait_event_info)
case PG_WAIT_LOCK:
event_type = "Lock";
break;
- case PG_WAIT_BUFFER_PIN:
+ case PG_WAIT_BUFFERPIN:
event_type = "BufferPin";
break;
case PG_WAIT_ACTIVITY:
@@ -147,9 +149,13 @@ pgstat_get_wait_event(uint32 wait_event_info)
case PG_WAIT_LOCK:
event_name = GetLockNameFromTagType(eventId);
break;
- case PG_WAIT_BUFFER_PIN:
- event_name = "BufferPin";
- break;
+ case PG_WAIT_BUFFERPIN:
+ {
+ WaitEventBufferPin w = (WaitEventBufferPin) wait_event_info;
+
+ event_name = pgstat_get_wait_bufferpin(w);
+ break;
+ }
case PG_WAIT_ACTIVITY:
{
WaitEventActivity w = (WaitEventActivity) wait_event_info;
@@ -165,8 +171,12 @@ pgstat_get_wait_event(uint32 wait_event_info)
break;
}
case PG_WAIT_EXTENSION:
- event_name = "Extension";
- break;
+ {
+ WaitEventExtension w = (WaitEventExtension) wait_event_info;
+
+ event_name = pgstat_get_wait_extension(w);
+ break;
+ }
case PG_WAIT_IPC:
{
WaitEventIPC w = (WaitEventIPC) wait_event_info;
@@ -255,6 +265,28 @@ pgstat_get_wait_activity(WaitEventActivity w)
}
/* ----------
+ * pgstat_get_wait_bufferpin() -
+ *
+ * Convert WaitEventBufferPin to string.
+ * ----------
+ */
+static const char *
+pgstat_get_wait_bufferpin(WaitEventBufferPin w)
+{
+ const char *event_name = "unknown wait event";
+
+ switch (w)
+ {
+ case WAIT_EVENT_BUFFER_PIN:
+ event_name = "BufferPin";
+ break;
+ /* no default case, so that compiler will warn */
+ }
+
+ return event_name;
+}
+
+/* ----------
* pgstat_get_wait_client() -
*
* Convert WaitEventClient to string.
@@ -298,6 +330,28 @@ pgstat_get_wait_client(WaitEventClient w)
}
/* ----------
+ * pgstat_get_wait_extension() -
+ *
+ * Convert WaitEventExtension to string.
+ * ----------
+ */
+static const char *
+pgstat_get_wait_extension(WaitEventExtension w)
+{
+ const char *event_name = "unknown wait event";
+
+ switch (w)
+ {
+ case WAIT_EVENT_EXTENSION:
+ event_name = "Extension";
+ break;
+ /* no default case, so that compiler will warn */
+ }
+
+ return event_name;
+}
+
+/* ----------
* pgstat_get_wait_ipc() -
*
* Convert WaitEventIPC to string.
diff --git a/src/include/utils/wait_event.h b/src/include/utils/wait_event.h
index 518d3b0a1f7..dc01d4e84df 100644
--- a/src/include/utils/wait_event.h
+++ b/src/include/utils/wait_event.h
@@ -17,7 +17,7 @@
*/
#define PG_WAIT_LWLOCK 0x01000000U
#define PG_WAIT_LOCK 0x03000000U
-#define PG_WAIT_BUFFER_PIN 0x04000000U
+#define PG_WAIT_BUFFERPIN 0x04000000U
#define PG_WAIT_ACTIVITY 0x05000000U
#define PG_WAIT_CLIENT 0x06000000U
#define PG_WAIT_EXTENSION 0x07000000U
@@ -51,6 +51,15 @@ typedef enum
} WaitEventActivity;
/* ----------
+ * Wait Events - BUFFERPIN
+ * ----------
+ */
+typedef enum
+{
+ WAIT_EVENT_BUFFER_PIN = PG_WAIT_BUFFERPIN
+} WaitEventBufferPin;
+
+/* ----------
* Wait Events - Client
*
* Use this category when a process is waiting to send data to or receive data
@@ -71,6 +80,15 @@ typedef enum
} WaitEventClient;
/* ----------
+ * Wait Events - EXTENSION
+ * ----------
+ */
+typedef enum
+{
+ WAIT_EVENT_EXTENSION = PG_WAIT_EXTENSION
+} WaitEventExtension;
+
+/* ----------
* Wait Events - IPC
*
* Use this category when a process cannot complete the work it is doing because
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index bec5732e873..192e5cc2ab4 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -280,7 +280,7 @@ wait_for_workers_to_become_ready(worker_state *wstate,
/* Wait to be signaled. */
(void) WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0,
- PG_WAIT_EXTENSION);
+ WAIT_EVENT_EXTENSION);
/* Reset the latch so we don't spin. */
ResetLatch(MyLatch);
diff --git a/src/test/modules/test_shm_mq/test.c b/src/test/modules/test_shm_mq/test.c
index 906e943e2d9..d9be7033502 100644
--- a/src/test/modules/test_shm_mq/test.c
+++ b/src/test/modules/test_shm_mq/test.c
@@ -232,7 +232,7 @@ test_shm_mq_pipelined(PG_FUNCTION_ARGS)
* for us to do.
*/
(void) WaitLatch(MyLatch, WL_LATCH_SET | WL_EXIT_ON_PM_DEATH, 0,
- PG_WAIT_EXTENSION);
+ WAIT_EVENT_EXTENSION);
ResetLatch(MyLatch);
CHECK_FOR_INTERRUPTS();
}
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index ad491d77229..7227cfaa45c 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -199,7 +199,7 @@ worker_spi_main(Datum main_arg)
(void) WaitLatch(MyLatch,
WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
worker_spi_naptime * 1000L,
- PG_WAIT_EXTENSION);
+ WAIT_EVENT_EXTENSION);
ResetLatch(MyLatch);
CHECK_FOR_INTERRUPTS();
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 260854747b4..e941fb6c82f 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -2986,7 +2986,9 @@ WSANETWORKEVENTS
WSAPROTOCOL_INFO
WaitEvent
WaitEventActivity
+WaitEventBufferPin
WaitEventClient
+WaitEventExtension
WaitEventIO
WaitEventIPC
WaitEventSet