Re: Proposal: Add a callback data parameter to GetNamedDSMSegment

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Sami Imseih <samimseih(at)gmail(dot)com>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Proposal: Add a callback data parameter to GetNamedDSMSegment
Date: 2025-12-12 21:07:04
Message-ID: CAN4CZFPJazcr-J3Kk=BLswYdc+nbkaxEfVvAL=7JCZECaQqAyQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> fair point. In that case why don't we just keep:

I did something similar, but using a simple pointer comparison instead
of strings, to avoid a warning about discarding const qualifiers.

What do you think about this version?

+void *sample_arg_ptr = &tdr_dsm;
+
static void
-init_tdr_dsm(void *ptr)
+init_tdr_dsm(void *ptr, void *arg)
{
TestDSMRegistryStruct *dsm = (TestDSMRegistryStruct *) ptr;

- LWLockInitialize(&dsm->lck, LWLockNewTrancheId("test_dsm_registry"));
+ if (arg != sample_arg_ptr)
+ ereport(ERROR,
+ (errmsg("Unexpected arg pointer address")));
+
+ LWLockInitialize(&dsm->lck,
LWLockNewTrancheId("test_dsm_registry_dsm"));
dsm->val = 0;
}

On Fri, Dec 12, 2025 at 8:57 PM Sami Imseih <samimseih(at)gmail(dot)com> wrote:
>
> > On Fri, Dec 12, 2025 at 12:48:52PM -0600, Sami Imseih wrote:
> > > As far as testing, I did not think it's worth it since in the cases out
> > > there now a NULL void * will result in an error when calling
> > > LWLockNewTrancheId.
> >
> > I think we should pass NULL to all the existing in-tree calls to
> > GetNamedDSMSegment(), except for perhaps a new test in test_dsm_registry
> > that verifies the pointer value in the initialization function. In all the
> > other cases, there's no issue with hard-coding the tranche names, so we can
> > keep those simple.
>
> fair point. In that case why don't we just keep:
>
> ```
> static void
> -init_tdr_dsm(void *ptr)
> +init_tdr_dsm(void *ptr, void *arg)
> {
> TestDSMRegistryStruct *dsm = (TestDSMRegistryStruct *) ptr;
>
> - LWLockInitialize(&dsm->lck, LWLockNewTrancheId("test_dsm_registry"));
> + LWLockInitialize(&dsm->lck, LWLockNewTrancheId((char *) arg));
> dsm->val = 0;
> }
>
> @@ -60,6 +60,7 @@ tdr_attach_shmem(void)
> tdr_dsm = GetNamedDSMSegment("test_dsm_registry_dsm",
>
> sizeof(TestDSMRegistryStruct),
> init_tdr_dsm,
> +
> "test_dsm_registry",
> &found);
>
> if (tdr_dsa == NULL)
> ```
>
> instead of creating a new test? For the other GetNamedDSMSegment
> calls, I'll pass
> NULL to the void * and hard code the tranche name in the init callback.
>
> --
> Sami Imseih
> Amazon Web Services (AWS)
>

Attachment Content-Type Size
v6-0001-Add-init_callback_arg-parameter-to-GetNamedDSMSegmen.patch application/octet-stream 8.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2025-12-12 21:07:22 Re: Proposal: Add a callback data parameter to GetNamedDSMSegment
Previous Message Sami Imseih 2025-12-12 20:56:39 Re: Proposal: Add a callback data parameter to GetNamedDSMSegment