Extend the array for various slave variables to match the size of the master
authorPavan Deolasee <[email protected]>
Fri, 1 Apr 2016 06:26:57 +0000 (11:56 +0530)
committerPavan Deolasee <[email protected]>
Tue, 18 Oct 2016 10:05:04 +0000 (15:35 +0530)
array.

This fixes the problem when a slave for only one master datanode or coordinator
is added, as demonstrated by the tap tests

contrib/pgxc_ctl/coord_cmd.c
contrib/pgxc_ctl/datanode_cmd.c

index c3c67520adfa3518ffdc1e217bc8485585b98579..de4d622f6e5fcd184f1439ce53b8de75e3081da0 100644 (file)
@@ -1248,6 +1248,7 @@ int add_coordinatorSlave(char *name, char *host, int port, int pooler_port, char
        char port_s[MAXTOKEN+1];
        char pooler_s[MAXTOKEN+1];
        int kk;
+       int size;
 
        /* Check if the name is valid coordinator */
        if ((idx = coordIdx(name)) < 0)
@@ -1338,23 +1339,24 @@ int add_coordinatorSlave(char *name, char *host, int port, int pooler_port, char
                        sval(VAR_pgxcOwner), getIpAddress(host));
        pclose(f);
        /* Reconfigure pgxc_ctl configuration with the new slave */
+       size = arraySizeName(VAR_coordNames);
        /* Need an API to expand the array to desired size */
-       if ((extendVar(VAR_coordSlaveServers, idx + 1, "none") != 0) ||
-               (extendVar(VAR_coordSlaveDirs, idx + 1, "none")  != 0) ||
-               (extendVar(VAR_coordSlavePorts, idx + 1, "none")  != 0) ||
-               (extendVar(VAR_coordSlavePoolerPorts, idx + 1, "none")  != 0) ||
-               (extendVar(VAR_coordArchLogDirs, idx + 1, "none") != 0))
+       if ((extendVar(VAR_coordSlaveServers, size, "none") != 0) ||
+               (extendVar(VAR_coordSlaveDirs, size, "none")  != 0) ||
+               (extendVar(VAR_coordSlavePorts, size, "none")  != 0) ||
+               (extendVar(VAR_coordSlavePoolerPorts, size, "none")  != 0) ||
+               (extendVar(VAR_coordArchLogDirs, size, "none") != 0))
        {
                elog(PANIC, "PANIC: Internal error, inconsistent coordinator information\n");
                return 1;
        }
        if (!isVarYes(VAR_coordSlave))
                assign_sval(VAR_coordSlave, "y");
-       assign_arrayEl(VAR_coordSlaveServers, idx, host, NULL);
-       assign_arrayEl(VAR_coordSlavePorts, idx, port_s, NULL);
-       assign_arrayEl(VAR_coordSlavePoolerPorts, idx, pooler_s, NULL);
-       assign_arrayEl(VAR_coordSlaveDirs, idx, dir, NULL);
-       assign_arrayEl(VAR_coordArchLogDirs, idx, archDir, NULL);
+       replace_arrayEl(VAR_coordSlaveServers, idx, host, NULL);
+       replace_arrayEl(VAR_coordSlavePorts, idx, port_s, NULL);
+       replace_arrayEl(VAR_coordSlavePoolerPorts, idx, pooler_s, NULL);
+       replace_arrayEl(VAR_coordSlaveDirs, idx, dir, NULL);
+       replace_arrayEl(VAR_coordArchLogDirs, idx, archDir, NULL);
        /* Update the configuration file and backup it */
        if ((f = fopen(pgxc_ctl_config_path, "a")) == NULL)
        {
index c9d4731ba2c854126d487ff5bc178470c77aef24..3d639ff79c360f9784593c4601d9c3ea124f36a1 100644 (file)
@@ -1299,6 +1299,7 @@ int add_datanodeSlave(char *name, char *host, int port, int pooler, char *dir,
     char pooler_s[MAXTOKEN+1];
        int kk;
        bool wal;
+       int size;
 
        if (walDir && (strcasecmp(walDir, "none") != 0))
                wal = true;
@@ -1396,12 +1397,15 @@ int add_datanodeSlave(char *name, char *host, int port, int pooler, char *dir,
                        "# End of addition ===============================\n",
                        sval(VAR_pgxcOwner), getIpAddress(host));
        pclose(f);
+
+       size = arraySizeName(VAR_datanodeNames);
        /* Need an API to expand the array to desired size */
-       if ((extendVar(VAR_datanodeSlaveServers, idx + 1, "none") != 0) ||
-               (extendVar(VAR_datanodeSlavePorts, idx + 1, "none")  != 0) ||
-               (extendVar(VAR_datanodeSlavePoolerPorts, idx + 1, "none")  != 0) ||
-               (extendVar(VAR_datanodeSlaveDirs, idx + 1, "none")  != 0) ||
-               (extendVar(VAR_datanodeArchLogDirs, idx + 1, "none") != 0))
+       if ((extendVar(VAR_datanodeSlaveServers, size, "none") != 0) ||
+               (extendVar(VAR_datanodeSlavePorts, size, "none")  != 0) ||
+               (extendVar(VAR_datanodeSlavePoolerPorts, size, "none")  != 0) ||
+               (extendVar(VAR_datanodeSlaveDirs, size, "none")  != 0) ||
+               (extendVar(VAR_datanodeSlaveWALDirs, size, "none")  != 0) ||
+               (extendVar(VAR_datanodeArchLogDirs, size, "none") != 0))
        {
                elog(PANIC, "PANIC: Internal error, inconsistent datanode information\n");
                return 1;
@@ -1413,12 +1417,12 @@ int add_datanodeSlave(char *name, char *host, int port, int pooler, char *dir,
 
        if (!isVarYes(VAR_datanodeSlave))
                assign_sval(VAR_datanodeSlave, "y");
-       assign_arrayEl(VAR_datanodeSlaveServers, idx, host, NULL);
-       assign_arrayEl(VAR_datanodeSlavePorts, idx, port_s, NULL);
-       assign_arrayEl(VAR_datanodeSlavePoolerPorts, idx, pooler_s, NULL);
-       assign_arrayEl(VAR_datanodeSlaveDirs, idx, dir, NULL);
-       assign_arrayEl(VAR_datanodeSlaveWALDirs, idx, walDir, NULL);
-       assign_arrayEl(VAR_datanodeArchLogDirs, idx, archDir, NULL);
+       replace_arrayEl(VAR_datanodeSlaveServers, idx, host, NULL);
+       replace_arrayEl(VAR_datanodeSlavePorts, idx, port_s, NULL);
+       replace_arrayEl(VAR_datanodeSlavePoolerPorts, idx, pooler_s, NULL);
+       replace_arrayEl(VAR_datanodeSlaveDirs, idx, dir, NULL);
+       replace_arrayEl(VAR_datanodeSlaveWALDirs, idx, walDir, NULL);
+       replace_arrayEl(VAR_datanodeArchLogDirs, idx, archDir, NULL);
        /* Update the configuration file and backup it */
        if ((f = fopen(pgxc_ctl_config_path, "a")) == NULL)
        {