While working on the new shmem allocation functions, I looked at how the
NamedLWLockTranche stuff works now in lwlock.c, and I have to say it's a
bit of a mess.
What is a "named tranche"? It usually means tranches requested with
RequestNamedLWLockTranche() at postmaster startup. But all tranches have
a name. LWLockTrancheNames includes all user-defined tranches, also ones
assigned with LWLockNewTrancheId(), and MAX_NAMED_TRANCHES is the
maximum for all of them.
At postmaster startup, NamedLWLockTrancheRequests points to a
backend-private array. But after startup, and always in backends, it
points to a copy in shared memory and
LocalNamedLWLockTrancheRequestArray is used to hold the original. It
took me a while to realize that NamedLWLockTrancheRequests in shared
memory is *not* updated when you call LWLockNewTrancheId(), it only
holds the requests made with RequestNamedLWLockTranche() before startup.
I propose the attached refactorings to make this less confusing. See
commit messages for details.
- Heikki