From: Pavan Deolasee Date: Fri, 28 Sep 2018 09:24:11 +0000 (+0530) Subject: Ensure config changes caused by functions are rolled back correctly. X-Git-Tag: XL_10_R1~21 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=faf1934162bf24adf567ecaeba8894c9b50feb81;p=postgres-xl.git Ensure config changes caused by functions are rolled back correctly. When a function body has SET clauses attached to it, the function validation/execution reflects those config changes locally as well as on the remote nodes. But we were failing to restore the old values back when the command ends. This had gone unnoticed so far for the lack of any test case exercising this code. Note that there were existing test cases in this area, but the bug got unmasked only after we added a temporary table in the session. When a temporary table is accessed in a session, we don't reset the session at the end of the transaction and hence the issue surfaced. This was causing failure in a new test added in the 'rules' test. This patch fixes that. --- diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 261a6d9f90..bd21b10c75 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -5835,8 +5835,20 @@ AtEOXact_GUC(bool isCommit, int nestLevel) newvalStr = GetConfigOptionByName(gconf->name, NULL, true); if (newvalStr) - PGXCNodeSetParam((stack->state == GUC_LOCAL), gconf->name, - newvalStr, gconf->flags); + { + /* + * If we're unwinding changes caused by SET clauses + * attached to a function, reset those changes at the + * remote nodes immediately. Otherwise, we just remember + * the changes locally and send them to the remote nodes at + * next transaction/session. + */ + if (stack->state == GUC_SAVE) + set_remote_config_option(gconf->name, newvalStr, false); + else + PGXCNodeSetParam((stack->state == GUC_LOCAL), gconf->name, + newvalStr, gconf->flags); + } } /* Finish popping the state stack */