summaryrefslogtreecommitdiff
path: root/src/include/utils/pgstat_internal.h
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2024-09-09 11:12:29 +0900
committerMichael Paquier <michael@paquier.xyz>2024-09-09 11:12:29 +0900
commitfc415edf8ca883b38cf8186f0d4b794d4a738cd5 (patch)
treebb70f55dc200a2e1ba9df5ad3e7282169c9e5a33 /src/include/utils/pgstat_internal.h
parent2e62fa62d6745ba3bcb0a517d002aff1f3cdefb7 (diff)
Add callbacks to control flush of fixed-numbered stats
This commit adds two callbacks in pgstats to have a better control of the flush timing of pgstat_report_stat(), whose operation depends on the three PGSTAT_*_INTERVAL variables: - have_fixed_pending_cb(), to check if a stats kind has any pending data waiting for a flush. This is used as a fast path if there are no pending statistics to flush, and this check is done for fixed-numbered statistics only if there are no variable-numbered statistics to flush. A flush will need to happen if at least one callback reports any pending data. - flush_fixed_cb(), to do the actual flush. These callbacks are currently used by the SLRU, WAL and IO statistics, generalizing the concept for all stats kinds (builtin and custom). The SLRU and IO stats relied each on one global variable to determine whether a flush should happen; these are now local to pgstat_slru.c and pgstat_io.c, cleaning up a bit how the pending flush states are tracked in pgstat.c. pgstat_flush_io() and pgstat_flush_wal() are still required, but we do not need to check their return result anymore. Reviewed-by: Bertrand Drouvot, Kyotaro Horiguchi Discussion: https://postgr.es/m/ZtaVO0N-aTwiAk3w@paquier.xyz
Diffstat (limited to 'src/include/utils/pgstat_internal.h')
-rw-r--r--src/include/utils/pgstat_internal.h42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat_internal.h
index 25820cbf0a6..bba90e898dd 100644
--- a/src/include/utils/pgstat_internal.h
+++ b/src/include/utils/pgstat_internal.h
@@ -237,7 +237,7 @@ typedef struct PgStat_KindInfo
/*
* For variable-numbered stats: flush pending stats. Required if pending
- * data is used.
+ * data is used. See flush_fixed_cb for fixed-numbered stats.
*/
bool (*flush_pending_cb) (PgStat_EntryRef *sr, bool nowait);
@@ -266,6 +266,19 @@ typedef struct PgStat_KindInfo
void (*init_shmem_cb) (void *stats);
/*
+ * For fixed-numbered statistics: Flush pending stats. Returns true if
+ * some of the stats could not be flushed, due to lock contention for
+ * example. Optional.
+ */
+ bool (*flush_fixed_cb) (bool nowait);
+
+ /*
+ * For fixed-numbered statistics: Check for pending stats in need of
+ * flush. Returns true if there are any stats pending for flush. Optional.
+ */
+ bool (*have_fixed_pending_cb) (void);
+
+ /*
* For fixed-numbered statistics: Reset All.
*/
void (*reset_all_cb) (TimestampTz ts);
@@ -609,7 +622,10 @@ extern bool pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait);
* Functions in pgstat_io.c
*/
-extern bool pgstat_flush_io(bool nowait);
+extern void pgstat_flush_io(bool nowait);
+
+extern bool pgstat_io_have_pending_cb(void);
+extern bool pgstat_io_flush_cb(bool nowait);
extern void pgstat_io_init_shmem_cb(void *stats);
extern void pgstat_io_reset_all_cb(TimestampTz ts);
extern void pgstat_io_snapshot_cb(void);
@@ -668,7 +684,8 @@ extern PgStatShared_Common *pgstat_init_entry(PgStat_Kind kind,
* Functions in pgstat_slru.c
*/
-extern bool pgstat_slru_flush(bool nowait);
+extern bool pgstat_slru_have_pending_cb(void);
+extern bool pgstat_slru_flush_cb(bool nowait);
extern void pgstat_slru_init_shmem_cb(void *stats);
extern void pgstat_slru_reset_all_cb(TimestampTz ts);
extern void pgstat_slru_snapshot_cb(void);
@@ -678,10 +695,11 @@ extern void pgstat_slru_snapshot_cb(void);
* Functions in pgstat_wal.c
*/
-extern bool pgstat_flush_wal(bool nowait);
-extern bool pgstat_have_pending_wal(void);
+extern void pgstat_flush_wal(bool nowait);
extern void pgstat_wal_init_backend_cb(void);
+extern bool pgstat_wal_have_pending_cb(void);
+extern bool pgstat_wal_flush_cb(bool nowait);
extern void pgstat_wal_init_shmem_cb(void *stats);
extern void pgstat_wal_reset_all_cb(TimestampTz ts);
extern void pgstat_wal_snapshot_cb(void);
@@ -712,20 +730,6 @@ extern PGDLLIMPORT PgStat_LocalState pgStatLocal;
/*
- * Variables in pgstat_io.c
- */
-
-extern PGDLLIMPORT bool have_iostats;
-
-
-/*
- * Variables in pgstat_slru.c
- */
-
-extern PGDLLIMPORT bool have_slrustats;
-
-
-/*
* Implementation of inline functions declared above.
*/