summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2025-01-21 01:12:39 +0000
committerMichael Paquier2025-01-21 01:12:39 +0000
commit28de66cee5f45e2f173fa60dd6867c810ecabe38 (patch)
tree938a554530086e6a77563920e898214386114165
parent60c513f8fa17b83878bc2267b4d1e77dccd38cea (diff)
Rename some pgstats callbacks related to flush of entries
The two callbacks have_fixed_pending_cb and flush_fixed_cb have been introduced in fc415edf8ca8 to provide a way for fixed-numbered statistics to control the flush of their data. These are renamed to respectively have_static_pending_cb and flush_static_cb. The restriction that these only apply to fixed-numbered stats is removed. A follow-up patch will make use of them for backend statistics. This stats kind is variable-numbered, and patches are under discussion to track WAL data for IO and backend stats which cannot use PgStat_EntryRef->pending as pending data would be touched in critical sections, where no memory allocation can happen. Per discussion with Andres Freund. Author: Bertrand Drouvot Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/66efowskppsns35v5u2m7k4sdnl7yoz5bo64tdjwq7r5lhplrz@y7dme5xwh2r5
-rw-r--r--src/backend/utils/activity/pgstat.c36
-rw-r--r--src/include/utils/pgstat_internal.h27
2 files changed, 30 insertions, 33 deletions
diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c
index 34520535d54..402e8202bfa 100644
--- a/src/backend/utils/activity/pgstat.c
+++ b/src/backend/utils/activity/pgstat.c
@@ -437,8 +437,8 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
.shared_data_off = offsetof(PgStatShared_IO, stats),
.shared_data_len = sizeof(((PgStatShared_IO *) 0)->stats),
- .flush_fixed_cb = pgstat_io_flush_cb,
- .have_fixed_pending_cb = pgstat_io_have_pending_cb,
+ .flush_static_cb = pgstat_io_flush_cb,
+ .have_static_pending_cb = pgstat_io_have_pending_cb,
.init_shmem_cb = pgstat_io_init_shmem_cb,
.reset_all_cb = pgstat_io_reset_all_cb,
.snapshot_cb = pgstat_io_snapshot_cb,
@@ -455,8 +455,8 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
.shared_data_off = offsetof(PgStatShared_SLRU, stats),
.shared_data_len = sizeof(((PgStatShared_SLRU *) 0)->stats),
- .flush_fixed_cb = pgstat_slru_flush_cb,
- .have_fixed_pending_cb = pgstat_slru_have_pending_cb,
+ .flush_static_cb = pgstat_slru_flush_cb,
+ .have_static_pending_cb = pgstat_slru_have_pending_cb,
.init_shmem_cb = pgstat_slru_init_shmem_cb,
.reset_all_cb = pgstat_slru_reset_all_cb,
.snapshot_cb = pgstat_slru_snapshot_cb,
@@ -474,8 +474,8 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
.shared_data_len = sizeof(((PgStatShared_Wal *) 0)->stats),
.init_backend_cb = pgstat_wal_init_backend_cb,
- .flush_fixed_cb = pgstat_wal_flush_cb,
- .have_fixed_pending_cb = pgstat_wal_have_pending_cb,
+ .flush_static_cb = pgstat_wal_flush_cb,
+ .have_static_pending_cb = pgstat_wal_have_pending_cb,
.init_shmem_cb = pgstat_wal_init_shmem_cb,
.reset_all_cb = pgstat_wal_reset_all_cb,
.snapshot_cb = pgstat_wal_snapshot_cb,
@@ -713,22 +713,17 @@ pgstat_report_stat(bool force)
{
bool do_flush = false;
- /* Check for pending fixed-numbered stats */
+ /* Check for pending stats */
for (PgStat_Kind kind = PGSTAT_KIND_MIN; kind <= PGSTAT_KIND_MAX; kind++)
{
const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
if (!kind_info)
continue;
- if (!kind_info->fixed_amount)
- {
- Assert(kind_info->have_fixed_pending_cb == NULL);
- continue;
- }
- if (!kind_info->have_fixed_pending_cb)
+ if (!kind_info->have_static_pending_cb)
continue;
- if (kind_info->have_fixed_pending_cb())
+ if (kind_info->have_static_pending_cb())
{
do_flush = true;
break;
@@ -789,25 +784,20 @@ pgstat_report_stat(bool force)
partial_flush = false;
- /* flush of variable-numbered stats */
+ /* flush of variable-numbered stats tracked in pending entries list */
partial_flush |= pgstat_flush_pending_entries(nowait);
- /* flush of fixed-numbered stats */
+ /* flush of other stats kinds */
for (PgStat_Kind kind = PGSTAT_KIND_MIN; kind <= PGSTAT_KIND_MAX; kind++)
{
const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind);
if (!kind_info)
continue;
- if (!kind_info->fixed_amount)
- {
- Assert(kind_info->flush_fixed_cb == NULL);
- continue;
- }
- if (!kind_info->flush_fixed_cb)
+ if (!kind_info->flush_static_cb)
continue;
- partial_flush |= kind_info->flush_fixed_cb(nowait);
+ partial_flush |= kind_info->flush_static_cb(nowait);
}
last_flush = now;
diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat_internal.h
index 4bb8e5c53ab..8914aaca9ab 100644
--- a/src/include/utils/pgstat_internal.h
+++ b/src/include/utils/pgstat_internal.h
@@ -156,8 +156,8 @@ typedef struct PgStat_EntryRef
* Pending statistics data that will need to be flushed to shared memory
* stats eventually. Each stats kind utilizing pending data defines what
* format its pending data has and needs to provide a
- * PgStat_KindInfo->flush_pending_cb callback to merge pending into shared
- * stats.
+ * PgStat_KindInfo->flush_pending_cb callback to merge pending entries
+ * into the shared stats hash table.
*/
void *pending;
dlist_node pending_node; /* membership in pgStatPending list */
@@ -260,7 +260,8 @@ typedef struct PgStat_KindInfo
/*
* For variable-numbered stats: flush pending stats. Required if pending
- * data is used. See flush_fixed_cb for fixed-numbered stats.
+ * data is used. See flush_static_cb when dealing with stats data that
+ * that cannot use PgStat_EntryRef->pending.
*/
bool (*flush_pending_cb) (PgStat_EntryRef *sr, bool nowait);
@@ -289,17 +290,23 @@ 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.
+ * For fixed-numbered or variable-numbered statistics: Flush pending stats
+ * entries, for stats kinds that do not use PgStat_EntryRef->pending.
+ *
+ * Returns true if some of the stats could not be flushed, due to lock
+ * contention for example. Optional.
*/
- bool (*flush_fixed_cb) (bool nowait);
+ bool (*flush_static_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.
+ * For fixed-numbered or variable-numbered statistics: Check for pending
+ * stats in need of flush with flush_static_cb, when these do not use
+ * PgStat_EntryRef->pending.
+ *
+ * Returns true if there are any stats pending for flush, triggering
+ * flush_static_cb. Optional.
*/
- bool (*have_fixed_pending_cb) (void);
+ bool (*have_static_pending_cb) (void);
/*
* For fixed-numbered statistics: Reset All.