From dd5b4c8349f442156718deac7cf41f64f98152d7 Mon Sep 17 00:00:00 2001 From: Craig Ringer Date: Wed, 14 May 2014 18:51:05 +0800 Subject: [PATCH] bdr: Better error message on slot creation for db where bdr not active 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/contrib/bdr/bdr_catalogs.c b/contrib/bdr/bdr_catalogs.c index b96c5c706d..3641cbc99d 100644 --- a/contrib/bdr/bdr_catalogs.c +++ b/contrib/bdr/bdr_catalogs.c @@ -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)); -- 2.39.5