Skip to content

Commit 1aa33c3

Browse files
erthalionCommitfest Bot
authored andcommitted
Introduce pending flag for GUC assign hooks
Currently an assing hook can perform some preprocessing of a new value, but it cannot change the behavior, which dictates that the new value will be applied immediately after the hook. Certain GUC options (like shared_buffers, coming in subsequent patches) may need coordinating work between backends to change, meaning we cannot apply it right away. Add a new flag "pending" for an assign hook to allow the hook indicate exactly that. If the pending flag is set after the hook, the new value will not be applied and it's handling becomes the hook's implementation responsibility. Note, that this also requires changes in the way how GUCs are getting reported, but the patch does not cover that yet.
1 parent d3c9e06 commit 1aa33c3

File tree

8 files changed

+61
-40
lines changed

8 files changed

+61
-40
lines changed

src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@ CalculateCheckpointSegments(void)
23212321
}
23222322

23232323
void
2324-
assign_max_wal_size(int newval, void *extra)
2324+
assign_max_wal_size(int newval, void *extra, bool *pending)
23252325
{
23262326
max_wal_size_mb = newval;
23272327
CalculateCheckpointSegments();

src/backend/commands/variable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ check_cluster_name(char **newval, void **extra, GucSource source)
11431143
* GUC assign_hook for maintenance_io_concurrency
11441144
*/
11451145
void
1146-
assign_maintenance_io_concurrency(int newval, void *extra)
1146+
assign_maintenance_io_concurrency(int newval, void *extra, bool *pending)
11471147
{
11481148
/*
11491149
* Reconfigure recovery prefetching, because a setting it depends on
@@ -1161,12 +1161,12 @@ assign_maintenance_io_concurrency(int newval, void *extra)
11611161
* they may be assigned in either order.
11621162
*/
11631163
void
1164-
assign_io_max_combine_limit(int newval, void *extra)
1164+
assign_io_max_combine_limit(int newval, void *extra, bool *pending)
11651165
{
11661166
io_combine_limit = Min(newval, io_combine_limit_guc);
11671167
}
11681168
void
1169-
assign_io_combine_limit(int newval, void *extra)
1169+
assign_io_combine_limit(int newval, void *extra, bool *pending)
11701170
{
11711171
io_combine_limit = Min(io_max_combine_limit, newval);
11721172
}

src/backend/libpq/pqcomm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ pq_settcpusertimeout(int timeout, Port *port)
19521952
* GUC assign_hook for tcp_keepalives_idle
19531953
*/
19541954
void
1955-
assign_tcp_keepalives_idle(int newval, void *extra)
1955+
assign_tcp_keepalives_idle(int newval, void *extra, bool *pending)
19561956
{
19571957
/*
19581958
* The kernel API provides no way to test a value without setting it; and
@@ -1985,7 +1985,7 @@ show_tcp_keepalives_idle(void)
19851985
* GUC assign_hook for tcp_keepalives_interval
19861986
*/
19871987
void
1988-
assign_tcp_keepalives_interval(int newval, void *extra)
1988+
assign_tcp_keepalives_interval(int newval, void *extra, bool *pending)
19891989
{
19901990
/* See comments in assign_tcp_keepalives_idle */
19911991
(void) pq_setkeepalivesinterval(newval, MyProcPort);
@@ -2008,7 +2008,7 @@ show_tcp_keepalives_interval(void)
20082008
* GUC assign_hook for tcp_keepalives_count
20092009
*/
20102010
void
2011-
assign_tcp_keepalives_count(int newval, void *extra)
2011+
assign_tcp_keepalives_count(int newval, void *extra, bool *pending)
20122012
{
20132013
/* See comments in assign_tcp_keepalives_idle */
20142014
(void) pq_setkeepalivescount(newval, MyProcPort);
@@ -2031,7 +2031,7 @@ show_tcp_keepalives_count(void)
20312031
* GUC assign_hook for tcp_user_timeout
20322032
*/
20332033
void
2034-
assign_tcp_user_timeout(int newval, void *extra)
2034+
assign_tcp_user_timeout(int newval, void *extra, bool *pending)
20352035
{
20362036
/* See comments in assign_tcp_keepalives_idle */
20372037
(void) pq_settcpusertimeout(newval, MyProcPort);

src/backend/tcop/postgres.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3591,7 +3591,7 @@ check_log_stats(bool *newval, void **extra, GucSource source)
35913591

35923592
/* GUC assign hook for transaction_timeout */
35933593
void
3594-
assign_transaction_timeout(int newval, void *extra)
3594+
assign_transaction_timeout(int newval, void *extra, bool *pending)
35953595
{
35963596
if (IsTransactionState())
35973597
{

src/backend/utils/misc/guc.c

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ InitializeOneGUCOption(struct config_generic *gconf)
16791679
struct config_int *conf = (struct config_int *) gconf;
16801680
int newval = conf->boot_val;
16811681
void *extra = NULL;
1682+
bool pending = false;
16821683

16831684
Assert(newval >= conf->min);
16841685
Assert(newval <= conf->max);
@@ -1687,9 +1688,13 @@ InitializeOneGUCOption(struct config_generic *gconf)
16871688
elog(FATAL, "failed to initialize %s to %d",
16881689
conf->gen.name, newval);
16891690
if (conf->assign_hook)
1690-
conf->assign_hook(newval, extra);
1691-
*conf->variable = conf->reset_val = newval;
1692-
conf->gen.extra = conf->reset_extra = extra;
1691+
conf->assign_hook(newval, extra, &pending);
1692+
1693+
if (!pending)
1694+
{
1695+
*conf->variable = conf->reset_val = newval;
1696+
conf->gen.extra = conf->reset_extra = extra;
1697+
}
16931698
break;
16941699
}
16951700
case PGC_REAL:
@@ -2041,13 +2046,18 @@ ResetAllOptions(void)
20412046
case PGC_INT:
20422047
{
20432048
struct config_int *conf = (struct config_int *) gconf;
2049+
bool pending = false;
20442050

20452051
if (conf->assign_hook)
20462052
conf->assign_hook(conf->reset_val,
2047-
conf->reset_extra);
2048-
*conf->variable = conf->reset_val;
2049-
set_extra_field(&conf->gen, &conf->gen.extra,
2050-
conf->reset_extra);
2053+
conf->reset_extra,
2054+
&pending);
2055+
if (!pending)
2056+
{
2057+
*conf->variable = conf->reset_val;
2058+
set_extra_field(&conf->gen, &conf->gen.extra,
2059+
conf->reset_extra);
2060+
}
20512061
break;
20522062
}
20532063
case PGC_REAL:
@@ -2424,16 +2434,21 @@ AtEOXact_GUC(bool isCommit, int nestLevel)
24242434
struct config_int *conf = (struct config_int *) gconf;
24252435
int newval = newvalue.val.intval;
24262436
void *newextra = newvalue.extra;
2437+
bool pending = false;
24272438

24282439
if (*conf->variable != newval ||
24292440
conf->gen.extra != newextra)
24302441
{
24312442
if (conf->assign_hook)
2432-
conf->assign_hook(newval, newextra);
2433-
*conf->variable = newval;
2434-
set_extra_field(&conf->gen, &conf->gen.extra,
2435-
newextra);
2436-
changed = true;
2443+
conf->assign_hook(newval, newextra, &pending);
2444+
2445+
if (!pending)
2446+
{
2447+
*conf->variable = newval;
2448+
set_extra_field(&conf->gen, &conf->gen.extra,
2449+
newextra);
2450+
changed = true;
2451+
}
24372452
}
24382453
break;
24392454
}
@@ -3850,18 +3865,24 @@ set_config_with_handle(const char *name, config_handle *handle,
38503865

38513866
if (changeVal)
38523867
{
3868+
bool pending = false;
3869+
38533870
/* Save old value to support transaction abort */
38543871
if (!makeDefault)
38553872
push_old_value(&conf->gen, action);
38563873

38573874
if (conf->assign_hook)
3858-
conf->assign_hook(newval, newextra);
3859-
*conf->variable = newval;
3860-
set_extra_field(&conf->gen, &conf->gen.extra,
3861-
newextra);
3862-
set_guc_source(&conf->gen, source);
3863-
conf->gen.scontext = context;
3864-
conf->gen.srole = srole;
3875+
conf->assign_hook(newval, newextra, &pending);
3876+
3877+
if (!pending)
3878+
{
3879+
*conf->variable = newval;
3880+
set_extra_field(&conf->gen, &conf->gen.extra,
3881+
newextra);
3882+
set_guc_source(&conf->gen, source);
3883+
conf->gen.scontext = context;
3884+
conf->gen.srole = srole;
3885+
}
38653886
}
38663887
if (makeDefault)
38673888
{

src/backend/utils/misc/stack_depth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ check_max_stack_depth(int *newval, void **extra, GucSource source)
156156

157157
/* GUC assign hook for max_stack_depth */
158158
void
159-
assign_max_stack_depth(int newval, void *extra)
159+
assign_max_stack_depth(int newval, void *extra, bool *pending)
160160
{
161161
ssize_t newval_bytes = newval * (ssize_t) 1024;
162162

src/include/utils/guc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ typedef bool (*GucStringCheckHook) (char **newval, void **extra, GucSource sourc
187187
typedef bool (*GucEnumCheckHook) (int *newval, void **extra, GucSource source);
188188

189189
typedef void (*GucBoolAssignHook) (bool newval, void *extra);
190-
typedef void (*GucIntAssignHook) (int newval, void *extra);
190+
typedef void (*GucIntAssignHook) (int newval, void *extra, bool *pending);
191191
typedef void (*GucRealAssignHook) (double newval, void *extra);
192192
typedef void (*GucStringAssignHook) (const char *newval, void *extra);
193193
typedef void (*GucEnumAssignHook) (int newval, void *extra);

src/include/utils/guc_hooks.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ extern bool check_log_stats(bool *newval, void **extra, GucSource source);
8181
extern bool check_log_timezone(char **newval, void **extra, GucSource source);
8282
extern void assign_log_timezone(const char *newval, void *extra);
8383
extern const char *show_log_timezone(void);
84-
extern void assign_maintenance_io_concurrency(int newval, void *extra);
85-
extern void assign_io_max_combine_limit(int newval, void *extra);
86-
extern void assign_io_combine_limit(int newval, void *extra);
84+
extern void assign_maintenance_io_concurrency(int newval, void *extra, bool *pending);
85+
extern void assign_io_max_combine_limit(int newval, void *extra, bool *pending);
86+
extern void assign_io_combine_limit(int newval, void *extra, bool *pending);
8787
extern bool check_max_slot_wal_keep_size(int *newval, void **extra,
8888
GucSource source);
89-
extern void assign_max_wal_size(int newval, void *extra);
89+
extern void assign_max_wal_size(int newval, void *extra, bool *pending);
9090
extern bool check_max_stack_depth(int *newval, void **extra, GucSource source);
91-
extern void assign_max_stack_depth(int newval, void *extra);
91+
extern void assign_max_stack_depth(int newval, void *extra, bool *pending);
9292
extern bool check_multixact_member_buffers(int *newval, void **extra,
9393
GucSource source);
9494
extern bool check_multixact_offset_buffers(int *newval, void **extra,
@@ -143,13 +143,13 @@ extern void assign_synchronous_standby_names(const char *newval, void *extra);
143143
extern void assign_synchronous_commit(int newval, void *extra);
144144
extern void assign_syslog_facility(int newval, void *extra);
145145
extern void assign_syslog_ident(const char *newval, void *extra);
146-
extern void assign_tcp_keepalives_count(int newval, void *extra);
146+
extern void assign_tcp_keepalives_count(int newval, void *extra, bool *pending);
147147
extern const char *show_tcp_keepalives_count(void);
148-
extern void assign_tcp_keepalives_idle(int newval, void *extra);
148+
extern void assign_tcp_keepalives_idle(int newval, void *extra, bool *pending);
149149
extern const char *show_tcp_keepalives_idle(void);
150-
extern void assign_tcp_keepalives_interval(int newval, void *extra);
150+
extern void assign_tcp_keepalives_interval(int newval, void *extra, bool *pending);
151151
extern const char *show_tcp_keepalives_interval(void);
152-
extern void assign_tcp_user_timeout(int newval, void *extra);
152+
extern void assign_tcp_user_timeout(int newval, void *extra, bool *pending);
153153
extern const char *show_tcp_user_timeout(void);
154154
extern bool check_temp_buffers(int *newval, void **extra, GucSource source);
155155
extern bool check_temp_tablespaces(char **newval, void **extra,
@@ -165,7 +165,7 @@ extern bool check_transaction_buffers(int *newval, void **extra, GucSource sourc
165165
extern bool check_transaction_deferrable(bool *newval, void **extra, GucSource source);
166166
extern bool check_transaction_isolation(int *newval, void **extra, GucSource source);
167167
extern bool check_transaction_read_only(bool *newval, void **extra, GucSource source);
168-
extern void assign_transaction_timeout(int newval, void *extra);
168+
extern void assign_transaction_timeout(int newval, void *extra, bool *pending);
169169
extern const char *show_unix_socket_permissions(void);
170170
extern bool check_wal_buffers(int *newval, void **extra, GucSource source);
171171
extern bool check_wal_consistency_checking(char **newval, void **extra,

0 commit comments

Comments
 (0)