Move several functions from pgxcnode.c to poolmgr.c
authorTomas Vondra <[email protected]>
Sat, 4 Nov 2017 14:52:13 +0000 (15:52 +0100)
committerTomas Vondra <[email protected]>
Sat, 4 Nov 2017 16:23:11 +0000 (17:23 +0100)
A number of functions were defined in pgxcnode.h/pgxnnode.h, but
only ever used in poolmgr.c. Those are:

- PGXCNodeConnect    - open libpq connection using conn. string
- PGXCNodePing       - ping node using connection string
- PGXCNodeClose      - close libpq connection
- PGXCNodeConnected  - verify connection status
- PGXCNodeConnStr    - build connection string

So move them to poolmgr.c and make them static, so that poolmgr
is the only part dealing with libpq connections directly.

src/backend/pgxc/pool/pgxcnode.c
src/backend/pgxc/pool/poolmgr.c
src/include/pgxc/pgxcnode.h
src/include/pgxc/poolmgr.h

index a664cc22dae9537c63f915d555fcff1820721d5d..f6dfd2a48c6b546b3ab1f7a9e368b000782a9e2d 100644 (file)
  * release_handles     - release all connection (back to pool)
  *
  *
- * connection functions (TODO move to poolmgr.c)
- * --------------------
- * PGXCNodeConnect    - open libpq connection using connection string
- * PGXCNodePing       - ping node using connection string
- * PGXCNodeClose      - close libpq connection
- * PGXCNodeConnected  - verify connection status
- * PGXCNodeConnStr    - build connection string
- *
- *
  * node handle management
  * ----------------------
  * PGXCNodeGetNodeOid        - OID for node by index in handle array
@@ -356,109 +347,6 @@ InitMultinodeExecutor(bool is_force)
        }
 }
 
-/*
- * PGXCNodeConnStr
- *       Builds a connection string for the provided connection parameters.
- *
- * Aside from the usual connection parameters (host, port, ...) we also
- * pass information about type of the parent node and remote node type.
- *
- * XXX Shouldn't this rather throw an ERROR instead of returning NULL?
- */
-char *
-PGXCNodeConnStr(char *host, int port, char *dbname,
-                               char *user, char *pgoptions, char *remote_type, char *parent_node)
-{
-       char       *out,
-                               connstr[1024];
-       int                     num;
-
-       /*
-        * Build up connection string
-        * remote type can be Coordinator, Datanode or application.
-        *
-        * XXX What's application remote type?
-        */
-       num = snprintf(connstr, sizeof(connstr),
-                                  "host=%s port=%d dbname=%s user=%s application_name='pgxc:%s' sslmode=disable options='-c remotetype=%s -c parentnode=%s %s'",
-                                  host, port, dbname, user, parent_node, remote_type, parent_node,
-                                  pgoptions);
-
-       /* Check for overflow */
-       if (num > 0 && num < sizeof(connstr))
-       {
-               /* Output result */
-               out = (char *) palloc(num + 1);
-               strcpy(out, connstr);
-               return out;
-       }
-
-       /* return NULL if we have problem */
-       return NULL;
-}
-
-
-/*
- * PGXCNodeConnect
- *       Connect to a Datanode using a constructed connection string.
- */
-NODE_CONNECTION *
-PGXCNodeConnect(char *connstr)
-{
-       PGconn     *conn;
-
-       /* Delegate call to the pglib */
-       conn = PQconnectdb(connstr);
-       return (NODE_CONNECTION *) conn;
-}
-
-/*
- * PGXCNodePing
- *       Check that a node (identified the connstring) responds correctly.
- */
-int
-PGXCNodePing(const char *connstr)
-{
-       if (connstr[0])
-       {
-               PGPing status = PQping(connstr);
-               if (status == PQPING_OK)
-                       return 0;
-               else
-                       return 1;
-       }
-       else
-               return -1;
-}
-
-/*
- * PGXCNodeClose
- *       Close connection connection.
- */
-void
-PGXCNodeClose(NODE_CONNECTION *conn)
-{
-       /* Delegate call to the libpq */
-       PQfinish((PGconn *) conn);
-}
-
-/*
- * PGXCNodeConnected
- *       Check if the provided connection is open and valid.
- */
-int
-PGXCNodeConnected(NODE_CONNECTION *conn)
-{
-       PGconn     *pgconn = (PGconn *) conn;
-
-       /*
-        * Simple check, want to do more comprehencive -
-        * check if it is ready for guery
-        */
-       return pgconn && PQstatus(pgconn) == CONNECTION_OK;
-}
-
-
 /*
  * pgxc_node_free
  *       Close the socket handle (local copy) and free occupied memory.
index 3722e9e04de77be665b919d0cf9cde4dd2474aa4..768ed80d7e7715fa4c5f7a8112eb0a69fb9328da 100644 (file)
  * - PoolManagerReloadConnectionInfo   close all connections
  *
  * There's a number of additional helper functions, but those are mostly
- * internal and marked as static.
+ * internal and marked as static. Example of such functions are functions
+ * constructing connection strings, opening/closing connections, pinging
+ * nodes, etc.
+ *
+ * - PGXCNodeConnect    - open libpq connection using connection string
+ * - PGXCNodePing       - ping node using connection string
+ * - PGXCNodeClose      - close libpq connection
+ * - PGXCNodeConnected  - verify connection status
+ * - PGXCNodeConnStr    - build connection string
  *
  *
  * XXX Why do we even need a separate connection pool manager? Can't we
  * constants (e.g. PoolManagerAbortTransactions uses 'a'). Perhaps
  * define this somewhere in a clear manner, e.g. like a #define.
  *
+ * XXX The PGXCNode* functions were originally placed in pgxcnode.c, but
+ * were moved into poolmgr as that's the only place using them. But the
+ * name still reflects the original location, so perhaps rename them?
+ *
+ *
  * Portions Copyright (c) 2012-2014, TransLattice, Inc.
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 2010-2012 Postgres-XC Development Group
@@ -382,6 +395,16 @@ static void pooler_sighup(SIGNAL_ARGS);
 
 static void TryPingUnhealthyNode(Oid nodeoid);
 
+/* Open/close connection routines (invoked from Pool Manager) */
+static char *PGXCNodeConnStr(char *host, int port, char *dbname, char *user,
+                                                        char *pgoptions,
+                                                        char *remote_type, char *parent_node);
+static NODE_CONNECTION *PGXCNodeConnect(char *connstr);
+static void PGXCNodeClose(NODE_CONNECTION * conn);
+static int PGXCNodeConnected(NODE_CONNECTION * conn);
+static int PGXCNodePing(const char *connstr);
+
+
 /*
  * Flags set by interrupt handlers for later service in the main loop.
  */
