Re: Non-blocking archiver process

From: Artem Gavrilov <artem(dot)gavrilov(at)percona(dot)com>
To: Patrick Stählin <me(at)packi(dot)ch>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Ronan Dunklau <ronan(dot)dunklau(at)aiven(dot)io>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Non-blocking archiver process
Date: 2025-09-25 11:13:24
Message-ID: CAFPkQKwgOvyyt2LmrCjCX4_aR2S+DsCnH6_rXHHp396CMh_5HQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello Patrick

I did a review of your patch.

Initial Run
===========
The patch applies cleanly to HEAD (196063d6761). All tests successfully
pass on MacOS 15.7.

Comments
===========
1) Instead of `malloc` and `free` it should be `palloc` and `pfree`.

2) In fact `archiveFileno` is a file descriptor, and the first variable one
is not. I think it's worth to rename them to `archiveFile` and `archiveFd`.
Or maybe even just `file` and `fd` as the scope there is not so big.
>
> FILE *archiveFd = NULL;
> int archiveFileno;

3) Variable name `bytesRead` is rare in PG code base. It is used only two
times, while `readBytes` is used four times. Other variants, like `nbytes`
are more common. Let's pick some popular name.

4) Variable name `dwRc` is unique for the PG codebase and not really clear
as for me. How about name it just `exitcode`?

5) `return` is redundant here as it will never be reached.

ereport(FATAL,
> (errmsg_internal("Failed to malloc win32cmd %m")));
> return false;

6) Same here, `free` and `return` are unreachable due ereport with fatal
level.

> ereport(FATAL,
> (errmsg("CreateProcess() call failed: %m (error code %lu)",
> GetLastError())));
> free(win32cmd);
> return false;

7) This loop can be stuck forever as `WaitForSingleObject` may
return `WAIT_FAILED*` *and it's not always retriable.

> while (true)
> {
> CHECK_FOR_INTERRUPTS();
> if (WaitForSingleObject(pi.hProcess, POLL_TIMEOUT_MSEC) ==
> WAIT_OBJECT_0)
> break;
> }

--

<https://www.percona.com/>

Artem Gavrilov
Senior Software Engineer, Percona

artem(dot)gavrilov(at)percona(dot)com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2025-09-25 11:57:09 Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
Previous Message Hayato Kuroda (Fujitsu) 2025-09-25 11:11:17 RE: Remove obsolate comments from 047_checkpoint_physical_slot