summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2012-10-03 06:27:01 +0000
committerMichael Paquier2012-10-03 06:27:01 +0000
commit42ddf37ca13aa27c1c8e20fabaedf3d943d8dabb (patch)
tree9423be9a9fa11229fcfb0b1a0d9f233a60158b12
parent9d3446d1829bdee8ae767936cb20f339f16f5655 (diff)
Allow primary node data modification with ALTER NODE
When trying to use ALTER NODE on a primary node, node manager was complaining about the fact that there cannot be two primary nodes even if the data altered was something else like host IP or port number. The origin of the error was the error handling of primary node inside node manager. For a newly-created node, it is checked with this new node is primary and an error is returned if there is already a node defined. For an altered node, it is checked if a node different than the one altered is primary and if yes an error is returned. This check was originally moved inside check_node_options but this was a bad bet as it decentralized the primary node error check which is really different for new and altered nodes.
-rw-r--r--src/backend/pgxc/nodemgr/nodemgr.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/backend/pgxc/nodemgr/nodemgr.c b/src/backend/pgxc/nodemgr/nodemgr.c
index 1d1b5fb1a1..ee5ef63efb 100644
--- a/src/backend/pgxc/nodemgr/nodemgr.c
+++ b/src/backend/pgxc/nodemgr/nodemgr.c
@@ -184,18 +184,14 @@ check_node_options(const char *node_name, List *options, char **node_host,
}
}
- /* Checks on primary and preferred nodes */
+ /* A primary node has to be a Datanode */
if (*is_primary && *node_type != PGXC_NODE_DATANODE)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("PGXC node %s: cannot be a primary node, it has to be a Datanode",
node_name)));
- if (*is_primary && OidIsValid(primary_data_node))
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("PGXC node %s: two nodes cannot be primary",
- node_name)));
+ /* A preferred node has to be a Datanode */
if (*is_preferred && *node_type != PGXC_NODE_DATANODE)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
@@ -524,6 +520,16 @@ PgxcNodeCreate(CreateNodeStmt *stmt)
node_id = generate_node_id(node_name);
/*
+ * Check that this node is not created as a primary if one already
+ * exists.
+ */
+ if (is_primary && OidIsValid(primary_data_node))
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("PGXC node %s: two nodes cannot be primary",
+ node_name)));
+
+ /*
* Then assign default values if necessary
* First for port.
*/
@@ -636,6 +642,19 @@ PgxcNodeAlter(AlterNodeStmt *stmt)
&node_port, &node_type,
&is_primary, &is_preferred);
+ /*
+ * Two nodes cannot be primary at the same time. If the primary
+ * node is this node itself, well there is no point in having an
+ * error.
+ */
+ if (is_primary &&
+ OidIsValid(primary_data_node) &&
+ node_id != primary_data_node)
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("PGXC node %s: two nodes cannot be primary",
+ node_name)));
+
/* Check type dependency */
if (node_type_old == PGXC_NODE_COORDINATOR &&
node_type == PGXC_NODE_DATANODE)