@@ -3651,3 +3674,105 @@ check_persistent_connections(bool *newval, void **extra, GucSource source)
        }
        return true;
 }
+
+/*
+ * PGXCNodeConnStr
+ *       Builds a connection string for the provided connection parameters.
+ *
+ * Aside from the usual connection parameters (host, port, ...) we also
+ * pass information about type of the parent node and remote node type.
+ *
+ * XXX Shouldn't this rather throw an ERROR instead of returning NULL?
+ */
+static char *
+PGXCNodeConnStr(char *host, int port, char *dbname,
+                               char *user, char *pgoptions, char *remote_type, char *parent_node)
+{
+       char       *out,
+                               connstr[1024];
+       int                     num;
+
+       /*
+        * Build up connection string
+        * remote type can be Coordinator, Datanode or application.
+        *
+        * XXX What's application remote type?
+        */
+       num = snprintf(connstr, sizeof(connstr),
+                                  "host=%s port=%d dbname=%s user=%s application_name='pgxc:%s' sslmode=disable options='-c remotetype=%s -c parentnode=%s %s'",
+                                  host, port, dbname, user, parent_node, remote_type, parent_node,
+                                  pgoptions);
+
+       /* Check for overflow */
+       if (num > 0 && num < sizeof(connstr))
+       {
+               /* Output result */
+               out = (char *) palloc(num + 1);
+               strcpy(out, connstr);
+               return out;
+       }
+
+       /* return NULL if we have problem */
+       return NULL;
+}
+
+
+/*
+ * PGXCNodeConnect
+ *       Connect to a Datanode using a constructed connection string.
+ */
+static NODE_CONNECTION *
+PGXCNodeConnect(char *connstr)
+{
+       PGconn     *conn;
+
+       /* Delegate call to the pglib */
+       conn = PQconnectdb(connstr);
+       return (NODE_CONNECTION *) conn;
+}
+
+/*
+ * PGXCNodePing
+ *       Check that a node (identified the connstring) responds correctly.
+ */
+static int
+PGXCNodePing(const char *connstr)
+{
+       if (connstr[0])
+       {
+               PGPing status = PQping(connstr);
+               if (status == PQPING_OK)
+                       return 0;
+               else
+                       return 1;
+       }
+       else
+               return -1;
+}
+
+/*
+ * PGXCNodeClose
+ *       Close connection connection.
+ */
+static void
+PGXCNodeClose(NODE_CONNECTION *conn)
+{
+       /* Delegate call to the libpq */
+       PQfinish((PGconn *) conn);
+}
+
+/*
+ * PGXCNodeConnected
+ *       Check if the provided connection is open and valid.
+ */
+static int
+PGXCNodeConnected(NODE_CONNECTION *conn)
+{
+       PGconn     *pgconn = (PGconn *) conn;
+
+       /*
+        * Simple check, want to do more comprehencive -
+        * check if it is ready for guery
+        */
+       return pgconn && PQstatus(pgconn) == CONNECTION_OK;
+}
index 13b52e802c772589049c3951fcc0958eab259c90..9f002ce3c3006a28939ee3b7d55643aa6af4b4df 100644 (file)
 
 #define NO_SOCKET -1
 
-/* Connection to Datanode maintained by Pool Manager */
-typedef struct PGconn NODE_CONNECTION;
-typedef struct PGcancel NODE_CANCEL;
-
 /* Helper structure to access Datanode from Session */
 typedef enum
 {
@@ -113,15 +109,7 @@ typedef struct
 extern void InitMultinodeExecutor(bool is_force);
 
 /* Open/close connection routines (invoked from Pool Manager) */
-extern char *PGXCNodeConnStr(char *host, int port, char *dbname, char *user,
-                                                        char *pgoptions,
-                                                        char *remote_type, char *parent_node);
-extern NODE_CONNECTION *PGXCNodeConnect(char *connstr);
-extern void PGXCNodeClose(NODE_CONNECTION * conn);
-extern int PGXCNodeConnected(NODE_CONNECTION * conn);
-extern int PGXCNodeConnClean(NODE_CONNECTION * conn);
 extern void PGXCNodeCleanAndRelease(int code, Datum arg);
-extern int PGXCNodePing(const char *connstr);
 
 extern PGXCNodeHandle *get_any_handle(List *datanodelist);
 /* Look at information cached in node handles */
index 3c2d1f4eb2db7c5591858b29984f9a3e718a6b0e..c7f93433937453fcc5ca4c187a360b73962af77b 100644 (file)
 
 #define MAX_IDLE_TIME 60
 
+/* Connection to nodes maintained by Pool Manager */
+typedef struct PGconn NODE_CONNECTION;
+typedef struct PGcancel NODE_CANCEL;
+
 /*
  * One connection in the pool (to datanode or coordinator).
  *