Skip to content

Commit 39f67d9

Browse files
committed
injection_points: Fix incrementation of variable-numbered stats
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
1 parent 158c483 commit 39f67d9

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/test/modules/injection_points/injection_stats.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ void
164164
pgstat_report_inj(const char *name)
165165
{
166166
PgStat_EntryRef *entry_ref;
167-
PgStatShared_InjectionPoint *shstatent;
168-
PgStat_StatInjEntry *statent;
167+
PgStat_StatInjEntry *pending;
169168

170169
/* leave if disabled */
171170
if (!inj_stats_loaded || !inj_stats_enabled)
@@ -174,11 +173,10 @@ pgstat_report_inj(const char *name)
174173
entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_INJECTION, InvalidOid,
175174
PGSTAT_INJ_IDX(name), NULL);
176175

177-
shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
178-
statent = &shstatent->stats;
176+
pending = (PgStat_StatInjEntry *) entry_ref->pending;
179177

180-
/* Update the injection point statistics */
181-
statent->numcalls++;
178+
/* Update the injection point pending statistics */
179+
pending->numcalls++;
182180
}
183181

184182
/*

0 commit comments

Comments
 (0)