mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
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
This commit is contained in:
@ -80,6 +80,9 @@ injection_stats_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
shfuncent->stats.numcalls += localent->numcalls;
|
shfuncent->stats.numcalls += localent->numcalls;
|
||||||
|
|
||||||
|
pgstat_unlock_entry(entry_ref);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,13 +130,13 @@ pgstat_create_inj(const char *name)
|
|||||||
if (!inj_stats_loaded || !inj_stats_enabled)
|
if (!inj_stats_loaded || !inj_stats_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_INJECTION, InvalidOid,
|
entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_INJECTION, InvalidOid,
|
||||||
PGSTAT_INJ_IDX(name), false);
|
PGSTAT_INJ_IDX(name), NULL);
|
||||||
|
|
||||||
shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
|
shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
|
||||||
|
|
||||||
/* initialize shared memory data */
|
/* initialize shared memory data */
|
||||||
memset(&shstatent->stats, 0, sizeof(shstatent->stats));
|
memset(&shstatent->stats, 0, sizeof(shstatent->stats));
|
||||||
pgstat_unlock_entry(entry_ref);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -168,16 +171,14 @@ pgstat_report_inj(const char *name)
|
|||||||
if (!inj_stats_loaded || !inj_stats_enabled)
|
if (!inj_stats_loaded || !inj_stats_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_INJECTION, InvalidOid,
|
entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_INJECTION, InvalidOid,
|
||||||
PGSTAT_INJ_IDX(name), false);
|
PGSTAT_INJ_IDX(name), NULL);
|
||||||
|
|
||||||
shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
|
shstatent = (PgStatShared_InjectionPoint *) entry_ref->shared_stats;
|
||||||
statent = &shstatent->stats;
|
statent = &shstatent->stats;
|
||||||
|
|
||||||
/* Update the injection point statistics */
|
/* Update the injection point statistics */
|
||||||
statent->numcalls++;
|
statent->numcalls++;
|
||||||
|
|
||||||
pgstat_unlock_entry(entry_ref);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user