[PATCH] aio: Refactor to deduplicate shared and local completion callbacks

Started by zengman9 months ago3 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t53012
psql -h localhost -U postgres

Built from patchset v1 (message #1), September 20, 2026 at 08:48 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t53012_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t53012_1 && git checkout t53012_1

Patchset v1 (message #1) is on t53012_1

Jump to latest
#1zengman
zengman@halodbtech.com

Hi,

I've observed that the functions `pgaio_io_call_complete_shared()` and` pgaio_io_call_complete_local()` contain nearly identical code,
with only minor differences in initialization and callback selection.
This code duplication was previously noted with an XXX comment.
I propose extracting the common logic into a new internal function `pgaio_io_call_complete_internal()`,
which uses a boolean parameter to distinguish between the two code paths.
What do you think of this approach?

--
Regards,
Man Zeng
www.openhalo.org

Attachments:

t53012_1
0001-aio-Deduplicate-shared-and-local-completion-callback.patchapplication/octet-stream; charset=ISO-8859-1; name=0001-aio-Deduplicate-shared-and-local-completion-callback.patchDownload+41-48
#2Andres Freund
andres@anarazel.de
In reply to: zengman (#1)
Re: [PATCH] aio: Refactor to deduplicate shared and local completion callbacks

Hi,

On 2026-01-02 20:51:14 +0800, zengman wrote:

I've observed that the functions `pgaio_io_call_complete_shared()` and`
pgaio_io_call_complete_local()` contain nearly identical code, with only
minor differences in initialization and callback selection. This code
duplication was previously noted with an XXX comment.

I propose extracting the common logic into a new internal function
`pgaio_io_call_complete_internal()`, which uses a boolean parameter to
distinguish between the two code paths. What do you think of this approach?

It doesn't really seem to improve things sufficiently for my taste. If you
don't remove comments that are actually important, like "Note that we don't
save the result", the code doesn't even get shorter. And it's not like the
function afterwards is more generic, since it encodes all the knowledge about
the different callback kinds.

Greetings,

Andres Freund

#3zengman
zengman@halodbtech.com
In reply to: Andres Freund (#2)
Re: [PATCH] aio: Refactor to deduplicate shared and local completion callbacks

It doesn't really seem to improve things sufficiently for my taste. If you
don't remove comments that are actually important, like "Note that we don't
save the result", the code doesn't even get shorter. And it's not like the
function afterwards is more generic, since it encodes all the knowledge about
the different callback kinds.

Thanks for the feedback. I’ll think of a better approach.
Thanks for the guidance.

--
Regards,
Man Zeng
www.openhalo.org