[SCM] PostGIS branch master updated. 3.5.0-194-g1f7c3150b
git at osgeo.org
git at osgeo.org
Thu Jan 23 13:58:34 PST 2025
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".
The branch, master has been updated
via 1f7c3150b47ac75059ede6ee4cc8cec30bf5f5ea (commit)
via 9d9d0c0d0e49631651b2b0896bccd496178244a2 (commit)
from 607b81d5af061e4a8dd76ee68f3e601d87107a00 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 1f7c3150b47ac75059ede6ee4cc8cec30bf5f5ea
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Thu Jan 23 13:58:08 2025 -0800
Rework interrupt handling and remove signal handling
from PostGIS. PostGIS does not need to capture signals,
it just needs to look at the state flags exposed by
PgSQL (QueryCancelPending || ProcDiePending) from
time to time and interrupt itself if they are set.
References #5841
diff --git a/NEWS b/NEWS
index 1757d0d78..4c979824c 100644
--- a/NEWS
+++ b/NEWS
@@ -17,3 +17,4 @@ PostGIS 3.6.0
Straight Skeleton Partition) from SFCGAL 2 (Loïc Bartoletti)
- New GUC postgis.gdal_cpl_debug, enables GDAL debugging messages
and routes them into the PostgreSQL logging system. (Paul Ramsey)
+ - #5841, Change interrupt handling to remove use of pqsignal (Paul Ramsey)
diff --git a/postgis/postgis_module.c b/postgis/postgis_module.c
index 5c207d3da..c990e690a 100644
--- a/postgis/postgis_module.c
+++ b/postgis/postgis_module.c
@@ -25,6 +25,7 @@
#include "postgres.h"
#include "fmgr.h"
+#include "miscadmin.h"
#include "executor/executor.h"
#include "utils/elog.h"
#include "utils/guc.h"
@@ -45,18 +46,34 @@
*/
PG_MODULE_MAGIC;
-static pqsigfunc coreIntHandler = 0;
-static void handleInterrupt(int sig);
+// static ExecutorStart_hook_type onExecutorStartPrev = NULL;
+// static void onExecutorStart(QueryDesc *queryDesc, int eflags);
-#ifdef WIN32
-static void interruptCallback() {
- if (UNBLOCKED_SIGNAL_QUEUE())
- pgwin32_dispatch_queued_signals();
+static void interrupt_geos_callback()
+{
+ /*
+ * If PgSQL global flags show interrupt,
+ * flip the pending flag in GEOS
+ * to end current query.
+ */
+ if (QueryCancelPending || ProcDiePending)
+ {
+ GEOS_interruptRequest();
+ }
}
-#endif
-static ExecutorStart_hook_type onExecutorStartPrev = NULL;
-static void onExecutorStart(QueryDesc *queryDesc, int eflags);
+static void interrupt_liblwgeom_callback()
+{
+ /*
+ * If PgSQL global flags show interrupt,
+ * flip the pending flag in liblwgeom
+ * to end current query.
+ */
+ if (QueryCancelPending || ProcDiePending)
+ {
+ lwgeom_request_interrupt();
+ }
+}
/*
* Pass proj error message out via the PostgreSQL logging
@@ -80,24 +97,24 @@ void _PG_init(void);
void
_PG_init(void)
{
- coreIntHandler = pqsignal(SIGINT, handleInterrupt);
+ /*
+ * Hook up interrupt checking to call back here
+ * and examine the PgSQL interrupt state variables
+ */
+ GEOS_interruptRegisterCallback(interrupt_geos_callback);
+ lwgeom_register_interrupt_callback(interrupt_liblwgeom_callback);
-#ifdef WIN32
- GEOS_interruptRegisterCallback(interruptCallback);
- lwgeom_register_interrupt_callback(interruptCallback);
-#endif
+ /* Install PostgreSQL error/memory handlers */
+ pg_install_lwgeom_handlers();
- /* install PostgreSQL handlers */
- pg_install_lwgeom_handlers();
-
- /* pass proj messages through the pgsql error handler */
#if POSTGIS_PROJ_VERSION > 60000
- proj_log_func(NULL, NULL, pjLogFunction);
+ /* Pass proj messages through the pgsql error handler */
+ proj_log_func(NULL, NULL, pjLogFunction);
#endif
- /* setup hooks */
- onExecutorStartPrev = ExecutorStart_hook;
- ExecutorStart_hook = onExecutorStart;
+ /* setup hooks */
+ // onExecutorStartPrev = ExecutorStart_hook;
+ // ExecutorStart_hook = onExecutorStart;
}
/*
@@ -107,54 +124,29 @@ void _PG_fini(void);
void
_PG_fini(void)
{
- elog(NOTICE, "Goodbye from PostGIS %s", POSTGIS_VERSION);
- pqsignal(SIGINT, coreIntHandler);
+ elog(NOTICE, "Goodbye from PostGIS %s", POSTGIS_VERSION);
- /* restore original hooks */
- ExecutorStart_hook = onExecutorStartPrev;
+ /* restore original hooks */
+ // ExecutorStart_hook = onExecutorStartPrev;
}
-static void
-handleInterrupt(int sig)
-{
- /* NOTE: printf here would be dangerous, see
- * https://trac.osgeo.org/postgis/ticket/3644
- *
- * TODO: block interrupts during execution, to fix the problem
- */
- /* printf("Interrupt requested\n"); fflush(stdout); */
- GEOS_interruptRequest();
+// static void onExecutorStart(QueryDesc *queryDesc, int eflags) {
+// /* cancel interrupt requests */
-#ifdef HAVE_LIBPROTOBUF
- /* Taking out per #5385 crash */
- //lwgeom_wagyu_interruptRequest();
-#endif
+// GEOS_interruptCancel();
- /* request interruption of liblwgeom as well */
- lwgeom_request_interrupt();
+// #ifdef HAVE_LIBPROTOBUF
+// /* Taking out per #5385 crash */
+// //lwgeom_wagyu_interruptReset();
+// #endif
- if ( coreIntHandler ) {
- (*coreIntHandler)(sig);
- }
-}
+// lwgeom_cancel_interrupt();
-static void onExecutorStart(QueryDesc *queryDesc, int eflags) {
- /* cancel interrupt requests */
-
- GEOS_interruptCancel();
-
-#ifdef HAVE_LIBPROTOBUF
- /* Taking out per #5385 crash */
- //lwgeom_wagyu_interruptReset();
-#endif
-
- lwgeom_cancel_interrupt();
-
- if (onExecutorStartPrev) {
- (*onExecutorStartPrev)(queryDesc, eflags);
- } else {
- standard_ExecutorStart(queryDesc, eflags);
- }
-}
+// if (onExecutorStartPrev) {
+// (*onExecutorStartPrev)(queryDesc, eflags);
+// } else {
+// standard_ExecutorStart(queryDesc, eflags);
+// }
+// }
diff --git a/raster/rt_pg/rtpostgis.c b/raster/rt_pg/rtpostgis.c
index cd9ab0c56..a28c2aca1 100644
--- a/raster/rt_pg/rtpostgis.c
+++ b/raster/rt_pg/rtpostgis.c
@@ -646,47 +646,6 @@ rtpg_assignHookEnableOutDBRasters(bool enable, void *extra) {
}
-/*
-* Machinery for intercepting the system SIGINT
-* handler so we can cancel long-running GDAL operations
-* via the progress handlers.
-*/
-static pqsigfunc coreIntHandler = 0;
-
-#ifdef WIN32
-static void interruptCallback() {
- if (UNBLOCKED_SIGNAL_QUEUE())
- pgwin32_dispatch_queued_signals();
-}
-#endif
-
-
-/*
-* This is the interrupt capture for this module.
-* Before handing off the signal to the core, it
-* sets the interrupt flag for currently running
-* functions.
-*/
-static void
-handleInterrupt(int sig)
-{
- /*
- * NOTE: printf here would be dangerous, see
- * https://trac.osgeo.org/postgis/ticket/3644
- */
- // printf("postgis_raster interrupt requested\n"); fflush(stdout);
-
- /* Request interruption of liblwgeom as well */
- lwgeom_request_interrupt();
-
- /* Pass control into the usual core handler */
- if (coreIntHandler) {
- (*coreIntHandler)(sig);
- }
-}
-
-
-
/* Module load callback */
void
_PG_init(void) {
@@ -694,15 +653,6 @@ _PG_init(void) {
bool boot_postgis_enable_outdb_rasters = false;
MemoryContext old_context;
- /* Set up interrupt capture */
- coreIntHandler = pqsignal(SIGINT, handleInterrupt);
-
-#ifdef WIN32
- GEOS_interruptRegisterCallback(interruptCallback);
- lwgeom_register_interrupt_callback(interruptCallback);
-#endif
-
-
/*
* Change to context for memory allocation calls like palloc() in the
* extension initialization routine
@@ -890,9 +840,6 @@ _PG_fini(void) {
elog(NOTICE, "Goodbye from PostGIS Raster %s", POSTGIS_VERSION);
- /* Return SIGINT handling to core */
- pqsignal(SIGINT, coreIntHandler);
-
/* Clean up */
pfree(env_postgis_gdal_enabled_drivers);
pfree(boot_postgis_gdal_enabled_drivers);
diff --git a/sfcgal/lwgeom_sfcgal.c b/sfcgal/lwgeom_sfcgal.c
index e20a4709a..a73834701 100644
--- a/sfcgal/lwgeom_sfcgal.c
+++ b/sfcgal/lwgeom_sfcgal.c
@@ -40,72 +40,12 @@
* This is required for builds against pgsql
*/
PG_MODULE_MAGIC;
-#ifdef WIN32
-static void
-interruptCallback()
-{
- if (UNBLOCKED_SIGNAL_QUEUE())
- pgwin32_dispatch_queued_signals();
-}
-#endif
-
-static pqsigfunc coreIntHandler = 0;
-static void handleInterrupt(int sig);
-
-/*
- * Module load callback
- */
-void _PG_init(void);
-void
-_PG_init(void)
-{
-
- coreIntHandler = pqsignal(SIGINT, handleInterrupt);
-
-#ifdef WIN32
- GEOS_interruptRegisterCallback(interruptCallback);
- lwgeom_register_interrupt_callback(interruptCallback);
-#endif
-
- /* install PostgreSQL handlers */
- pg_install_lwgeom_handlers();
-}
-
-/*
- * Module unload callback
- */
-void _PG_fini(void);
-void
-_PG_fini(void)
-{
- elog(NOTICE, "Goodbye from PostGIS SFCGAL %s", POSTGIS_VERSION);
- pqsignal(SIGINT, coreIntHandler);
-}
-
-static void
-handleInterrupt(int sig)
-{
- /* NOTE: printf here would be dangerous, see
- * https://trac.osgeo.org/postgis/ticket/3644
- *
- * TODO: block interrupts during execution, to fix the problem
- */
- /* printf("Interrupt requested\n"); fflush(stdout); */
-
- /* request interruption of liblwgeom as well */
- lwgeom_request_interrupt();
-
- if (coreIntHandler)
- {
- (*coreIntHandler)(sig);
- }
-}
-
-Datum postgis_sfcgal_version(PG_FUNCTION_ARGS);
+/* Prototypes */
#if POSTGIS_SFCGAL_VERSION >= 10400
Datum postgis_sfcgal_full_version(PG_FUNCTION_ARGS);
#endif
+Datum postgis_sfcgal_version(PG_FUNCTION_ARGS);
Datum sfcgal_from_ewkt(PG_FUNCTION_ARGS);
Datum sfcgal_distance(PG_FUNCTION_ARGS);
@@ -140,9 +80,31 @@ Datum sfcgal_optimalalphashape(PG_FUNCTION_ARGS);
GSERIALIZED *geometry_serialize(LWGEOM *lwgeom);
char *text_to_cstring(const text *textptr);
+void _PG_init(void);
+void _PG_fini(void);
+
static int __sfcgal_init = 0;
+
+/* Module load callback */
+void
+_PG_init(void)
+{
+ /* install PostgreSQL handlers */
+ pg_install_lwgeom_handlers();
+ elog(DEBUG1, "PostGIS SFCGAL %s loaded", POSTGIS_VERSION);
+}
+
+
+/* Module unload callback */
+void
+_PG_fini(void)
+{
+ elog(NOTICE, "Goodbye from PostGIS SFCGAL %s", POSTGIS_VERSION);
+}
+
+
void
sfcgal_postgis_init(void)
{
commit 9d9d0c0d0e49631651b2b0896bccd496178244a2
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Thu Jan 23 13:05:29 2025 -0800
New GUC postgis.gdal_cpl_debug turns on GDAL
debugging messages and routes them into the
PostgreSQL logging stream.
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index 4fdd1c507..6396f7408 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -54,7 +54,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
- sudo apt-get install -y g++ autoconf automake libgeos-dev libproj-dev libgdal-dev libjson-c-dev gettext libxml2-dev postgresql-server-dev-14 postgresql-client-14 libprotobuf-c-dev libprotoc-dev protobuf-c-compiler
+ sudo apt-get install -y g++ autoconf automake libgeos-dev libproj-dev libgdal-dev libjson-c-dev gettext libxml2-dev postgresql-server-dev-16 postgresql-client-16 libprotobuf-c-dev libprotoc-dev protobuf-c-compiler
- name: Build
run: |
diff --git a/NEWS b/NEWS
index 20da4b96d..1757d0d78 100644
--- a/NEWS
+++ b/NEWS
@@ -15,3 +15,5 @@ PostGIS 3.6.0
(Maxime Schoemans)
- GT-228 Add new functions (Scale, Translate, Rotate, Buffer 3D and
Straight Skeleton Partition) from SFCGAL 2 (Loïc Bartoletti)
+ - New GUC postgis.gdal_cpl_debug, enables GDAL debugging messages
+ and routes them into the PostgreSQL logging system. (Paul Ramsey)
diff --git a/doc/reference_guc.xml b/doc/reference_guc.xml
index 01a9c9668..d95a91d73 100644
--- a/doc/reference_guc.xml
+++ b/doc/reference_guc.xml
@@ -297,5 +297,34 @@ SET LOCAL postgis.gdal_vsi_options = 'AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxx AWS_SECR
</refentry>
+ <refentry xml:id="postgis_gdal_cpl_debug">
+ <refnamediv>
+ <refname>postgis.gdal_cpl_debug</refname>
+ <refpurpose>
+ A boolean configuration to turn logging of GDAL debug messages on and off.
+ </refpurpose>
+ </refnamediv>
+
+ <refsection>
+ <title>Description</title>
+ <para>
+ By default, GDAL logging is printed to stderr, and lower level debug messages are not printed at all. Turning this GUC to true will cause GDAL logging to be sent into the PostgreSQL logging stream, so you can see more or less of it by altering the <code>client_min_message</code> PostgreSQL GUC.
+ </para>
+
+ <para role="availability" conformance="3.6.0">Availability: 3.6.0</para>
+
+ </refsection>
+
+ <refsection>
+ <title>See Also</title>
+ <para>
+ <xref linkend="postgis_enable_outdb_rasters"/>
+ <xref linkend="postgis_gdal_enabled_drivers"/>
+ </para>
+ </refsection>
+ </refentry>
+
+
+
</section>
diff --git a/raster/rt_pg/rtpg_gdal.c b/raster/rt_pg/rtpg_gdal.c
index 039ea61d5..957c208e2 100644
--- a/raster/rt_pg/rtpg_gdal.c
+++ b/raster/rt_pg/rtpg_gdal.c
@@ -1075,3 +1075,67 @@ Datum RASTER_GDALWarp(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(pgrast);
}
+/***********************************************************************/
+/* Support for hooking up GDAL logging to PgSQL error/debug reporting */
+
+#define gdalErrorTypesSize 17
+
+const char* const gdalErrorTypes[gdalErrorTypesSize] =
+{
+ "None",
+ "AppDefined",
+ "OutOfMemory",
+ "FileIO",
+ "OpenFailed",
+ "IllegalArg",
+ "NotSupported",
+ "AssertionFailed",
+ "NoWriteAccess",
+ "UserInterrupt",
+ "ObjectNull",
+ "HttpResponse",
+ "AWSBucketNotFound",
+ "AWSObjectNotFound",
+ "AWSAccessDenied",
+ "AWSInvalidCredentials",
+ "AWSSignatureDoesNotMatch"
+};
+
+static void
+ogrErrorHandler(CPLErr eErrClass, int err_no, const char* msg)
+{
+ const char* gdalErrType = "unknown type";
+ if (err_no >= 0 && err_no < gdalErrorTypesSize)
+ {
+ gdalErrType = gdalErrorTypes[err_no];
+ }
+ switch (eErrClass)
+ {
+ case CE_None:
+ elog(NOTICE, "GDAL %s [%d] %s", gdalErrType, err_no, msg);
+ break;
+ case CE_Debug:
+ elog(DEBUG2, "GDAL %s [%d] %s", gdalErrType, err_no, msg);
+ break;
+ case CE_Warning:
+ elog(WARNING, "GDAL %s [%d] %s", gdalErrType, err_no, msg);
+ break;
+ case CE_Failure:
+ case CE_Fatal:
+ default:
+ elog(ERROR, "GDAL %s [%d] %s", gdalErrType, err_no, msg);
+ break;
+ }
+ return;
+}
+
+void
+rtpg_gdal_set_cpl_debug(bool value, void *extra)
+{
+ (void)extra;
+ CPLSetConfigOption("CPL_DEBUG", value ? "ON" : "OFF");
+ /* Hook up the GDAL error handlers to PgSQL elog() */
+ CPLSetErrorHandler(value ? ogrErrorHandler : NULL);
+ CPLSetCurrentErrorHandlerCatchDebug(value);
+}
+
diff --git a/raster/rt_pg/rtpostgis.c b/raster/rt_pg/rtpostgis.c
index 09c5bd65a..cd9ab0c56 100644
--- a/raster/rt_pg/rtpostgis.c
+++ b/raster/rt_pg/rtpostgis.c
@@ -167,7 +167,6 @@ void _PG_fini(void);
#define RT_MSG_MAXLEN 256
-
/* ---------------------------------------------------------------- */
/* Memory allocation / error reporting hooks */
/* ---------------------------------------------------------------- */
@@ -462,6 +461,7 @@ static char *gdal_datapath = NULL;
static char *gdal_vsi_options = NULL;
static char *gdal_enabled_drivers = NULL;
static bool enable_outdb_rasters = false;
+static bool gdal_cpl_debug = false;
/* ---------------------------------------------------------------- */
/* Useful variables */
@@ -646,7 +646,6 @@ rtpg_assignHookEnableOutDBRasters(bool enable, void *extra) {
}
-
/*
* Machinery for intercepting the system SIGINT
* handler so we can cancel long-running GDAL operations
@@ -835,6 +834,30 @@ _PG_init(void) {
);
}
+ /* Prototype for CPL_Degbuf control function. */
+ if ( postgis_guc_find_option("postgis.gdal_cpl_debug") )
+ {
+ /* In this narrow case the previously installed GUC is tied to the callback in */
+ /* the previously loaded library. Probably this is happening during an */
+ /* upgrade, so the old library is where the callback ties to. */
+ elog(WARNING, "'%s' is already set and cannot be changed until you reconnect", "postgis.gdal_cpl_debug");
+ }
+ else
+ {
+ DefineCustomBoolVariable(
+ "postgis.gdal_cpl_debug", /* name */
+ "Enable GDAL debugging messages", /* short_desc */
+ "GDAL debug messages will be sent at the PgSQL debug log level", /* long_desc */
+ &gdal_cpl_debug, /* valueAddr */
+ false, /* bootValue */
+ PGC_SUSET, /* GucContext context */
+ 0, /* int flags */
+ NULL, /* GucBoolCheckHook check_hook */
+ rtpg_gdal_set_cpl_debug, /* GucBoolAssignHook assign_hook */
+ NULL /* GucShowHook show_hook */
+ );
+ }
+
if ( postgis_guc_find_option("postgis.gdal_vsi_options") )
{
elog(WARNING, "'%s' is already set and cannot be changed until you reconnect", "postgis.gdal_vsi_options");
diff --git a/raster/rt_pg/rtpostgis.h b/raster/rt_pg/rtpostgis.h
index d12c291be..bef763e15 100644
--- a/raster/rt_pg/rtpostgis.h
+++ b/raster/rt_pg/rtpostgis.h
@@ -47,27 +47,27 @@
/* Display a simple message at NOTICE level */
#define POSTGIS_RT_DEBUG(level, msg) \
- do { \
- if (POSTGIS_DEBUG_LEVEL >= level) \
- ereport((level < 1 || level > 5) ? DEBUG5 : (LOG - level), (errmsg_internal("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__))); \
- } while (0);
+ do { \
+ if (POSTGIS_DEBUG_LEVEL >= level) \
+ ereport((level < 1 || level > 5) ? DEBUG5 : (LOG - level), (errmsg_internal("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__))); \
+ } while (0);
/* Display a formatted message at NOTICE level (like printf, with variadic arguments) */
#define POSTGIS_RT_DEBUGF(level, msg, ...) \
- do { \
- if (POSTGIS_DEBUG_LEVEL >= level) \
- ereport((level < 1 || level > 5) ? DEBUG5 : (LOG - level), (errmsg_internal("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__, __VA_ARGS__))); \
- } while (0);
+ do { \
+ if (POSTGIS_DEBUG_LEVEL >= level) \
+ ereport((level < 1 || level > 5) ? DEBUG5 : (LOG - level), (errmsg_internal("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__, __VA_ARGS__))); \
+ } while (0);
#else
/* Empty prototype that can be optimised away by the compiler for non-debug builds */
#define POSTGIS_RT_DEBUG(level, msg) \
- ((void) 0)
+ ((void) 0)
/* Empty prototype that can be optimised away by the compiler for non-debug builds */
#define POSTGIS_RT_DEBUGF(level, msg, ...) \
- ((void) 0)
+ ((void) 0)
#endif
@@ -79,5 +79,7 @@ typedef struct rt_raster_serialized_t rt_pgraster;
#define MAX_DBL_CHARLEN (3 + DBL_MANT_DIG - DBL_MIN_EXP)
#define MAX_INT_CHARLEN 32
+/* postgis.gdal_cpl_debug on/off callback */
+void rtpg_gdal_set_cpl_debug(bool value, void *extra);
#endif /* RTPOSTGIS_H_INCLUDED */
-----------------------------------------------------------------------
Summary of changes:
.github/workflows/codeql.yml | 2 +-
NEWS | 3 ++
doc/reference_guc.xml | 29 +++++++++++
postgis/postgis_module.c | 120 ++++++++++++++++++++-----------------------
raster/rt_pg/rtpg_gdal.c | 64 +++++++++++++++++++++++
raster/rt_pg/rtpostgis.c | 80 +++++++++--------------------
raster/rt_pg/rtpostgis.h | 22 ++++----
sfcgal/lwgeom_sfcgal.c | 86 +++++++++----------------------
8 files changed, 214 insertions(+), 192 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list