bdr: Better error message on slot creation for db where bdr not active
authorCraig Ringer <craig@2ndquadrant.com>
Wed, 14 May 2014 10:51:05 +0000 (18:51 +0800)
committerAndres Freund <andres@anarazel.de>
Thu, 3 Jul 2014 15:55:36 +0000 (17:55 +0200)
We want to block slot creation on a database where there's no active
bdr connection configured for that db. Test to see whether there's a
bdr schema and refuse to create a slot in this case.

Doesn't protect against bdr being enabled then disabled, but nothing
exciting will happen in that case anyway.

contrib/bdr/bdr_catalogs.c

index b96c5c706daefce0c344b35000d3084d34da601b..3641cbc99d13600a7bc6d35f52767abc7f552144 100644 (file)
@@ -25,6 +25,7 @@
 #include "executor/spi.h"
 
 #include "utils/builtins.h"
+#include "utils/syscache.h"
 
 /*
  * Get the bdr.bdr_nodes status value for the current local node from the local
@@ -43,12 +44,27 @@ bdr_nodes_get_local_status(uint64 sysid, Name dbname)
    bool        isnull;
    char        status;
    char        sysid_str[33];
+   Oid         schema_oid;
 
    Assert(IsTransactionState());
 
    snprintf(sysid_str, sizeof(sysid_str), UINT64_FORMAT, sysid);
    sysid_str[sizeof(sysid_str)-1] = '\0';
 
+   /*
+    * Determine if BDR is present on this DB. The output plugin can
+    * be started on a db that doesn't actually have BDR active, but
+    * we don't want to allow that.
+    *
+    * Check for a bdr schema.
+    */
+   schema_oid = GetSysCacheOid1(NAMESPACENAME, CStringGetDatum("bdr"));
+   if (schema_oid == InvalidOid)
+       ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+               errmsg("No bdr schema is present in database %s, cannot create a bdr_output slot",
+                      NameStr(*dbname)),
+               errhint("There is no bdr.bdr_connections entry for this database on the target node or bdr is not in shared_preload_libraries")));
+
    values[0] = DirectFunctionCall3Coll(numeric_in, InvalidOid,
                                        CStringGetDatum(sysid_str),
                                        InvalidOid, Int32GetDatum(-1));