Re: Improve LWLock tranche name visibility across backends
Sami Imseih <samimseih@gmail.com>
From: Sami Imseih <samimseih@gmail.com>
To: Nathan Bossart <nathandbossart@gmail.com>
Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-08-05T03:47:45Z
Lists: pgsql-hackers
Attachments
- v4-0001-Implement-a-DSA-for-LWLock-tranche-names.patch (application/octet-stream) patch v4-0001
> > > With a local hash table, I don't think it's necessary to introduce new > > > code for managing > > > a DSA based list of tranche names as is done in v3. We can go back to > > > storing the shared > > > trance names in dshash. > > > > > > What do you think? > > > > My first thought is that a per-backend hash table seems too > > expensive/complicated for this. Couldn't it just be an array like we have > > now? > > We can, but I was considering simplicity of implementation, and using a > local hash table is slightly simpler. > > That said, since we're dealing with an append-only data structure, a hash > table is probably more than we need. All we need is index-based lookup, > so I’ll go with the local array to mirror the shared ( dsa ) array. Here is v4. We can keep using the local array as the backend local array. It will already include the tranches registered during postmaster startup, and it will be updated during tranche name lookup from the dsa based array. I added a new routine UpdateLocalTrancheName which can be used in both LWLockRegisterTranche and GetLWTrancheName to append to the local tranche during both postmaster startup and afterwards. Also, initially I thought we can get rid of returning the "extension" wait event name, but it's still possible for an "extension" tranche name to be returned if LWLockInitialize is called with a tranche_id that was never registered with LWLockNewTrancheId. We don't prevent that, and I can't see how we can without changing the LWLockInitialize API, but it is something that should probably be improved. For now, I added a mention of this behavior in the documentation. This is existing behavior, so I could also separate this doc change into a separate patch if it makes more sense to do so. -- Sami
Commits
-
test_dsa: Avoid leaking LWLock tranches.
- c5c74282f2ea 19 (unreleased) landed
-
Teach DSM registry to ERROR if attaching to an uninitialized entry.
- b26d76f64327 18.2 landed
- ac2800ddc185 17.8 landed
- 1165a933aab1 19 (unreleased) landed
-
Add a test harness for the LWLock tranche code.
- 16607718c010 19 (unreleased) landed
-
Revert recent change to RequestNamedLWLockTranche().
- d814d7fc3d52 19 (unreleased) landed
-
Move dynamically-allocated LWLock tranche names to shared memory.
- 38b602b0289f 19 (unreleased) landed
-
Prepare DSM registry for upcoming changes to LWLock tranche names.
- 5487058b56e0 19 (unreleased) landed
-
Add GetNamedDSA() and GetNamedDSHash().
- fe07100e82b0 19 (unreleased) cited