Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b757abe

Browse files
committed
injection_points: Tweak variable-numbered stats to work with pending data
As coded, the module was not using pending entries to store its data locally before doing a flush to the central dshash with a timed pgstat_report_stat() call. Hence, the flush callback was defined, but finished by being not used. As a template, this is more efficient than the original logic of updating directly the shared memory entries as this reduces the interactions that need to be done with the pgstats hash table in shared memory. injection_stats_flush_cb() was also missing a pgstat_unlock_entry(), so add one, while on it. Reviewed-by: Bertrand Drouvot Discussion: https://postgr.es/m/Z3JbLhKFFm6kKfT8@ip-10-97-1-34.eu-west-3.compute.internal
1 parent c9b3d49 commit b757abe

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/test/modules/injection_points/injection_stats.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ injection_stats_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
8080
return false;
8181

8282
shfuncent->stats.numcalls += localent->numcalls;
83+
84+
pgstat_unlock_entry(entry_ref);
85+
8386
return true;
8487
}
8588

@@ -127,13 +130,13 @@ pgstat_create_inj(const char *name)
127130
if (!inj_stats_loaded || !inj_stats_enabled)
128131
return;
129132

130-
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_INJECTION, InvalidOid,
131-
PGSTAT_INJ_IDX(name), false);
133+
entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_INJECTION, InvalidOid,
134+
PGSTAT_INJ_IDX(name), NULL);
135+
132136
shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
133137

134138
/* initialize shared memory data */
135139
memset(&shstatent->stats, 0, sizeof(shstatent->stats));
136-
pgstat_unlock_entry(entry_ref);
137140
}
138141

139142
/*
@@ -168,16 +171,14 @@ pgstat_report_inj(const char *name)
168171
if (!inj_stats_loaded || !inj_stats_enabled)
169172
return;
170173

171-
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_INJECTION, InvalidOid,
172-
PGSTAT_INJ_IDX(name), false);
174+
entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_INJECTION, InvalidOid,
175+
PGSTAT_INJ_IDX(name), NULL);
173176

174177
shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
175178
statent = &shstatent->stats;
176179

177180
/* Update the injection point statistics */
178181
statent->numcalls++;
179-
180-
pgstat_unlock_entry(entry_ref);
181182
}
182183

183184
/*

0 commit comments

Comments
 (0)