Re: Enables to call Unregister*XactCallback() in Call*XactCallback()

From: Hao Wu <gfphoenix78(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Enables to call Unregister*XactCallback() in Call*XactCallback()
Date: 2022-04-05 23:27:21
Message-ID: CAH+9SWXs6meXwSv5tTy0-amzOeZN=sko8B78cDG4HhHp3566Ew@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> You normally shouldn'd need to do this frequently - what's your use case?
> UnregisterXactCallback() is O(N), so workloads registering / unregistering
> a
> lot of callbacks would be problematic.
>
> It's not about workloads or efficiency. Here is the use case:
I want to register a callback for some subtransaction, and only run this
callback once
when the subtransaction ends, no matter if it was committed or cancelled.

It's reasonable to unregister the callback at the end of the callback, or I
have to
call UnregisterSubXactCallback() somewhere. Because
SubXact_callbacks/Xact_callbacks
is only set by Unregister*XactCallback(). The question now becomes
1. where to call UnregisterSubXactCallback()
2. ensure that calling UnregisterSubXactCallback() is not triggered in the
current callback

This patch enables us to safely delete the current callback when the
callback finishes to
implement run callback once and unregister in one place.

Regards,
Hao Wu

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thom Brown 2022-04-06 00:42:48 Re: [COMMITTERS] pgsql: Allow time delayed standbys and recovery
Previous Message Andres Freund 2022-04-05 23:16:28 Re: shared-memory based stats collector - v69