From 7c612cc6f3257f23fdc626a745e114ea2ef66308 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 28 Nov 2022 15:15:37 -0800 Subject: [PATCH v18 4/4] Do not delay shutdown due to long-running custodian tasks. These tasks are not essential enough to delay shutdown and can be retried the next time the server is running. --- src/backend/access/heap/rewriteheap.c | 9 +++++++++ src/backend/postmaster/custodian.c | 8 ++++++++ src/backend/replication/logical/snapbuild.c | 9 +++++++++ 3 files changed, 26 insertions(+) diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c index ff4cd8cef9..a098060d76 100644 --- a/src/backend/access/heap/rewriteheap.c +++ b/src/backend/access/heap/rewriteheap.c @@ -117,6 +117,7 @@ #include "miscadmin.h" #include "pgstat.h" #include "postmaster/custodian.h" +#include "postmaster/interrupt.h" #include "replication/logical.h" #include "replication/slot.h" #include "storage/bufmgr.h" @@ -1313,6 +1314,14 @@ RemoveOldLogicalRewriteMappings(void) lo; PGFileType de_type; + /* + * This task is not essential enough to delay shutdown, so bail out if + * there's a pending shutdown request. We'll try again the next time + * the server is running. + */ + if (ShutdownRequestPending) + break; + if (strcmp(mapping_de->d_name, ".") == 0 || strcmp(mapping_de->d_name, "..") == 0) continue; diff --git a/src/backend/postmaster/custodian.c b/src/backend/postmaster/custodian.c index 33185e9913..5c24c5aefe 100644 --- a/src/backend/postmaster/custodian.c +++ b/src/backend/postmaster/custodian.c @@ -226,6 +226,14 @@ DoCustodianTasks(void) { CustodianTaskFunction func = (LookupCustodianFunctions(task))->task_func; + /* + * Custodian tasks are not essential enough to delay shutdown, so bail + * out if there's a pending shutdown request. Tasks should be + * requested again and retried the next time the server is running. + */ + if (ShutdownRequestPending) + break; + PG_TRY(); { (*func) (); diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c index e7c4f69b42..939ad4c4ab 100644 --- a/src/backend/replication/logical/snapbuild.c +++ b/src/backend/replication/logical/snapbuild.c @@ -126,6 +126,7 @@ #include "common/file_utils.h" #include "miscadmin.h" #include "pgstat.h" +#include "postmaster/interrupt.h" #include "replication/logical.h" #include "replication/reorderbuffer.h" #include "replication/snapbuild.h" @@ -2072,6 +2073,14 @@ RemoveOldSerializedSnapshots(void) XLogRecPtr lsn; PGFileType de_type; + /* + * This task is not essential enough to delay shutdown, so bail out if + * there's a pending shutdown request. We'll try again the next time + * the server is running. + */ + if (ShutdownRequestPending) + break; + if (strcmp(snap_de->d_name, ".") == 0 || strcmp(snap_de->d_name, "..") == 0) continue; -- 2.25.1