wait-detect-invalid-custom-v0.patch
text/plain
Filename: wait-detect-invalid-custom-v0.patch
Type: text/plain
Part: 0
Message:
Re: race condition in pg_class
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v0
| File | + | − |
|---|---|---|
| src/backend/utils/activity/wait_event.c | 34 | 33 |
| src/tools/pgindent/typedefs.list | 1 | 1 |
diff --git a/src/backend/utils/activity/wait_event.c b/src/backend/utils/activity/wait_event.c
index 300de90..aaf9f3d 100644
--- a/src/backend/utils/activity/wait_event.c
+++ b/src/backend/utils/activity/wait_event.c
@@ -47,11 +47,11 @@ uint32 *my_wait_event_info = &local_my_wait_event_info;
* Hash tables for storing custom wait event ids and their names in
* shared memory.
*
- * WaitEventCustomHashById is used to find the name from an event id.
- * Any backend can search it to find custom wait events.
+ * WaitEventCustomHashByInfo is used to find the name from wait event
+ * information. Any backend can search it to find custom wait events.
*
- * WaitEventCustomHashByName is used to find the ID from a name.
- * It is used to ensure that no duplicated entries are registered.
+ * WaitEventCustomHashByName is used to find the wait event information from a
+ * name. It is used to ensure that no duplicated entries are registered.
*
* For simplicity, we use the same ID counter across types of custom events.
* We could end that anytime the need arises.
@@ -61,18 +61,18 @@ uint32 *my_wait_event_info = &local_my_wait_event_info;
* unlikely that the number of entries will reach
* WAIT_EVENT_CUSTOM_HASH_MAX_SIZE.
*/
-static HTAB *WaitEventCustomHashById; /* find names from IDs */
-static HTAB *WaitEventCustomHashByName; /* find IDs from names */
+static HTAB *WaitEventCustomHashByInfo; /* find names from infos */
+static HTAB *WaitEventCustomHashByName; /* find infos from names */
#define WAIT_EVENT_CUSTOM_HASH_INIT_SIZE 16
#define WAIT_EVENT_CUSTOM_HASH_MAX_SIZE 128
/* hash table entries */
-typedef struct WaitEventCustomEntryById
+typedef struct WaitEventCustomEntryByInfo
{
- uint16 event_id; /* hash key */
+ uint32 wait_event_info; /* hash key */
char wait_event_name[NAMEDATALEN]; /* custom wait event name */
-} WaitEventCustomEntryById;
+} WaitEventCustomEntryByInfo;
typedef struct WaitEventCustomEntryByName
{
@@ -95,7 +95,7 @@ static WaitEventCustomCounterData *WaitEventCustomCounter;
#define WAIT_EVENT_CUSTOM_INITIAL_ID 1
static uint32 WaitEventCustomNew(uint32 classId, const char *wait_event_name);
-static const char *GetWaitEventCustomIdentifier(uint16 eventId);
+static const char *GetWaitEventCustomIdentifier(uint32 wait_event_info);
/*
* Return the space for dynamic shared hash tables and dynamic allocation counter.
@@ -107,7 +107,7 @@ WaitEventCustomShmemSize(void)
sz = MAXALIGN(sizeof(WaitEventCustomCounterData));
sz = add_size(sz, hash_estimate_size(WAIT_EVENT_CUSTOM_HASH_MAX_SIZE,
- sizeof(WaitEventCustomEntryById)));
+ sizeof(WaitEventCustomEntryByInfo)));
sz = add_size(sz, hash_estimate_size(WAIT_EVENT_CUSTOM_HASH_MAX_SIZE,
sizeof(WaitEventCustomEntryByName)));
return sz;
@@ -134,13 +134,13 @@ WaitEventCustomShmemInit(void)
}
/* initialize or attach the hash tables to store custom wait events */
- info.keysize = sizeof(uint16);
- info.entrysize = sizeof(WaitEventCustomEntryById);
- WaitEventCustomHashById = ShmemInitHash("WaitEventCustom hash by id",
- WAIT_EVENT_CUSTOM_HASH_INIT_SIZE,
- WAIT_EVENT_CUSTOM_HASH_MAX_SIZE,
- &info,
- HASH_ELEM | HASH_BLOBS);
+ info.keysize = sizeof(uint32);
+ info.entrysize = sizeof(WaitEventCustomEntryByInfo);
+ WaitEventCustomHashByInfo = ShmemInitHash("WaitEventCustom hash by wait event information",
+ WAIT_EVENT_CUSTOM_HASH_INIT_SIZE,
+ WAIT_EVENT_CUSTOM_HASH_MAX_SIZE,
+ &info,
+ HASH_ELEM | HASH_BLOBS);
/* key is a NULL-terminated string */
info.keysize = sizeof(char[NAMEDATALEN]);
@@ -176,7 +176,7 @@ WaitEventCustomNew(uint32 classId, const char *wait_event_name)
uint16 eventId;
bool found;
WaitEventCustomEntryByName *entry_by_name;
- WaitEventCustomEntryById *entry_by_id;
+ WaitEventCustomEntryByInfo *entry_by_info;
uint32 wait_event_info;
/* Check the limit of the length of the event name */
@@ -249,18 +249,18 @@ WaitEventCustomNew(uint32 classId, const char *wait_event_name)
SpinLockRelease(&WaitEventCustomCounter->mutex);
/* Register the new wait event */
- entry_by_id = (WaitEventCustomEntryById *)
- hash_search(WaitEventCustomHashById, &eventId,
+ wait_event_info = classId | eventId;
+ entry_by_info = (WaitEventCustomEntryByInfo *)
+ hash_search(WaitEventCustomHashByInfo, &wait_event_info,
HASH_ENTER, &found);
Assert(!found);
- strlcpy(entry_by_id->wait_event_name, wait_event_name,
- sizeof(entry_by_id->wait_event_name));
+ strlcpy(entry_by_info->wait_event_name, wait_event_name,
+ sizeof(entry_by_info->wait_event_name));
entry_by_name = (WaitEventCustomEntryByName *)
hash_search(WaitEventCustomHashByName, wait_event_name,
HASH_ENTER, &found);
Assert(!found);
- wait_event_info = classId | eventId;
entry_by_name->wait_event_info = wait_event_info;
LWLockRelease(WaitEventCustomLock);
@@ -269,28 +269,29 @@ WaitEventCustomNew(uint32 classId, const char *wait_event_name)
}
/*
- * Return the name of a custom wait event ID.
+ * Return the name of a custom wait event information.
*/
static const char *
-GetWaitEventCustomIdentifier(uint16 eventId)
+GetWaitEventCustomIdentifier(uint32 wait_event_info)
{
bool found;
- WaitEventCustomEntryById *entry;
+ WaitEventCustomEntryByInfo *entry;
/* Built-in event? */
- if (eventId < WAIT_EVENT_CUSTOM_INITIAL_ID)
+ if (wait_event_info == PG_WAIT_EXTENSION)
return "Extension";
/* It is a user-defined wait event, so lookup hash table. */
LWLockAcquire(WaitEventCustomLock, LW_SHARED);
- entry = (WaitEventCustomEntryById *)
- hash_search(WaitEventCustomHashById, &eventId,
+ entry = (WaitEventCustomEntryByInfo *)
+ hash_search(WaitEventCustomHashByInfo, &wait_event_info,
HASH_FIND, &found);
LWLockRelease(WaitEventCustomLock);
if (!entry)
- elog(ERROR, "could not find custom wait event name for ID %u",
- eventId);
+ elog(ERROR,
+ "could not find custom name for wait event information %u",
+ wait_event_info);
return entry->wait_event_name;
}
@@ -449,7 +450,7 @@ pgstat_get_wait_event(uint32 wait_event_info)
break;
case PG_WAIT_EXTENSION:
case PG_WAIT_INJECTIONPOINT:
- event_name = GetWaitEventCustomIdentifier(eventId);
+ event_name = GetWaitEventCustomIdentifier(wait_event_info);
break;
case PG_WAIT_BUFFERPIN:
{
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 5696604..75433b3 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -3100,7 +3100,7 @@ WaitEventActivity
WaitEventBufferPin
WaitEventClient
WaitEventCustomCounterData
-WaitEventCustomEntryById
+WaitEventCustomEntryByInfo
WaitEventCustomEntryByName
WaitEventIO
WaitEventIPC