From 2594cf0e8c04406ffff19b1651c5a406d376657c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 7 Apr 2011 00:11:01 -0400 Subject: 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". --- src/backend/tcop/postgres.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/backend/tcop/postgres.c') diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 79c0f68966e..cc7945aeb66 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -2804,7 +2804,8 @@ RecoveryConflictInterrupt(ProcSignalReason reason) break; default: - elog(FATAL, "Unknown conflict mode"); + elog(FATAL, "unrecognized conflict mode: %d", + (int) reason); } Assert(RecoveryConflictPending && (QueryCancelPending || ProcDiePending)); @@ -3062,27 +3063,32 @@ check_stack_depth(void) #endif /* IA64 */ } -/* GUC assign hook for max_stack_depth */ +/* GUC check hook for max_stack_depth */ bool -assign_max_stack_depth(int newval, bool doit, GucSource source) +check_max_stack_depth(int *newval, void **extra, GucSource source) { - long newval_bytes = newval * 1024L; + long newval_bytes = *newval * 1024L; long stack_rlimit = get_stack_depth_rlimit(); if (stack_rlimit > 0 && newval_bytes > stack_rlimit - STACK_DEPTH_SLOP) { - ereport(GUC_complaint_elevel(source), - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("\"max_stack_depth\" must not exceed %ldkB", - (stack_rlimit - STACK_DEPTH_SLOP) / 1024L), - errhint("Increase the platform's stack depth limit via \"ulimit -s\" or local equivalent."))); + GUC_check_errdetail("\"max_stack_depth\" must not exceed %ldkB.", + (stack_rlimit - STACK_DEPTH_SLOP) / 1024L); + GUC_check_errhint("Increase the platform's stack depth limit via \"ulimit -s\" or local equivalent."); return false; } - if (doit) - max_stack_depth_bytes = newval_bytes; return true; } +/* GUC assign hook for max_stack_depth */ +void +assign_max_stack_depth(int newval, void *extra) +{ + long newval_bytes = newval * 1024L; + + max_stack_depth_bytes = newval_bytes; +} + /* * set_debug_options --- apply "-d N" command line option -- cgit v1.2.3