Merge pull request #182 from darkfronza/PG-326_check_histogram_minmax
PG-326: Validate histogram_min and histogram_max ranges.pull/196/head
commit
5356e2e75c
34
guc.c
34
guc.c
|
@ -20,9 +20,14 @@
|
|||
|
||||
GucVariable conf[MAX_SETTINGS];
|
||||
static void DefineIntGUC(GucVariable *conf);
|
||||
static void DefineIntGUCWithCheck(GucVariable *conf, GucIntCheckHook check);
|
||||
static void DefineBoolGUC(GucVariable *conf);
|
||||
static void DefineEnumGUC(GucVariable *conf, const struct config_enum_entry *options);
|
||||
|
||||
/* Check hooks to ensure histogram_min < histogram_max */
|
||||
static bool check_histogram_min(int *newval, void **extra, GucSource source);
|
||||
static bool check_histogram_max(int *newval, void **extra, GucSource source);
|
||||
|
||||
/*
|
||||
* Define (or redefine) custom GUC variables.
|
||||
*/
|
||||
|
@ -113,7 +118,7 @@ init_guc(void)
|
|||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_HISTOGRAM_MIN
|
||||
};
|
||||
DefineIntGUC(&conf[i++]);
|
||||
DefineIntGUCWithCheck(&conf[i++], check_histogram_min);
|
||||
|
||||
conf[i] = (GucVariable) {
|
||||
.guc_name = "pg_stat_monitor.pgsm_histogram_max",
|
||||
|
@ -125,7 +130,7 @@ init_guc(void)
|
|||
.guc_unit = 0,
|
||||
.guc_value = &PGSM_HISTOGRAM_MAX
|
||||
};
|
||||
DefineIntGUC(&conf[i++]);
|
||||
DefineIntGUCWithCheck(&conf[i++], check_histogram_max);
|
||||
|
||||
conf[i] = (GucVariable) {
|
||||
.guc_name = "pg_stat_monitor.pgsm_histogram_buckets",
|
||||
|
@ -218,8 +223,7 @@ init_guc(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
DefineIntGUC(GucVariable *conf)
|
||||
static void DefineIntGUCWithCheck(GucVariable *conf, GucIntCheckHook check)
|
||||
{
|
||||
conf->type = PGC_INT;
|
||||
DefineCustomIntVariable(conf->guc_name,
|
||||
|
@ -231,10 +235,17 @@ DefineIntGUC(GucVariable *conf)
|
|||
conf->guc_max,
|
||||
conf->guc_restart ? PGC_POSTMASTER : PGC_USERSET,
|
||||
conf->guc_unit,
|
||||
NULL,
|
||||
check,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
DefineIntGUC(GucVariable *conf)
|
||||
{
|
||||
DefineIntGUCWithCheck(conf, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
DefineBoolGUC(GucVariable *conf)
|
||||
{
|
||||
|
@ -274,3 +285,16 @@ get_conf(int i)
|
|||
return &conf[i];
|
||||
}
|
||||
|
||||
static bool check_histogram_min(int *newval, void **extra, GucSource source)
|
||||
{
|
||||
/*
|
||||
* During module initialization PGSM_HISTOGRAM_MIN is initialized before
|
||||
* PGSM_HISTOGRAM_MAX, in this case PGSM_HISTOGRAM_MAX will be zero.
|
||||
*/
|
||||
return (PGSM_HISTOGRAM_MAX == 0 || *newval < PGSM_HISTOGRAM_MAX);
|
||||
}
|
||||
|
||||
static bool check_histogram_max(int *newval, void **extra, GucSource source)
|
||||
{
|
||||
return (*newval > PGSM_HISTOGRAM_MIN);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue