Thread

  1. Re: Proposal: Add a callback data parameter to GetNamedDSMSegment

    Sami Imseih <samimseih@gmail.com> — 2025-12-11T22:12:02Z

    > 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)