Initialise PGXCNodeIdentifier as part of multi-executor setup
authorPavan Deolasee <[email protected]>
Fri, 7 Dec 2018 02:52:48 +0000 (08:22 +0530)
committerPavan Deolasee <[email protected]>
Fri, 7 Dec 2018 02:52:48 +0000 (08:22 +0530)
We used to do this while creating a portal. It's not clear why that place was
chosen by the original author, but it seems more logical to do so while setting
up multi-node execution environment. This also solves the problem of a parallel
worker not seeing the correct state, as reported by Virendra Kumar.

src/backend/pgxc/pool/pgxcnode.c
src/backend/postmaster/postmaster.c
src/backend/utils/mmgr/portalmem.c

index d59e9cd7f790adc0ef6d5a260271b41a1cebdbe1..1c4409708bced151b740ebf51afbcd92d3aa7132 100644 (file)
@@ -181,6 +181,16 @@ static List        *local_param_list = NIL;
 static StringInfo      session_params;
 static StringInfo      local_params;
 
+char           *PGXCNodeName = NULL;
+int                    PGXCNodeId = 0;
+
+/*
+ * When a particular node starts up, store the node identifier in this variable
+ * so that we dont have to calculate it OR do a search in cache any where else
+ * This will have minimal impact on performance
+ */
+uint32                 PGXCNodeIdentifier = 0;
+
 typedef struct
 {
        NameData name;
@@ -252,6 +262,7 @@ InitMultinodeExecutor(bool is_force)
        int                             count;
        Oid                             *coOids, *dnOids;
        MemoryContext   oldcontext;
+       char                    *node_name;
 
        /* Free all the existing information first */
        if (is_force)
@@ -268,6 +279,11 @@ InitMultinodeExecutor(bool is_force)
        /* Get classified list of node Oids */
        PgxcNodeGetOids(&coOids, &dnOids, &NumCoords, &NumDataNodes, true);
 
+       /* Initialise node identifier */
+       node_name = str_tolower(PGXCNodeName, strlen(PGXCNodeName), DEFAULT_COLLATION_OID);
+       PGXCNodeIdentifier = get_pgxc_node_id(get_pgxc_nodeoid(node_name));
+       pfree(node_name);
+
        /*
         * Coordinator and datanode handles should be available during all the
         * session lifetime
index dd45c638c4f8134b9a8e5a46b7ff8fe9099b10a4..c4a258452df19c20fd543cc4f5ee861d66c68d4c 100644 (file)
@@ -405,17 +405,6 @@ static bool LoadedSSL = false;
 static DNSServiceRef bonjour_sdref = NULL;
 #endif
 
-#ifdef PGXC
-char                   *PGXCNodeName = NULL;
-int                    PGXCNodeId = 0;
-/*
- * When a particular node starts up, store the node identifier in this variable
- * so that we dont have to calculate it OR do a search in cache any where else
- * This will have minimal impact on performance
- */
-uint32                 PGXCNodeIdentifier = 0;
-#endif
-
 /*
  * postmaster.c - function prototypes
  */
index aa61b52de0282f965882c3264c2d880dc5fee159..dffcd62624cc69f014af28fa35301754c1c0f84f 100644 (file)
@@ -237,19 +237,9 @@ CreatePortal(const char *name, bool allowDup, bool dupSilent)
        /* put portal in table (sets portal->name) */
        PortalHashTableInsert(portal, name);
 
-#ifdef PGXC
        elog(DEBUG3, "Created portal %s and inserted an entry in the has table",
                        name);
 
-       if (PGXCNodeIdentifier == 0)
-       {
-               char *node_name;
-               node_name = str_tolower(PGXCNodeName, strlen(PGXCNodeName), DEFAULT_COLLATION_OID);
-               PGXCNodeIdentifier = get_pgxc_node_id(get_pgxc_nodeoid(node_name));
-               pfree(node_name);
-       }
-#endif
-
        return portal;
 }