> Now, it is kind of true that the STATS_WRITE case feels a bit
> disturbing written this way: we let a module take an action, but we
> don't actually know the state of the main pgstats file when inside the
> callback.  I mean, you can know how things are going on, but it means
> that a module can just rely on a check if
> PGSTAT_STAT_PERMANENT_FILENAME is on disk, but an unlink() could have
> failed as well.  So, yes, I am wondering whether we should do what
> Chao is suggesting, passing an extra state to the callback to let the
> module know if we have actually succeeded or failed the operations
> that have been taken on the main stats file before the callback
> end_extra_stats is called in the three cases.  It does not matter for
> the STATS_READ case, but it may matter for the STATS_DISCARD or
> STATS_WRITE case.

I am having a hard time being convinced that this extra status is needed.
I am not expecting an extension to operate on the main stats file inside
the end_extra_stats callback, and even if some operation failed on the
main stats file, the cleanup callback will need to take the steps to
perform the cleanup on its own resources.

Is there a concrete example?

> FWIW, I still have the same question as the one posted here about the
> business in pgstat_initialize(), still present in v6:
> https://www.postgresql.org/message-id/[email protected]
>
> This remains unanswered.

Responding to the questions from the thread above.

> Why does this part need to run each time a backend initializes its
> access to pgstats?

Good point. This is unnecessary. This validation should really be
done inside StatsShmemInit by postmaster.

> By the way, checking that to_serialized_extra_stats and
> kind_info->from_serialized_extra_stats need to be both defined is
> fine as these are coupled together, but I am not following the reason
> why end_extra_stats would need to be included in the set? For
> example, a stats kind could decide to add some data to the main
> pgstats file without creating extra files, hence they may not need to
> define end_extra_stats.

.. and after giving this more thought, I actually don't think we should
do any validation for any of the callbacks. If an extension is writing
to any file ( core or custom ), naturally they will want to read it back.
Now I am not sure what these validations are protecting us against.
Also, maybe the extension wants to just read data from the main stats
file, I could see that use-case, perhaps.

So, I am proposing removing the validation altogether. What do
you think?

--
Sami Imseih
Amazon Web Services (AWS)


Reply via email to