Re: Improve LWLock tranche name visibility across backends - Mailing list pgsql-hackers

From Sami Imseih
Subject Re: Improve LWLock tranche name visibility across backends
Date
Msg-id CAA5RZ0tm6UFuY43-=fB-JtDEten3gA6tMCH1zLv+R9FT=MDApg@mail.gmail.com
Whole thread Raw
In response to Re: Improve LWLock tranche name visibility across backends  (Bertrand Drouvot <bertranddrouvot.pg@gmail.com>)
Responses Re: Improve LWLock tranche name visibility across backends
List pgsql-hackers
> So we could do something like:
>
> int i = 0;
> while (i < LWLockTrancheNames.shmem->allocated &&
>            !DsaPointerIsValid(shared_ptrs[i]))
> {
>         i++;
> }

I found a different approach without tracking an additional counter.
Then sync stops when an invalid pointer is found after at least
one valid entry in shared memory, so we don't stop if there was a
lwlock registered in local memory during postmaster startup, and
this tranche will never actually be added to shared memory at
the same position.

>> Is there any reason to continue allowing this?  For example, maybe we could
>> ERROR if LWLockInitialize()/GetLWTrancheName() are given a tranche_id
>> greater than the number allocated.  I guess I'm not following why we should
>> gracefully handle these kinds of coding errors, especially when they result
>> in unhelpful behavior like an "extension" tranche.

> Essentially, we can call GetLWTrancheName within LWLockInitialize, but
> GetLWTrancheName can no longer have a fallback value such as "extension".
> It should error out instead. I believe that is what you mean. correct?

I also added this, so now only LWLocks correctly registered can be looked
up.

I also reconsidered the use of INJECTION_POINT for this purpose.
I felt it added unnecessary code where we only need a DEBUG ( I used DEBUG3)
statement at a few key places.

See v7.

--
Sami

Attachment

pgsql-hackers by date:

Previous
From: Marthin Laubscher
Date:
Subject: Re: About Custom Aggregates, C Extensions and Memory
Next
From: Tom Lane
Date:
Subject: Re: About Custom Aggregates, C Extensions and Memory