Re: Pluggable cumulative statistics

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Pluggable cumulative statistics
Date: 2024-07-03 09:47:15
Message-ID: ZoUeI2jdbO_gn8cU@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jun 21, 2024 at 08:13:15AM +0900, Michael Paquier wrote:
> On Thu, Jun 20, 2024 at 02:27:14PM +0000, Bertrand Drouvot wrote:
>> On Thu, Jun 20, 2024 at 09:46:30AM +0900, Michael Paquier wrote:
>> I think it makes sense to follow the same "behavior" as the custom
>> wal resource managers. That, indeed, looks much more simpler than v1.
>
> Thanks for the feedback.

While looking at a different patch from Tristan in this area at [1], I
still got annoyed that this patch set was not able to support the case
of custom fixed-numbered stats, so as it is possible to plug in
pgstats things similar to the archiver, the checkpointer, WAL, etc.
These are plugged in shared memory, and are handled with copies in the
stats snapshots. After a good night of sleep, I have come up with a
good solution for that, among the following lines:
- PgStat_ShmemControl holds an array of void* indexed by
PGSTAT_NUM_KINDS, pointing to shared memory areas allocated for each
fixed-numbered stats. Each entry is allocated a size corresponding to
PgStat_KindInfo->shared_size.
- PgStat_Snapshot holds an array of void* also indexed by
PGSTAT_NUM_KINDS, pointing to the fixed stats stored in the
snapshots. These have a size of PgStat_KindInfo->shared_data_len, set
up when stats are initialized at process startup, so this reflects
everywhere.
- Fixed numbered stats now set shared_size, and we use this number to
determine the size to allocate for each fixed-numbered stats in shmem.
- A callback is added to initialize the shared memory assigned to each
fixed-numbered stats, consisting of LWLock initializations for the
current types of stats. So this initialization step is moved out of
pgstat.c into each stats kind file.

All that has been done in the rebased patch set as of 0001, which is
kind of a nice cleanup overall because it removes all the dependencies
to the fixed-numbered stats structures from the "main" pgstats code in
pgstat.c and pgstat_shmem.c.

The remaining patches consist of:
- 0002, Switch PgStat_Kind to a uint32. Cleanup.
- 0003 introduces the pluggable stats facility. Feeding on the
refactoring for the fixed-numbered stats in 0001, it is actually
possible to get support for these in the pluggable APIs by just
removing the restriction in the registration path. This extends the
void* arrays to store references that cover the range of custom kind
IDs.
- 0004 has some docs.
- 0005 includes an example of implementation for variable-numbered
stats with the injection_points module.
- 0006 is new for this thread, implementing an example for
fixed-numbered stats, using again the injection_points module. This
stuff gathers stats about the number of times points are run, attached
and detached. Perhaps that's useful in itself, I don't know, but it
provides the coverage I want for this facility.

While on it, I have applied one of the cleanup patches as
9fd02525793f.

[1]: https://www.postgresql.org/message-id/ZoNytpoHOzHGBLYi@paquier.xyz
--
Michael

Attachment Content-Type Size
v3-0001-Rework-handling-of-fixed-numbered-statistics-in-p.patch text/x-diff 29.9 KB
v3-0002-Switch-PgStat_Kind-from-enum-to-uint32.patch text/x-diff 3.1 KB
v3-0003-Introduce-pluggable-APIs-for-Cumulative-Statistic.patch text/x-diff 15.7 KB
v3-0004-doc-Add-section-for-Custom-Cumulative-Statistics-.patch text/x-diff 3.3 KB
v3-0005-injection_points-Add-statistics-for-custom-points.patch text/x-diff 14.2 KB
v3-0006-Add-support-for-fixed-numbered-statistics-in-plug.patch text/x-diff 12.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2024-07-03 10:05:28 Re: Conflict Detection and Resolution
Previous Message Fujii Masao 2024-07-03 09:33:44 pg_wal_summary_contents() and pg_walsummary may return different results on the same WAL summary file