Skip to content

Commit

Permalink
support global SQL/MED cluster options
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Jelinek authored and markokr committed Aug 15, 2011
1 parent 8da208e commit f00da38
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,28 @@ extract_part_num(const char *partname, int *part_num)
return false;
}

/*
* Validate single cluster option
*/
static void
validate_cluster_option(const char *name, const char *arg)
{
const char **opt;

/* see that a valid config option is specified */
for (opt = cluster_config_options; *opt; opt++)
{
if (pg_strcasecmp(*opt, name) == 0)
break;
}

if (*opt == NULL)
elog(ERROR, "Pl/Proxy: invalid server option: %s", name);
else if (strspn(arg, "0123456789") != strlen(arg))
elog(ERROR, "Pl/Proxy: only integer options are allowed: %s=%s",
name, arg);
}

/*
* Validate the generic option given to servers or user mappings defined with
* plproxy foreign data wrapper. Raise an ERROR if the option or its value is
Expand Down Expand Up @@ -435,20 +457,7 @@ plproxy_fdw_validator(PG_FUNCTION_ARGS)
}
else
{
const char **opt;

/* see that a valid config option is specified */
for (opt = cluster_config_options; *opt; opt++)
{
if (pg_strcasecmp(*opt, def->defname) == 0)
break;
}

if (*opt == NULL)
elog(ERROR, "Pl/Proxy: invalid server option: %s", def->defname);
else if (strspn(arg, "0123456789") != strlen(arg))
elog(ERROR, "Pl/Proxy: only integer options are allowed: %s=%s",
def->defname, arg);
validate_cluster_option(def->defname, arg);
}
}
else if (catalog == UserMappingRelationId)
Expand All @@ -465,8 +474,7 @@ plproxy_fdw_validator(PG_FUNCTION_ARGS)
}
else if (catalog == ForeignDataWrapperRelationId)
{
/* At the moment there are no options to the fdw itself */
elog(WARNING, "Pl/Proxy: foreign data wrapper takes no options");
validate_cluster_option(def->defname, arg);
}
}

Expand Down Expand Up @@ -553,6 +561,16 @@ reload_sqlmed_cluster(ProxyFunction *func, ProxyCluster *cluster,
appendStringInfo(user_options, "%s='%s' ", def->defname, strVal(def->arg));
}

/*
* Collect the configuration definitions from foreign data wrapper.
*/
foreach(cell, fdw->options)
{
DefElem *def = lfirst(cell);

set_config_key(func, &cluster->config, def->defname, strVal(def->arg));
}

/*
* Collect the cluster configuration and partition definitions from foreign
* server options. At first pass just collect the cluster options and count
Expand Down

0 comments on commit f00da38

Please sign in to comment.