#2382, allow multiple libraries to co-exist during upgrade, warn about GUC value...
authorPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 11 Aug 2015 14:33:23 +0000 (14:33 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Tue, 11 Aug 2015 14:33:23 +0000 (14:33 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13902 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_backend_api.c

index 5bac65d5d29e4c2d8c9429e5a6395ff578caf3de..5fbfa54afef7768e822a0e36dd5cc62c8f212caa 100644 (file)
@@ -104,7 +104,31 @@ static void lwgeom_backend_switch( const char* newvalue, void* extra )
 
 void lwgeom_init_backend()
 {
-    DefineCustomStringVariable( "postgis.backend", /* name */
+       /* #2382 Before trying to create a user GUC, make sure */
+       /* that the name is not already in use. Why would it be in use? */
+       /* During an upgrade, a prior copy of the PostGIS library will */
+       /* already be loaded in memory and the GUC already defined. We */
+       /* can skip GUC definition in this case, so we just return. */
+       static const char *guc_name = "postgis.backend";
+       const char *guc_installed = GetConfigOption(guc_name, TRUE, FALSE);
+
+       /* Uh oh, this GUC name already exists. Ordinarily we could just go on */
+       /* our way, but the way the postgis.backend works is by using the "assign" */
+       /* callback to change which backend is in use by flipping a global variable */
+       /* over. This saves the overhead of looking up the engine every time, at */
+       /* the expense of the extra complexity. */
+       if ( guc_installed )
+       {
+               /* 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 currently set to '%s' and cannot be changed until you reconnect", guc_name, guc_installed);
+               return;
+       }
+
+       /* Good, the GUC name is not already in use, so this must be a fresh */
+       /* and clean new load of the library, and we can define the user GUC */
+       DefineCustomStringVariable( guc_name, /* name */
                                "Sets the PostGIS Geometry Backend.", /* short_desc */
                                "Sets the PostGIS Geometry Backend (allowed values are 'geos' or 'sfcgal')", /* long_desc */
                                &lwgeom_backend_name, /* valueAddr */