diff options
author | Michael Paquier | 2024-09-09 02:12:29 +0000 |
---|---|---|
committer | Michael Paquier | 2024-09-09 02:12:29 +0000 |
commit | fc415edf8ca883b38cf8186f0d4b794d4a738cd5 (patch) | |
tree | bb70f55dc200a2e1ba9df5ad3e7282169c9e5a33 /src/backend/utils/activity/pgstat_wal.c | |
parent | 2e62fa62d6745ba3bcb0a517d002aff1f3cdefb7 (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/[email protected]
Diffstat (limited to 'src/backend/utils/activity/pgstat_wal.c')
-rw-r--r-- | src/backend/utils/activity/pgstat_wal.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/backend/utils/activity/pgstat_wal.c b/src/backend/utils/activity/pgstat_wal.c index 8c19c3f2fd5..e1d371ba3cd 100644 --- a/src/backend/utils/activity/pgstat_wal.c +++ b/src/backend/utils/activity/pgstat_wal.c @@ -72,6 +72,15 @@ pgstat_fetch_stat_wal(void) } /* + * Simple wrapper of pgstat_wal_flush_cb() + */ +void +pgstat_flush_wal(bool nowait) +{ + (void) pgstat_wal_flush_cb(nowait); +} + +/* * Calculate how much WAL usage counters have increased by subtracting the * previous counters from the current ones. * @@ -79,7 +88,7 @@ pgstat_fetch_stat_wal(void) * acquired. Otherwise return false. */ bool -pgstat_flush_wal(bool nowait) +pgstat_wal_flush_cb(bool nowait) { PgStatShared_Wal *stats_shmem = &pgStatLocal.shmem->wal; WalUsage wal_usage_diff = {0}; @@ -92,7 +101,7 @@ pgstat_flush_wal(bool nowait) * This function can be called even if nothing at all has happened. Avoid * taking lock for nothing in that case. */ - if (!pgstat_have_pending_wal()) + if (!pgstat_wal_have_pending_cb()) return false; /* @@ -141,8 +150,8 @@ void pgstat_wal_init_backend_cb(void) { /* - * Initialize prevWalUsage with pgWalUsage so that pgstat_flush_wal() can - * calculate how much pgWalUsage counters are increased by subtracting + * Initialize prevWalUsage with pgWalUsage so that pgstat_wal_flush_cb() + * can calculate how much pgWalUsage counters are increased by subtracting * prevWalUsage from pgWalUsage. */ prevWalUsage = pgWalUsage; @@ -156,7 +165,7 @@ pgstat_wal_init_backend_cb(void) * data pages. */ bool -pgstat_have_pending_wal(void) +pgstat_wal_have_pending_cb(void) { return pgWalUsage.wal_records != prevWalUsage.wal_records || PendingWalStats.wal_write != 0 || |