Re: Enables to call Unregister*XactCallback() in Call*XactCallback() - Mailing list pgsql-hackers

From Hao Wu
Subject Re: Enables to call Unregister*XactCallback() in Call*XactCallback()
Date
Msg-id CAH+9SWXs6meXwSv5tTy0-amzOeZN=sko8B78cDG4HhHp3566Ew@mail.gmail.com
Whole thread Raw
In response to Re: Enables to call Unregister*XactCallback() in Call*XactCallback()  (Andres Freund <andres@anarazel.de>)
List 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

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: shared-memory based stats collector - v69
Next
From: Thom Brown
Date:
Subject: Re: [COMMITTERS] pgsql: Allow time delayed standbys and recovery