bdr: Rewrote lookup code for bdr.bdr_queued_commands
authorChristian Kruse <[email protected]>
Thu, 20 Mar 2014 17:50:39 +0000 (18:50 +0100)
committerAndres Freund <[email protected]>
Thu, 3 Jul 2014 15:55:21 +0000 (17:55 +0200)
Now we're looking up the QueuedDDLCommandsRelid of
bdr.bdr_queued_commands in bdr_maintain_schema() using
get_namespace_oid() as well as get_relname_relid().

contrib/bdr/bdr.c
contrib/bdr/bdr.h
contrib/bdr/bdr_apply.c

index c6e2a4e586f296d94b10fc04a185a3e677153cf1..cc0657cdd32070de90142b1d160b1e0137eb2c2b 100644 (file)
@@ -31,6 +31,7 @@
 #include "access/committs.h"
 #include "access/heapam.h"
 #include "access/xact.h"
+#include "catalog/namespace.h"
 #include "catalog/pg_extension.h"
 #include "catalog/pg_index.h"
 #include "catalog/catversion.h"
@@ -41,6 +42,7 @@
 #include "replication/replication_identifier.h"
 #include "utils/builtins.h"
 #include "utils/guc.h"
+#include "utils/lsyscache.h"
 #include "utils/memutils.h"
 #include "utils/snapmgr.h"
 #include "utils/timestamp.h"
@@ -425,9 +427,6 @@ bdr_apply_main(Datum main_arg)
 
    replication_origin_id = replication_identifier;
 
-   /* setup initial queued_cmds OID */
-   setup_queuedcmds_relid();
-
    while (!got_sigterm)
    {
        /* int       ret; */
@@ -838,6 +837,7 @@ bdr_maintain_schema(void)
 {
    Relation extrel;
    Oid     extoid;
+   Oid         schema_oid;
 
    StartTransactionCommand();
    PushActiveSnapshot(GetTransactionSnapshot());
@@ -875,6 +875,16 @@ bdr_maintain_schema(void)
 
    heap_close(extrel, NoLock);
 
+   /* setup initial queued_cmds OID */
+   schema_oid = get_namespace_oid("bdr", false);
+   if (schema_oid != InvalidOid)
+   {
+       QueuedDDLCommandsRelid = get_relname_relid("bdr_queued_commands",
+                                                  schema_oid);
+   }
+
+   elog(LOG, "bdr.bdr_queued_commands OID set to %u", QueuedDDLCommandsRelid);
+
    PopActiveSnapshot();
    CommitTransactionCommand();
 }
index 0b836577502f79ef93e8fe274eeccb1ccc2f4483..dbb4f79798036c0072b813e97531939c82e1677f 100644 (file)
@@ -48,6 +48,9 @@ extern ResourceOwner bdr_saved_resowner;
 extern BDRWorkerCon *bdr_apply_con;
 extern BDRSequencerCon *bdr_sequencer_con;
 
+/* DDL replication support */
+extern Oid QueuedDDLCommandsRelid;
+
 /* apply support */
 extern void process_remote_begin(StringInfo s);
 extern void process_remote_commit(StringInfo s);
@@ -69,9 +72,6 @@ extern void bdr_sequence_alloc(PG_FUNCTION_ARGS);
 extern void bdr_sequence_setval(PG_FUNCTION_ARGS);
 extern Datum bdr_sequence_options(PG_FUNCTION_ARGS);
 
-/* DDL replication support */
-extern void setup_queuedcmds_relid(void);
-
 /* statistic functions */
 extern void bdr_count_shmem_init(size_t nnodes);
 extern void bdr_count_set_current_node(RepNodeId node_id);
index 1ff969d0bdb4a71a25b59661b557b88aa21a2627..c1e235e0ae1a89b9c30b0845cdad725d14df8647 100644 (file)
@@ -70,7 +70,7 @@ static void tuple_to_stringinfo(StringInfo s, TupleDesc tupdesc, HeapTuple tuple
 static void check_sequencer_wakeup(Relation rel);
 
 bool request_sequencer_wakeup = false;
-static Oid     QueuedDDLCommandsRelid = InvalidOid;
+Oid            QueuedDDLCommandsRelid = InvalidOid;
 
 void
 process_remote_begin(StringInfo s)
@@ -1058,45 +1058,3 @@ find_pkey_tuple(ScanKey skey, Relation rel, Relation idxrel,
 
    return tuple;
 }
-
-void
-setup_queuedcmds_relid(void)
-{
-   Datum   oid;
-   int     ret;
-   bool    isnull;
-
-   StartTransactionCommand();
-   SPI_connect();
-   PushActiveSnapshot(GetTransactionSnapshot());
-
-   ret = SPI_execute("SELECT oid FROM pg_class "
-                     "WHERE oid = 'bdr.bdr_queued_commands'::regclass",
-                     true, 0);
-   if (ret != SPI_OK_SELECT)
-       goto failed;
-
-   if (SPI_processed != 1)
-       goto failed;
-
-   oid = SPI_getbinval(SPI_tuptable->vals[0],
-                       SPI_tuptable->tupdesc,
-                       1, &isnull);
-   if (isnull)
-       goto failed;
-
-   if (true)
-       QueuedDDLCommandsRelid = DatumGetObjectId(oid);
-   else
-   {
-failed:
-       QueuedDDLCommandsRelid = InvalidOid;
-   }
-
-   SPI_finish();
-   PopActiveSnapshot();
-   CommitTransactionCommand();
-   pgstat_report_activity(STATE_IDLE, NULL);
-
-   elog(LOG, "bdr.bdr_queued_commands OID set to %u", QueuedDDLCommandsRelid);
-}