diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-04-07 00:11:01 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-04-07 00:12:02 -0400 |
commit | 2594cf0e8c04406ffff19b1651c5a406d376657c (patch) | |
tree | 8ced737d26b54f4499a8029d8cad0ab42fc83ba3 /src/backend/utils/cache/ts_cache.c | |
parent | 5d0e462366f4521e37744fdb42fed3c6819a3374 (diff) | |
download | postgresql-2594cf0e8c04406ffff19b1651c5a406d376657c.tar.gz postgresql-2594cf0e8c04406ffff19b1651c5a406d376657c.zip |
Revise the API for GUC variable assign hooks.
The previous functions of assign hooks are now split between check hooks
and assign hooks, where the former can fail but the latter shouldn't.
Aside from being conceptually clearer, this approach exposes the
"canonicalized" form of the variable value to guc.c without having to do
an actual assignment. And that lets us fix the problem recently noted by
Bernd Helmle that the auto-tune patch for wal_buffers resulted in bogus
log messages about "parameter "wal_buffers" cannot be changed without
restarting the server". There may be some speed advantage too, because
this design lets hook functions avoid re-parsing variable values when
restoring a previous state after a rollback (they can store a pre-parsed
representation of the value instead). This patch also resolves a
longstanding annoyance about custom error messages from variable assign
hooks: they should modify, not appear separately from, guc.c's own message
about "invalid parameter value".
Diffstat (limited to 'src/backend/utils/cache/ts_cache.c')
-rw-r--r-- | src/backend/utils/cache/ts_cache.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/backend/utils/cache/ts_cache.c b/src/backend/utils/cache/ts_cache.c index 6a99e78c6a4..fc93551d069 100644 --- a/src/backend/utils/cache/ts_cache.c +++ b/src/backend/utils/cache/ts_cache.c @@ -587,8 +587,9 @@ getTSCurrentConfig(bool emitError) return TSCurrentConfigCache; } -const char * -assignTSCurrentConfig(const char *newval, bool doit, GucSource source) +/* GUC check_hook for default_text_search_config */ +bool +check_TSCurrentConfig(char **newval, void **extra, GucSource source) { /* * If we aren't inside a transaction, we cannot do database access so @@ -601,10 +602,10 @@ assignTSCurrentConfig(const char *newval, bool doit, GucSource source) Form_pg_ts_config cfg; char *buf; - cfgId = get_ts_config_oid(stringToQualifiedNameList(newval), true); + cfgId = get_ts_config_oid(stringToQualifiedNameList(*newval), true); if (!OidIsValid(cfgId)) - return NULL; + return false; /* * Modify the actually stored value to be fully qualified, to ensure @@ -622,17 +623,20 @@ assignTSCurrentConfig(const char *newval, bool doit, GucSource source) ReleaseSysCache(tuple); /* GUC wants it malloc'd not palloc'd */ - newval = strdup(buf); + free(*newval); + *newval = strdup(buf); pfree(buf); - - if (doit && newval) - TSCurrentConfigCache = cfgId; - } - else - { - if (doit) - TSCurrentConfigCache = InvalidOid; + if (!newval) + return false; } - return newval; + return true; +} + +/* GUC assign_hook for default_text_search_config */ +void +assign_TSCurrentConfig(const char *newval, void *extra) +{ + /* Just reset the cache to force a lookup on first use */ + TSCurrentConfigCache = InvalidOid; } |