Re: Improve LWLock tranche name visibility across backends

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

Hi,

I've begun reviewing this patch and have a few questions listed below:

1. + if (i < LWLockTrancheNames.shmem->allocated &&
DsaPointerIsValid(old_ptrs[i]))

Should an assert be used for the second condition instead?
Since for i < LWLockTrancheNames.shmem->allocated, the dsa pointer is
expected to be valid.

2. copied_ptr =
dsa_allocate(LWLockTrancheNames.dsa, len);
+
+ copied_addr =
dsa_get_address(LWLockTrancheNames.dsa, copied_ptr);
+ memcpy(copied_addr, old_name, len);
+
+ new_ptrs[i] = copied_ptr;
+
+ /* free old tranche names */
+ dsa_free(LWLockTrancheNames.dsa,
old_ptrs[i]);

Why is it necessary to allocate a new dsa_pointer for tranche names that
are the same size and then
free the old one?
Is there a reason we can't just assign new_ptrs[i] = old_ptrs[i]?

3.
>Additionally, while users should not pass arbitrary tranche IDs (that is,
>IDs not created via LWLockNewTrancheId) to LWLockInitialize, nothing
>technically prevents them from doing so. Therefore, we must continue to
>handle such cases gracefully by returning a default "extension" tranche
name.

Would it be possible to update LWLockInitialize so that it checks if
tranche_id is
already registered in the dsa, and if not, registers it during the
LWLockInitialize() process?

Thank you,
Rahila Syed

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message 厉超 2025-08-06 12:07:13 Re: Re: Enhance Makefiles to rebuild objects on map file changes
Previous Message Etsuro Fujita 2025-08-06 11:25:12 Re: [(known) BUG] DELETE/UPDATE more than one row in partitioned foreign table