Re: Proposal: Add a callback data parameter to GetNamedDSMSegment

From: Sami Imseih <samimseih(at)gmail(dot)com>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: Zsolt Parragi <zsolt(dot)parragi(at)percona(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-11 22:12:02
Message-ID: CAA5RZ0vHJV=aKfMLMPoB1xHYtge4pL31cFCUCCXDT6QVQo=nLw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> This works well for the first use-case identified. Instead of hard-
> coding the tranche name in the callback, the name can be
> retrieved as the segment name set in GetNamedDSMSegment.
>
> The caller could still pass this name via the extra callback args, but
> it's better to separate things a bit here, and reserve the extra callback
> arguments for more complex data.
>
> What do you think?

As I did not hear back, I went ahead and prepared a patch with the above.

I went back-forth on if it makes sense to provide the name as an
extra argument and decided it provides more flexibility. For example
I can use the same init callback and arguments for different segments.

Also, the name provides a guarantee of the name of the segment that
this callback is initializing.

Overall, I felt it was a better approach.

I updated the code comments and documentation.

Also, in test_dsa.c, i updated the name of the segments to
reflect the name of the functions creating the segments, like
below:
```
@@ -38,8 +38,8 @@ test_dsa_basic(PG_FUNCTION_ARGS)
dsa_area *a;
dsa_pointer p[100];

- tranche_id = GetNamedDSMSegment("test_dsa", sizeof(int),
-
init_tranche, &found);
+ tranche_id = GetNamedDSMSegment("test_dsa_basic", sizeof(int),
+
init_tranche, NULL, &found);

@@ -79,8 +79,8 @@ test_dsa_resowners(PG_FUNCTION_ARGS)
ResourceOwner oldowner;
ResourceOwner childowner;

- tranche_id = GetNamedDSMSegment("test_dsa", sizeof(int),
-
init_tranche, &found);
+ tranche_id = GetNamedDSMSegment("test_dsa_resowners", sizeof(int),
+
init_tranche, NULL, &found);

```
This is good for showing the same init callback being re-used
for different named segment initizations.

I also updated the commit message.

--
Sami Imseih
Amazon Web Services (AWS)

Attachment Content-Type Size
v2-0001-Pass-name-and-callback-data-to-GetNamedDSMSegment.patch application/octet-stream 8.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2025-12-11 22:36:50 Re: Fix uninitialized PruneFreezeResult in pruneheap and vacuumlazy
Previous Message Corey Huinker 2025-12-11 21:59:19 Re: Import Statistics in postgres_fdw before resorting to sampling.