Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 35f215a

Browse files
author
Andrei Kruchinin
committed
Clean GUC placeholders with reserved prefix.
Extensions can reserve prefixes for their configuration parameters while loading. Then all parameter placeholders with reserved prefixes are removed from GUC list. Multimaster GUC list should also be cleaned.
1 parent 83c3bc1 commit 35f215a

File tree

3 files changed

+76
-58
lines changed

3 files changed

+76
-58
lines changed

expected/regression_ee.diff

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,64 +1755,6 @@ diff ../../../src/test/regress/expected/subscription.out ../tmp_check/regress_ou
17551755

17561756
ALTER SUBSCRIPTION regress_testsub SET (slot_name = NONE);
17571757
DROP SUBSCRIPTION regress_testsub;
1758-
diff ../../../src/test/regress/expected/guc.out ../tmp_check/regress_outdir/results/guc.out
1759-
--- ../../../src/test/regress/expected/guc.out CENSORED
1760-
+++ ../tmp_check/regress_outdir/results/guc.out CENSORED
1761-
@@ -563,13 +563,14 @@
1762-
-- Test DISCARD TEMP
1763-
--
1764-
CREATE TEMP TABLE reset_test ( data text ) ON COMMIT DELETE ROWS;
1765-
+ERROR: unrecognized configuration parameter "plpgsql.extra_foo_warnings"
1766-
SELECT relname FROM pg_class WHERE relname = 'reset_test';
1767-
- relname
1768-
-------------
1769-
- reset_test
1770-
-(1 row)
1771-
+ relname
1772-
+---------
1773-
+(0 rows)
1774-
1775-
DISCARD TEMP;
1776-
+ERROR: unrecognized configuration parameter "plpgsql.extra_foo_warnings"
1777-
SELECT relname FROM pg_class WHERE relname = 'reset_test';
1778-
relname
1779-
---------
1780-
@@ -584,8 +585,11 @@
1781-
LISTEN foo_event;
1782-
SET vacuum_cost_delay = 13;
1783-
CREATE TEMP TABLE tmp_foo (data text) ON COMMIT DELETE ROWS;
1784-
+ERROR: unrecognized configuration parameter "plpgsql.extra_foo_warnings"
1785-
CREATE ROLE regress_guc_user;
1786-
+ERROR: unrecognized configuration parameter "plpgsql.extra_foo_warnings"
1787-
SET SESSION AUTHORIZATION regress_guc_user;
1788-
+ERROR: role "regress_guc_user" does not exist
1789-
-- look changes
1790-
SELECT pg_listening_channels();
1791-
pg_listening_channels
1792-
@@ -614,13 +618,12 @@
1793-
SELECT relname from pg_class where relname = 'tmp_foo';
1794-
relname
1795-
---------
1796-
- tmp_foo
1797-
-(1 row)
1798-
+(0 rows)
1799-
1800-
SELECT current_user = 'regress_guc_user';
1801-
?column?
1802-
----------
1803-
- t
1804-
+ f
1805-
(1 row)
1806-
1807-
-- discard everything
1808-
@@ -659,6 +662,7 @@
1809-
(1 row)
1810-
1811-
DROP ROLE regress_guc_user;
1812-
+ERROR: role "regress_guc_user" does not exist
1813-
--
1814-
-- search_path should react to changes in pg_namespace
1815-
--
18161758
diff ../../../src/test/regress/expected/prepare.out ../tmp_check/regress_outdir/results/prepare.out
18171759
--- ../../../src/test/regress/expected/prepare.out CENSORED
18181760
+++ ../tmp_check/regress_outdir/results/prepare.out CENSORED

src/ddl.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ static void MtmProcessUtilitySender(PlannedStmt *pstmt,
141141
static void MtmGucUpdate(const char *key);
142142
static void MtmInitializeRemoteFunctionsMap(void);
143143
static char *MtmGucSerialize(void);
144+
static void MtmGucSync(const char *prefix);
144145
static void MtmMakeRelationLocal(Oid relid, bool locked);
145146
static List *AdjustCreateSequence(List *options);
146147

@@ -638,6 +639,71 @@ MtmGucSerialize(void)
638639
return serialized_gucs->data;
639640
}
640641

642+
/*
643+
* Any loaded extension can set ist own parameters
644+
* replacing existing placeholders if needed
645+
* and reserve its own parameter pefix.
646+
* Then all remaining placeholders with this prefix are deleted.
647+
* Multimaster guc list MtmGucEntry should be updated also.
648+
* This version just removes parameters which:
649+
* - have reserved prefixes,
650+
* - are not in guc variables list now.
651+
*
652+
* XXX: Can module name be used as a reserved prefix?
653+
*
654+
* XXX: Is it better to store placeholder flag in MtmGucEntry?
655+
*
656+
*/
657+
void
658+
MtmGucSync(const char *prefix)
659+
{
660+
dlist_mutable_iter iter;
661+
662+
if (!MtmGucHash)
663+
MtmGucInit();
664+
665+
dlist_foreach_modify(iter, &MtmGucList)
666+
{
667+
MtmGucEntry *cur_entry = dlist_container(MtmGucEntry, list_node, iter.cur);
668+
struct config_generic *gconf;
669+
bool is_reserved_class = false;
670+
const char *sep = strchr(cur_entry->key, GUC_QUALIFIER_SEPARATOR);
671+
size_t classLen;
672+
ListCell *lc;
673+
674+
if (sep == NULL)
675+
/* leave if is not prefixed */
676+
continue;
677+
678+
classLen = sep - cur_entry->key;
679+
foreach(lc, reserved_class_prefix)
680+
{
681+
const char *rcprefix = lfirst(lc);
682+
683+
if (strlen(rcprefix) == classLen &&
684+
strncmp(cur_entry->key, rcprefix, classLen) == 0)
685+
{
686+
elog(LOG, "----> MtmGucSerialize: invalid configuration parameter name \"%s\": "
687+
"\"%s\" is a reserved prefix.",
688+
cur_entry->key, rcprefix);
689+
is_reserved_class = true;
690+
break;
691+
}
692+
}
693+
694+
if (!is_reserved_class)
695+
/* leave if prefix is not rerserved */
696+
continue;
697+
698+
gconf = fing_guc_conf(cur_entry->key);
699+
if (gconf)
700+
/* leave if is in guc variable list */
701+
continue;
702+
703+
dlist_delete(iter.cur);
704+
hash_search(MtmGucHash, cur_entry->key, HASH_REMOVE, NULL);
705+
}
706+
}
641707

642708

643709
/*****************************************************************************
@@ -1226,6 +1292,14 @@ MtmProcessUtilitySender(PlannedStmt *pstmt, const char *queryString, bool readOn
12261292
}
12271293
}
12281294

1295+
/* Catch GUC changes after LOAD */
1296+
if (nodeTag(parsetree) == T_LoadStmt)
1297+
{
1298+
LoadStmt *stmt = (LoadStmt *) parsetree;
1299+
1300+
MtmGucSync(stmt->filename);
1301+
}
1302+
12291303
if (executed)
12301304
{
12311305
MtmFinishDDLCommand();

src/multimaster.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ NULL);
717717
NULL);
718718
}
719719

720+
MarkGUCPrefixReserved("multimaster");
721+
720722
/*
721723
* Request additional shared resources. (These are no-ops if we're not in
722724
* the postmaster process.) We'll allocate or attach to the shared

0 commit comments

Comments
 (0)