Re: Improve LWLock tranche name visibility across backends

From: Sami Imseih <samimseih(at)gmail(dot)com>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)anarazel(dot)de>, Rahila Syed <rahilasyed90(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Improve LWLock tranche name visibility across backends
Date: 2025-08-27 19:13:39
Message-ID: CAA5RZ0ve-fHuNYW-ruMwg1y1v7-aCqMm_MiNq1KOdg2Y2-pKDw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks for reviewing!

> === 1
>
> We need to check if tranche_name is NULL and report an error if that's the case.
> If not, strlen() would segfault.

Added an error. Good call. The error message follows previously used
convention.

```
+ if (!tranche_name)
+ elog(ERROR, "tranche name cannot be null");
```

> === 2
>
> + if (tranche_name_length > MAX_NAMED_TRANCHES_NAME_LEN)
> + elog(ERROR, "tranche name too long");
>
> I think that we should mention in the doc that the tranche name is limited to
> 63 bytes.

Done. I just mentioned NAMEDATALEN -1 in the docs.

> === 3
>
> I was skeptical about using strcpy() while we hold a spinlock. I do see some
> examples with strlcpy() though (walreceiver.c for example), so that looks OK-ish.
>
> Using strcpy() might be OK too, as we already have validated the length, but maybe
> it would be safer to switch to strlcpy(), instead?

OK, since that is the pattern used, I changed to strlcpy. But since we are doing
checks in advance, I think it will be safe either way.

--
Sami

Attachment Content-Type Size
v14-0003-Remove-the-DSA-suffix-for-tranches-created-with-.patch application/octet-stream 3.5 KB
v14-0001-Improve-LWLock-tranche-registration.patch application/octet-stream 25.5 KB
v14-0002-Tests-for-LWLock-tranche-registration-improvemen.patch application/octet-stream 13.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2025-08-27 19:14:41 Re: Buffer locking is special (hints, checksums, AIO writes)
Previous Message Melanie Plageman 2025-08-27 19:08:41 Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)