Hi hackers.

I have a question about the recommended way to declare the C variables
used for the GUC values.

Here are some examples from the code:

~

The GUC boot values are defined in src/backend.utils/misc/guc_tables.c

e.g. See the 4, and 2 below

{
{"max_logical_replication_workers",
PGC_POSTMASTER,
REPLICATION_SUBSCRIBERS,
gettext_noop("Maximum number of logical replication worker processes."),
NULL,
},
&max_logical_replication_workers,
4, 0, MAX_BACKENDS,
NULL, NULL, NULL
},

{
{"max_sync_workers_per_subscription",
PGC_SIGHUP,
REPLICATION_SUBSCRIBERS,
gettext_noop("Maximum number of table synchronization workers per
subscription."),
NULL,
},
&max_sync_workers_per_subscription,
2, 0, MAX_BACKENDS,
NULL, NULL, NULL
},

~~

Meanwhile, the associated C variables are declared in their respective modules.

e.g. src/backend/replication/launcher.c

int max_logical_replication_workers = 4;
int max_sync_workers_per_subscription = 2;

~~

It seems confusing to me that for the above code the initial value is
"hardwired" in multiple places. Specifically, it looks tempting to
just change the variable declaration value, but IIUC that's going to
achieve nothing because it will just be overwritten by the
"boot-value" during the GUC mechanism start-up.

Furthermore, there seems no consistency with how these C variables are
auto-initialized:

a) Sometimes the static variable is assigned some (dummy?) value that
is not the same as the boot value
- See src/backend/utils/misc/guc_tables.c, max_replication_slots boot
value is 10
- See src/backend/replication/slot.c, int max_replication_slots = 0;

b) Sometimes the static value is assigned the same hardwired value as
the GUC boot value
- See src/backend/utils/misc/guc_tables.c,
max_logical_replication_workers boot value is 4
- See src/backend/replication/launcher.c, int
max_logical_replication_workers = 4;

c) Sometimes the GUC C variables don't even have a comment saying that
they are GUC variables, so it is not at all obvious their initial
values are going to get overwritten by some external mechanism.
- See src/backend/replication/launcher.c, int
max_logical_replication_workers = 4;

~

I would like to know what is the recommended way/convention to write
the C variable declarations for the GUC values.

IMO I felt the launch.c code as shown would be greatly improved simply
by starting with 0 values, and including an explanatory comment.

e.g.

CURRENT
int max_logical_replication_workers = 4;
int max_sync_workers_per_subscription = 2;

SUGGESTION
/*
 * GUC variables. Initial values are assigned at startup via
InitializeGUCOptions.
 */
int max_logical_replication_workers = 0;
int max_sync_workers_per_subscription = 0;


Thoughts?

------
Kind Regards,
Peter Smith.
Fujitsu Australia


Reply via email to