Re: Recovering from detoast-related catcache invalidations
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Noah Misch <noah@leadboat.com>, Xiaoran Wang <fanfuxiaoran@gmail.com>,
pgsql-hackers@lists.postgresql.org, Andres Freund <andres@anarazel.de>
Date: 2024-12-23T22:18:09Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix catcache invalidation of a list entry that's being built
- f217c410553d 13.19 landed
- 91fc447c21d3 16.7 landed
- 96e61b2792a5 17.3 landed
- fce17c3a53d6 14.16 landed
- ce7c406f0f8d 15.11 landed
- af8cd1639ab2 18.0 landed
-
Cope with inplace update making catcache stale during TOAST fetch.
- 7a21306aee0a 13.16 landed
- 11f3815d6af8 12.20 landed
- af73e37fa181 14.13 landed
- b08a4b6163eb 15.8 landed
- e4afd7153bd8 16.4 landed
- f9f47f0d93d1 17.0 landed
-
Add previous commit to .git-blame-ignore-revs.
- 36578fa04942 17.0 landed
-
Re-pgindent catcache.c after previous commit.
- d41358f4bbc8 15.6 landed
- d29a4fbacfb7 12.18 landed
- 96c019ffa3f8 17.0 landed
- 7ceeb57baddd 14.11 landed
- 56dcd71decb7 16.2 landed
- 475b3ea3c06b 13.14 landed
-
Cope with catcache entries becoming stale during detoasting.
- db122d426a2d 14.11 landed
- ad98fb14226a 17.0 landed
- 98e03f957436 13.14 landed
- 7e2561e1a258 16.2 landed
- 3b4d85cf159c 12.18 landed
- 2a46a0df4793 15.6 landed
Attachments
- 0001-Demonstrate-catcache-list-invalidation-bug.patch (text/x-patch) patch 0001
- 0001-Don-t-allow-GetTransactionSnapshot-in-logical-decodi.patch (text/x-patch) patch 0001
On 14/12/2024 02:06, Heikki Linnakangas wrote: > Ok, I missed that. It does not handle the 2nd scenario though: If a new > catalog tuple is concurrently inserted that should be part of the list, > it is missed. > > I was able to reproduce that, by pausing a process with gdb while it's > building the list in SearchCatCacheList(): > > 1. Create a function called foofunc(integer). It must be large so that > its pg_proc tuple is toasted. > > 2. In one backend, run "SELECT foofunc(1)". It calls > FuncnameGetCandidates() which calls > "SearchSysCacheList1(PROCNAMEARGSNSP, CStringGetDatum(funcname));". Put > a break point in SearchCatCacheList() just after the systable_beginscan(). > > 3. In another backend, create function foofunc() with no args. > > 4. continue execution from the breakpoint. > > 5. Run "SELECT foofunc()" in the first session. It fails to find the > function. The error persists, it will fail to find that function if you > try again, until the syscache is invalidated again for some reason. > > Attached is an injection point test case to reproduce that. If you > change the test so that the function's body is shorter, so that it's not > toasted, the test passes. I'm thinking of the attached to fix this. It changes the strategy for detecting concurrent cache invalidations. Instead of the "recheck" mechanism that was introduced in commit ad98fb1422, keep a stack of "build in-progress" entries, and CatCacheInvalidate() invalidate those "in-progress" entries in addition to the actual CatCTup and CatCList entries. My first attempt was to insert the CatCTup or CatCList entry to the catcache before starting to build it, marked with a flag to indicate that the entry isn't fully built yet. But when I started to write that it got pretty invasive, and it felt easier to add another structure to hold the in-progress entries instead. (I'm not sure I got the 'volatile' markers on the local variable right in this patch; before committing this I'll need to freshen my memory on the rules on PG_TRY() and local variables again. Also, I'm not sure I want to commit the test with the injection point, but it's useful now to demonstrate the bug.) -- Heikki Linnakangas Neon (https://neon.tech)