The forgotten patch


On Fri, Sep 18, 2026 at 5:59 PM shihao zhong <[email protected]> wrote:
>
> Hi Alexandre,
>
> Thanks for looking into this issue. It seems the patch is missing from the 
> attachment.
>
> Also, would you mind creating a new entry in commifeast?
>
> Thanks,
> Shihao
>
From a91d64addf12d93a6d4dc5e0089e8bd0801150f3 Mon Sep 17 00:00:00 2001
From: Alexandre Felipe <[email protected]>
Date: Thu, 17 Sep 2026 21:30:53 +0100
Subject: [PATCH-v1] pgaio: file descriptor cache invalidation.

It was reported that io_method=worker, I/O worker processes
retain open file descriptors on relation that have been dropped [1]

Regular backends do not accumulate them: they receive SMGR invalidation
via the shared invalidation queue I/O workers were not handling invalidation
messages.

This patch implements cache invalidation processing for I/O workers.
---
 src/backend/storage/aio/method_worker.c | 31 +++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/backend/storage/aio/method_worker.c b/src/backend/storage/aio/method_worker.c
index cf75b2816b7..d98464c67f4 100644
--- a/src/backend/storage/aio/method_worker.c
+++ b/src/backend/storage/aio/method_worker.c
@@ -44,7 +44,9 @@
 #include "storage/lwlock.h"
 #include "storage/pmsignal.h"
 #include "storage/proc.h"
+#include "storage/sinvaladt.h"
 #include "storage/shmem.h"
+#include "storage/smgr.h"
 #include "tcop/tcopprot.h"
 #include "utils/injection_point.h"
 #include "utils/memdebug.h"
@@ -683,6 +685,24 @@ check_io_worker_gucs(void)
 						   "io_max_workers", io_max_workers)));
 }
 
+/*
+ * Handle cache invalidation messages for IoWorker
+ *
+ * Same as LocalExecuteInvalidationMessage for backends,
+ * but in IoWorkers handle only file invalidation messages.
+ */
+static void
+pgaio_cache_invalidation_callback(SharedInvalidationMessage *msg)
+{
+	if (msg->id == SHAREDINVALSMGR_ID)
+	{
+		RelFileLocatorBackend rlocator;
+		rlocator.locator = msg->sm.rlocator;
+		rlocator.backend = (msg->sm.backend_hi << 16) | (int) msg->sm.backend_lo;
+		smgrreleaserellocator(rlocator);
+	}
+}
+
 void
 IoWorkerMain(const void *startup_data, size_t startup_data_len)
 {
@@ -698,6 +718,11 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
 
 	AuxiliaryProcessMainCommon();
 
+	/*
+	 * IO workers cache file descriptors locally, subscribe to cluster-wide
+	 * cache invalidation events.
+	 */
+	SharedInvalBackendInit(false);
 	pqsignal(SIGHUP, SignalHandlerForConfigReload);
 	pqsignal(SIGINT, die);		/* to allow manually triggering worker restart */
 
@@ -1032,6 +1057,12 @@ IoWorkerMain(const void *startup_data, size_t startup_data_len)
 
 		CHECK_FOR_INTERRUPTS();
 
+		/*
+		 * Handle pending invalidation one by one.
+		 * smgrreleaseall used when there are too many pending invalidations.
+		 */
+		ReceiveSharedInvalidMessages(pgaio_cache_invalidation_callback, smgrreleaseall);
+
 		if (ConfigReloadPending)
 		{
 			int			io_max_workers_prev = io_max_workers;
-- 
2.53.0

Reply via email to