On Mon, Sep 15, 2025 at 05:33:45PM -0500, Sami Imseih wrote:
> I think it's better to use ->pending here, since this is referenced
> as an example and most real-world cases will likely want to use
> ->pending for performance reasons.

Yes, it should use the pending entry.  b757abefc041 did not get that
completely right.

The purpose of this code is also to serve as a template, so better
that it does the correct thing.

How about renaming "statent" to "pending" in pgstat_report_inj(), as
well?  That would be a bit more consistent with the subscription stat
case, at least.
--
Michael
From 3c0740039c07d2e7bd4ad101ea15f4630a0c4efa Mon Sep 17 00:00:00 2001
From: Michael Paquier <[email protected]>
Date: Tue, 16 Sep 2025 11:28:18 +0900
Subject: [PATCH] injection_points: Fix incrementation of variable-numbered
 stats

The pending entry was not used when incrementing its data, the code was
directly manipulating the shared memory pointer, without even locking
it.
---
 src/test/modules/injection_points/injection_stats.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/test/modules/injection_points/injection_stats.c b/src/test/modules/injection_points/injection_stats.c
index e3947b23ba57..ca8df4ad217a 100644
--- 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++;
 }
 
 /*
-- 
2.51.0

Attachment: signature.asc
Description: PGP signature

Reply via email to