From: | Peter Smith <smithpb2250(at)gmail(dot)com> |
---|---|
To: | "Aya Iwata (Fujitsu)" <iwata(dot)aya(at)fujitsu(dot)com> |
Cc: | "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE |
Date: | 2025-10-08 22:18:00 |
Message-ID: | CAHut+PuuOKKW2oDT0Z8q+UXsiteS67j6G6075FC3aAxeR0cxHQ@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi Iwata-San,
Some v4 comments.
======
src/backend/postmaster/bgworker.c
1.
+ /*
+ * Set terminate flag in shared memory, unless slot has
+ * been used.
+ */
+ for (int slotno = 0; slotno < BackgroundWorkerData->total_slots; ++slotno)
+ {
+ PGPROC *proc;
+ BackgroundWorkerSlot *slot = &BackgroundWorkerData->slot[slotno];
+
+ if (!slot->in_use)
+ continue;
+
+ if (!(slot->worker.bgw_flags & BGWORKER_EXIT_AT_DATABASE_DROP))
+ continue;
+
+ proc = BackendPidGetProc(slot->pid);
+
+ if (proc && proc->databaseId == databaseId)
+ {
+ slot->terminate = true;
+ signal_postmaster = true;
+ }
+ }
1a.
It's not clear to me what you were trying to convey by saying "unless
slot has been used" in the comment. Maybe you meant "unless slot is
not in use", but is that useful even to say? Anyway, the comment as-is
seems incorrect.
~
1b.
Sorry for wavering on this, but now that I see the resulting v4 code,
I feel we don't really need any of those 'continues', and more if
conditions can be combined. It becomes simpler. See if you agree.
SUGGESTION:
for (int slotno ...)
{
if (slot->in_use && (slot->worker.bgw_flags & BGWORKER_EXIT_AT_DATABASE_DROP))
{
PGPROC *proc = BackendPidGetProc(slot->pid);
if (proc && proc->databaseId == databaseId)
{
slot->terminate = true;
signal_postmaster = true;
}
}
}
======
src/backend/storage/ipc/procarray.c
2.
+ /*
+ * if set the bgw_flags, cancel background workers.
+ */
+ CancelBackgroundWorkers(databaseId);
+
I was wondering about this function name "CancelXXX" -- do you
"cancel" a worker, or do you "terminate" it?
Isn't it better to name this new function more like the
existing/similar TerminateBackgroundWorker() function?
E.g. consider the following:
/*
* Terminate all background workers for this database, if
* they had requested it (BGWORKER_EXIT_AT_DATABASE_DROP).
*/
TerminateBackgroundWorkersForDB(databaseId);
======
Kind Regards,
Peter Smith.
Fujitsu Australia
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Smith | 2025-10-08 22:42:10 | Re: pg_createsubscriber --dry-run logging concerns |
Previous Message | David Rowley | 2025-10-08 22:08:36 | Re: VACUUM (PARALLEL) option processing not using DefElem the way it was intended |