summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavan Deolasee2014-08-03 10:42:12 +0000
committerPavan Deolasee2014-09-01 14:20:30 +0000
commit3a690a1239a9cf60fe765a594eeccc0f94987dcb (patch)
treec371c4caadd8780bc0905ef0b4065d4b57b47b3d
parent2494b287580267b265c73422f68d2cba52fa467c (diff)
Ensure the variable array is adjusted to the right size while adding new
members. The extendVar API is now fixed so that it takes the desired array size as an argument and enlarges the array to newSize + 1, if necessary. The last element in the array stores a NULL pointer as an end-of-array marker. We could instead use the val_used struct member, but that would require changes to several places because the code kind of assumes the last element to be NULL pointer to loop through the array elements
-rw-r--r--contrib/pgxc_ctl/coord_cmd.c27
-rw-r--r--contrib/pgxc_ctl/datanode_cmd.c38
-rw-r--r--contrib/pgxc_ctl/variables.c32
-rw-r--r--contrib/pgxc_ctl/variables.h15
4 files changed, 86 insertions, 26 deletions
diff --git a/contrib/pgxc_ctl/coord_cmd.c b/contrib/pgxc_ctl/coord_cmd.c
index bf3f60fee5..5a0d4a0dce 100644
--- a/contrib/pgxc_ctl/coord_cmd.c
+++ b/contrib/pgxc_ctl/coord_cmd.c
@@ -974,6 +974,23 @@ int add_coordinatorMaster(char *name, char *host, int port, int pooler, char *di
/*
* Now reconfigure
*/
+ /* Need an API to expand the array to desired size */
+ if ((extendVar(VAR_coordNames, idx + 1, "none") != 0) ||
+ (extendVar(VAR_coordMasterServers, idx + 1, "none") != 0) ||
+ (extendVar(VAR_coordPorts, idx + 1, "none") != 0) ||
+ (extendVar(VAR_poolerPorts, idx + 1, "none") != 0) ||
+ (extendVar(VAR_coordMasterDirs, idx + 1, "none") != 0) ||
+ (extendVar(VAR_coordMaxWALSenders, idx + 1, "none") != 0) ||
+ (extendVar(VAR_coordSlaveServers, idx + 1, "none") != 0) ||
+ (extendVar(VAR_coordSlavePorts, idx + 1, "none") != 0) ||
+ (extendVar(VAR_coordSlaveDirs, idx + 1, "none") != 0) ||
+ (extendVar(VAR_coordArchLogDirs, idx + 1, "none") != 0) ||
+ (extendVar(VAR_coordSpecificExtraConfig, idx + 1, "none") != 0) ||
+ (extendVar(VAR_coordSpecificExtraPgHba, idx + 1, "none") != 0))
+ {
+ elog(PANIC, "PANIC: Internal error, inconsitent coordinator information\n");
+ return 1;
+ }
/*
* 000 We need another way to configure specific pg_hba.conf and max_wal_senders.
*/
@@ -1245,11 +1262,11 @@ int add_coordinatorSlave(char *name, char *host, int port, int pooler_port, char
pclose(f);
/* Reconfigure pgxc_ctl configuration with the new slave */
/* Need an API to expand the array to desired size */
- if ((extendVar(VAR_coordSlaveServers, idx, "none") != 0) ||
- (extendVar(VAR_coordSlaveDirs, idx, "none") != 0) ||
- (extendVar(VAR_coordSlavePorts, idx, "none") != 0) ||
- (extendVar(VAR_coordSlavePoolerPorts, idx, "none") != 0) ||
- (extendVar(VAR_coordArchLogDirs, idx, "none") != 0))
+ 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))
{
elog(PANIC, "PANIC: Internal error, inconsitent coordinator information\n");
return 1;
diff --git a/contrib/pgxc_ctl/datanode_cmd.c b/contrib/pgxc_ctl/datanode_cmd.c
index abfec7d48c..c4547ec8c6 100644
--- a/contrib/pgxc_ctl/datanode_cmd.c
+++ b/contrib/pgxc_ctl/datanode_cmd.c
@@ -974,6 +974,30 @@ int add_datanodeMaster(char *name, char *host, int port, char *dir, char *restor
elog(ERROR, "ERROR: sorry found some inconflicts in datanode master configuration.\n");
return 1;
}
+
+ if ((extendVar(VAR_datanodeNames, idx + 1, "none") != 0) ||
+ (extendVar(VAR_datanodeMasterServers, idx + 1, "none") != 0) ||
+ (extendVar(VAR_datanodePorts, idx + 1, "none") != 0) ||
+#ifdef XCP
+ (extendVar(VAR_datanodePoolerPorts, idx + 1, "none") != 0) ||
+#endif
+ (extendVar(VAR_datanodeMasterDirs, idx + 1, "none") != 0) ||
+ (extendVar(VAR_datanodeMaxWALSenders, idx + 1, "none") != 0) ||
+ (extendVar(VAR_datanodeSlaveServers, idx + 1, "none") != 0) ||
+ (extendVar(VAR_datanodeSlavePorts, idx + 1, "none") != 0) ||
+#ifdef XCP
+ (extendVar(VAR_datanodeSlavePoolerPorts, idx + 1, "none") != 0) ||
+#endif
+ (extendVar(VAR_datanodeSlaveDirs, idx + 1, "none") != 0) ||
+ (extendVar(VAR_datanodeArchLogDirs, idx + 1, "none") != 0) ||
+ (extendVar(VAR_datanodeSpecificExtraConfig, idx + 1, "none") != 0) ||
+ (extendVar(VAR_datanodeSpecificExtraPgHba, idx + 1, "none") != 0))
+ {
+ elog(PANIC, "PANIC: Internal error, inconsitent datanode information\n");
+ return 1;
+ }
+
+
/*
* Now reconfigure
*/
@@ -1282,18 +1306,20 @@ int add_datanodeSlave(char *name, char *host, int port, int pooler, char *dir, c
timeStampString(date, MAXPATH),
sval(VAR_pgxcOwner), getIpAddress(host));
pclose(f);
- /* Reconfigure pgxc_ctl configuration with the new slave */
-#if 0
/* Need an API to expand the array to desired size */
- if ((extendVar(VAR_datanodeSlaveServers, idx, "none") != 0) ||
- (extendVar(VAR_datanodeSlaveDirs, idx, "none") != 0) ||
- (extendVar(VAR_datanodeArchLogDirs, idx, "none") != 0))
+ if ((extendVar(VAR_datanodeSlaveServers, idx + 1, "none") != 0) ||
+ (extendVar(VAR_datanodeSlavePorts, idx + 1, "none") != 0) ||
+#ifdef XCP
+ (extendVar(VAR_datanodeSlavePoolerPorts, idx + 1, "none") != 0) ||
+#endif
+ (extendVar(VAR_datanodeSlaveDirs, idx + 1, "none") != 0) ||
+ (extendVar(VAR_datanodeArchLogDirs, idx + 1, "none") != 0))
{
elog(PANIC, "PANIC: Internal error, inconsitent datanode information\n");
return 1;
}
-#endif
+ /* Reconfigure pgxc_ctl configuration with the new slave */
snprintf(port_s, MAXTOKEN, "%d", port);
#ifdef XCP
snprintf(pooler_s, MAXTOKEN, "%d", pooler);
diff --git a/contrib/pgxc_ctl/variables.c b/contrib/pgxc_ctl/variables.c
index 09f01e7f8f..59771202ff 100644
--- a/contrib/pgxc_ctl/variables.c
+++ b/contrib/pgxc_ctl/variables.c
@@ -387,6 +387,10 @@ int IfExists(char *name, char *value)
return FALSE;
}
+/*
+ * Extend the variable values array to newSize (plus 1 for store the
+ * end-of-array marker
+ */
int extendVar(char *name, int newSize, char *def_value)
{
pgxc_ctl_var *target;
@@ -398,24 +402,28 @@ int extendVar(char *name, int newSize, char *def_value)
return -1;
if (def_value == NULL)
def_value = "none";
- if (target->val_size < newSize)
+
+ /*
+ * If the allocated array is not already big enough to store newSize + 1
+ * elements, we must extend it newSize + 1
+ */
+ if (target->val_size <= newSize)
{
old_val = target->val;
old_size = target->val_size;
- target->val = Malloc0(sizeof(char *) * (newSize +1));
+ target->val = Malloc0(sizeof(char *) * (newSize + 1));
memcpy(target->val, old_val, sizeof(char *) * old_size);
- target->val_size = newSize;
+ target->val_size = newSize + 1;
Free(old_val);
- for (ii = target->val_used; ii < newSize; ii++)
- (target->val)[ii] = Strdup(def_value);
- target->val_used = newSize;
- }
- else if (target->val_used < newSize)
- {
- for (ii = target->val_used; ii < newSize; ii++)
- (target->val)[ii] = Strdup(def_value);
- target->val_used = newSize;
}
+
+ for (ii = target->val_used; ii < newSize; ii++)
+ (target->val)[ii] = Strdup(def_value);
+
+ /* Store NULL in the last element to mark the end-of-array */
+ (target->val)[newSize] = NULL;
+ target->val_used = newSize;
+
return 0;
}
diff --git a/contrib/pgxc_ctl/variables.h b/contrib/pgxc_ctl/variables.h
index 6998277e04..3821066864 100644
--- a/contrib/pgxc_ctl/variables.h
+++ b/contrib/pgxc_ctl/variables.h
@@ -19,9 +19,18 @@ typedef struct pgxc_ctl_var {
struct pgxc_ctl_var *next;
struct pgxc_ctl_var *prev;
char *varname;
- int val_size;
- int val_used;
- char **val;
+ int val_size; /*
+ * current size of the allocated array including
+ * place to store the NULL pointer as an
+ * end-of-array marker
+ */
+
+ int val_used; /* currently used values */
+
+ char **val; /*
+ * max (val_size - 1) values and NULL as the last
+ * element
+ */
} pgxc_ctl_var;