postgresql/src
Michael Paquier 1df1e1e787 Fix invalidation of local pgstats references for entry reinitialization
818119afcc has introduced the "generation" concept in pgstats entries,
incremented a counter when a pgstats entry is reinitialized, but it did
not count on the fact that backends still holding local references to
such entries need to be refreshed if the cache age is outdated.  The
previous logic only updated local references when an entry was dropped,
but it needs also to consider entries that are reinitialized.

This matters for replication slot stats (as well as custom pgstats kinds
in 18~), where concurrent drops and creates of a slot could cause
incorrect stats to be locally referenced.  This would lead to an
assertion failure at shutdown when writing out the stats file, as the
backend holding an outdated local reference would not be able to drop
during its shutdown sequence the stats entry that should be dropped, as
the last process holding a reference to the stats entry.  The
checkpointer was then complaining about such an entry late in the
shutdown sequence, after the shutdown checkpoint is finished with the
control file updated, causing the stats file to not be generated.  In
non-assert builds, the entry would just be skipped with the stats file
written.

Note that only logical replication slots use statistics.

A test case based on TAP is added to test_decoding, where a persistent
connection peeking at a slot's data is kept with concurrent drops and
creates of the same slot.  This is based on the isolation test case that
Anton has sent.  As it requires a node shutdown with a check to make
sure that the stats file is written with this specific sequence of
events, TAP is used instead.

Reported-by: Anton A. Melnikov
Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/56bf8ff9-dd8c-47b2-872a-748ede82af99@postgrespro.ru
Backpatch-through: 15
2024-12-09 10:46:10 +09:00
..
backend Fix invalidation of local pgstats references for entry reinitialization 2024-12-09 10:46:10 +09:00
bin Revert "Handle better implicit transaction state of pipeline mode" 2024-11-28 09:43:24 +09:00
common Replace pgwin32_is_junction() with lstat(). 2024-11-08 09:29:40 +10:30
fe_utils Prevent mis-encoding of "trailing junk after numeric literal" errors. 2024-09-05 12:42:33 -04:00
include Ensure that pg_amop/amproc entries depend on their lefttype/righttype. 2024-12-07 15:56:28 -05:00
interfaces Fix broken list-munging in ecpg's remove_variables(). 2024-12-01 14:15:37 -05:00
makefiles Refactor DLSUFFIX handling 2022-03-25 08:56:02 +01:00
pl Add support for Tcl 9 2024-11-25 12:27:26 +01:00
port Make unlink() work for junction points on Windows. 2024-11-08 09:30:09 +10:30
template On NetBSD, force dynamic symbol resolution at postmaster start. 2022-08-30 17:28:55 -04:00
test Fix possible crash during WindowAgg evaluation 2024-12-09 14:24:54 +13:00
timezone Update time zone data files to tzdata release 2024b. 2024-10-29 11:50:00 -04:00
tools Skip SectionMemoryManager.h in cpluspluscheck. 2024-11-28 15:47:17 +13:00
tutorial Doc: sync src/tutorial/basics.source with SGML documentation. 2022-11-19 13:09:14 -05:00
.gitignore
DEVELOPERS
Makefile Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00
Makefile.global.in Suppress macOS warnings about duplicate libraries in link commands. 2023-09-29 14:07:30 -04:00
Makefile.shlib Stop using "-multiply_defined suppress" on macOS. 2023-09-26 21:06:21 -04:00
nls-global.mk Improve frontend error logging style. 2022-04-08 14:55:14 -04:00