git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 158c483)
injection_points: Fix incrementation of variable-numbered stats
2025年9月17日 01:15:13 +0000 (10:15 +0900)
2025年9月17日 01:15:13 +0000 (10:15 +0900)
The pending entry was not used when incrementing its data, directly
manipulating the shared memory pointer, without even locking it. This
could mean losing statistics under concurrent activity. The flush
callback was a no-op.

This code serves as a base template for extensions for the custom
cumulative statistics, so let's be clean and use a pending entry for the
incrementations, whose data is then flushed to the corresponding entry
in the shared hashtable when all the stats are reported, in its own
flush callback.

Author: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0v0U0yhPbY+bqChomkPbyUrRQ3rQXnZf_SB-svDiQOpgQ@mail.gmail.com
Backpatch-through: 18


diff --git a/src/test/modules/injection_points/injection_stats.c b/src/test/modules/injection_points/injection_stats.c
index e3947b23ba57330d5a3339396da0a9a0cc5e8f2f..ca8df4ad217ab91fc5dbf18665135ced42d8cc84 100644 (file)
--- a/src/test/modules/injection_points/injection_stats.c
+++ b/src/test/modules/injection_points/injection_stats.c
@@ -164,8 +164,7 @@ void
pgstat_report_inj(const char *name)
{
PgStat_EntryRef *entry_ref;
- PgStatShared_InjectionPoint *shstatent;
- PgStat_StatInjEntry *statent;
+ PgStat_StatInjEntry *pending;
/* leave if disabled */
if (!inj_stats_loaded || !inj_stats_enabled)
@@ -174,11 +173,10 @@ pgstat_report_inj(const char *name)
entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_INJECTION, InvalidOid,
PGSTAT_INJ_IDX(name), NULL);
- shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
- statent = &shstatent->stats;
+ pending = (PgStat_StatInjEntry *) entry_ref->pending;
- /* Update the injection point statistics */
- statent->numcalls++;
+ /* Update the injection point pending statistics */
+ pending->numcalls++;
}
/*
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /