Re: Missing LWLock protection in pgstat_reset_replslot()
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
To: "Anton A. Melnikov" <a.melnikov@postgrespro.ru>
Cc: Michael Paquier <michael@paquier.xyz>, Tom Lane <tgl@sss.pgh.pa.us>, shveta malik <shveta.malik@gmail.com>, Heikki Linnakangas <hlinnaka@iki.fi>, pgsql-hackers@lists.postgresql.org
Date: 2024-12-04T15:20:03Z
Lists: pgsql-hackers
Hi,
On Wed, Dec 04, 2024 at 03:45:13AM +0300, Anton A. Melnikov wrote:
> Hi!
>
> b36fbd9f8d message says that inconsistency may still be possible because
> statistics are not completely consistent for a single scan of
> pg_stat_replication_slots under concurrent replication slot drop or
> creation activity.
>
> Seems there is a reproduction of such a case via isolation test.
> Please see the repslot_stat.spec attached.
Thanks for the report!
While I agree that your test case does produce a failed assertion, I don't
think it's linked to b36fbd9f8d (which focused on retrieving consistent stats).
As far your test case, it produces:
TRAP: failed Assert("!ps->dropped"), File: "pgstat.c", Line: 1400, PID: 189292
I did some test and from what I can see:
This is due to the fact that the "dropped" entry is "still in pgStatLocal.shared_hash".
Indeed, during the shutdown, Session 1 is going through:
pgstat_report_disconnect()->…->pgstat_get_entry_ref()->pgstat_gc_entry_refs()->
pgstat_release_entry_ref()-> “Shared stats entry has been reinitialized, so do not drop”
So it's not dropping the entry because It's going in the "Shared stats entry has been reinitialized"
case in pgstat_release_entry_ref().
It's doing so because the previous test:
"
if (pg_atomic_read_u32(&entry_ref->shared_entry->generation) ==
entry_ref->generation)
"
is false (entry_ref->shared_entry->generation is 1 while entry_ref->generation
is 0).
I need to think more about it but it seems to me that those values make sense,
so maybe we should drop the entry for this particular case (shmem_exit()).
Thoughts?
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Commits
-
Fix invalidation of local pgstats references for entry reinitialization
- 1df1e1e78762 15.11 landed
- ae77bcc3aa1b 16.7 landed
- dc5f9054186a 17.3 landed
- da99fedf8c17 18.0 landed
-
Improve consistency of replication slot statistics
- b36fbd9f8da1 17.0 landed