aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/time/snapmgr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/time/snapmgr.c')
-rw-r--r--src/backend/utils/time/snapmgr.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c
index a0b703a5195..a0b81bf1549 100644
--- a/src/backend/utils/time/snapmgr.c
+++ b/src/backend/utils/time/snapmgr.c
@@ -1625,6 +1625,32 @@ ThereAreNoPriorRegisteredSnapshots(void)
return false;
}
+/*
+ * HaveRegisteredOrActiveSnapshots
+ * Is there any registered or active snapshot?
+ *
+ * NB: Unless pushed or active, the cached catalog snapshot will not cause
+ * this function to return true. That allows this function to be used in
+ * checks enforcing a longer-lived snapshot.
+ */
+bool
+HaveRegisteredOrActiveSnapshot(void)
+{
+ if (ActiveSnapshot != NULL)
+ return true;
+
+ /*
+ * The catalog snapshot is in RegisteredSnapshots when valid, but can be
+ * removed at any time due to invalidation processing. If explicitly
+ * registered more than one snapshot has to be in RegisteredSnapshots.
+ */
+ if (pairingheap_is_empty(&RegisteredSnapshots) ||
+ !pairingheap_is_singular(&RegisteredSnapshots))
+ return false;
+
+ return CatalogSnapshot == NULL;
+}
+
/*
* Return a timestamp that is exactly on a minute boundary.