1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00

Split up guc.c for better build speed and ease of maintenance.

guc.c has grown to be one of our largest .c files, making it
a bottleneck for compilation.  It's also acquired a bunch of
knowledge that'd be better kept elsewhere, because of our not
very good habit of putting variable-specific check hooks here.
Hence, split it up along these lines:

* guc.c itself retains just the core GUC housekeeping mechanisms.
* New file guc_funcs.c contains the SET/SHOW interfaces and some
  SQL-accessible functions for GUC manipulation.
* New file guc_tables.c contains the data arrays that define the
  built-in GUC variables, along with some already-exported constant
  tables.
* GUC check/assign/show hook functions are moved to the variable's
  home module, whenever that's clearly identifiable.  A few hard-
  to-classify hooks ended up in commands/variable.c, which was
  already a home for miscellaneous GUC hook functions.

To avoid cluttering a lot more header files with #include "guc.h",
I also invented a new header file utils/guc_hooks.h and put all
the GUC hook functions' declarations there, regardless of their
originating module.  That allowed removal of #include "guc.h"
from some existing headers.  The fallout from that (hopefully
all caught here) demonstrates clearly why such inclusions are
best minimized: there are a lot of files that, for example,
were getting array.h at two or more levels of remove, despite
not having any connection at all to GUCs in themselves.

There is some very minor code beautification here, such as
renaming a couple of inconsistently-named hook functions
and improving some comments.  But mostly this just moves
code from point A to point B and deals with the ensuing
needs for #include adjustments and exporting a few functions
that previously weren't exported.

Patch by me, per a suggestion from Andres Freund; thanks also
to Michael Paquier for the idea to invent guc_funcs.c.

Discussion: https://postgr.es/m/587607.1662836699@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2022-09-13 11:05:07 -04:00
parent 257eb57b50
commit 0a20ff54f5
59 changed files with 7466 additions and 7128 deletions

View File

@@ -78,7 +78,7 @@
#include "miscadmin.h"
#include "port/pg_bswap.h"
#include "storage/ipc.h"
#include "utils/guc.h"
#include "utils/guc_hooks.h"
#include "utils/memutils.h"
/*
@@ -1914,6 +1914,108 @@ pq_settcpusertimeout(int timeout, Port *port)
return STATUS_OK;
}
/*
* GUC assign_hook for tcp_keepalives_idle
*/
void
assign_tcp_keepalives_idle(int newval, void *extra)
{
/*
* The kernel API provides no way to test a value without setting it; and
* once we set it we might fail to unset it. So there seems little point
* in fully implementing the check-then-assign GUC API for these
* variables. Instead we just do the assignment on demand.
* pq_setkeepalivesidle reports any problems via ereport(LOG).
*
* This approach means that the GUC value might have little to do with the
* actual kernel value, so we use a show_hook that retrieves the kernel
* value rather than trusting GUC's copy.
*/
(void) pq_setkeepalivesidle(newval, MyProcPort);
}
/*
* GUC show_hook for tcp_keepalives_idle
*/
const char *
show_tcp_keepalives_idle(void)
{
/* See comments in assign_tcp_keepalives_idle */
static char nbuf[16];
snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort));
return nbuf;
}
/*
* GUC assign_hook for tcp_keepalives_interval
*/
void
assign_tcp_keepalives_interval(int newval, void *extra)
{
/* See comments in assign_tcp_keepalives_idle */
(void) pq_setkeepalivesinterval(newval, MyProcPort);
}
/*
* GUC show_hook for tcp_keepalives_interval
*/
const char *
show_tcp_keepalives_interval(void)
{
/* See comments in assign_tcp_keepalives_idle */
static char nbuf[16];
snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort));
return nbuf;
}
/*
* GUC assign_hook for tcp_keepalives_count
*/
void
assign_tcp_keepalives_count(int newval, void *extra)
{
/* See comments in assign_tcp_keepalives_idle */
(void) pq_setkeepalivescount(newval, MyProcPort);
}
/*
* GUC show_hook for tcp_keepalives_count
*/
const char *
show_tcp_keepalives_count(void)
{
/* See comments in assign_tcp_keepalives_idle */
static char nbuf[16];
snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort));
return nbuf;
}
/*
* GUC assign_hook for tcp_user_timeout
*/
void
assign_tcp_user_timeout(int newval, void *extra)
{
/* See comments in assign_tcp_keepalives_idle */
(void) pq_settcpusertimeout(newval, MyProcPort);
}
/*
* GUC show_hook for tcp_user_timeout
*/
const char *
show_tcp_user_timeout(void)
{
/* See comments in assign_tcp_keepalives_idle */
static char nbuf[16];
snprintf(nbuf, sizeof(nbuf), "%d", pq_gettcpusertimeout(MyProcPort));
return nbuf;
}
/*
* Check if the client is still connected.
*/