Re: Improve LWLock tranche name visibility across backends

From: Sami Imseih <samimseih(at)gmail(dot)com>
To: Rahila Syed <rahilasyed90(at)gmail(dot)com>, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Improve LWLock tranche name visibility across backends
Date: 2025-08-12 03:28:07
Message-ID: CAA5RZ0siw2MrVjf9iPYRpe8sgZW+TJRqmxKfCr=QS9mX+ZF8Lw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Attached v6 which addresses the feedback from the last review.

1/ Rahila raised a point about the necessity to allocate new dsa pointers
for tranche names when copying ( during resize). That is correct. We can simply
memcpy those dsa pointers at the time of copy. All we need to
do is free the dsa pointer that tracks the list.

2/ I also implemented a full sync of the local cache when necessary.
That is the tranche name is not found locally and the tranche index is
not higher than the max used index. To do that we do have to track the
highest index used as the allocated counter is not sufficient to do this.
Allocation will grow geometrically to avoid resize operations.

3/ I also added tests using INJECTION_POINTS. Although the same tests
could be done with DEBUG, I felt INJECTION_POINTS
are better to use for this purpose to avoid unnecessary logging.
I created a test module called test_lwlock_tranches which has
a perl test because we do need to set shared_preload_libraries.

I did have to define the following in wait_classes.h:

+#define WAIT_EVENT_CLASS_MASK 0xFF000000
+#define WAIT_EVENT_ID_MASK 0x0000FFFF

This is because the extension calls
GetLWLockIdentifier ( to mimic pg_stat_activity) and
needs to calculate a classId.

--
Sami

Attachment Content-Type Size
v6-0001-Implement-a-DSA-for-LWLock-tranche-names.patch application/octet-stream 47.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sandino Araico Sánchez 2025-08-12 03:31:06 Re: Proposal to adjust typmod argument on base UDT input functions
Previous Message Fujii Masao 2025-08-12 03:22:11 Excessive LOG messages from replication slot sync worker