Re: Recovering from detoast-related catcache invalidations

2025-03-26 Thread Andres Freund
Hi, On 2025-01-14 15:13:21 +0200, Heikki Linnakangas wrote: > Committed with those fixes. Thanks for the review! The test doesn't seem entirely stable. E.g. https://cirrus-ci.com/task/6166374147424256 failed spuriously: [08:52:06.822](0.002s) # issuing query 1 via background psql: # SELECT

Re: Recovering from detoast-related catcache invalidations

2025-01-14 Thread Heikki Linnakangas
On 12/01/2025 03:26, Noah Misch wrote: On Thu, Jan 09, 2025 at 11:39:53AM +0200, Heikki Linnakangas wrote: On 07/01/2025 23:56, Noah Misch wrote: @@ -697,9 +725,14 @@ CreateCacheMemoryContext(void) * * This is not very efficient if the target cache is nearly empty. * However, it shouldn

Re: Recovering from detoast-related catcache invalidations

2025-01-11 Thread Noah Misch
On Thu, Jan 09, 2025 at 11:39:53AM +0200, Heikki Linnakangas wrote: > On 07/01/2025 23:56, Noah Misch wrote: > > On Tue, Dec 24, 2024 at 12:18:09AM +0200, Heikki Linnakangas wrote: > > > I'm thinking of the attached to fix this. It changes the strategy for > > > detecting concurrent cache invalidat

Re: Recovering from detoast-related catcache invalidations

2025-01-09 Thread Heikki Linnakangas
On 07/01/2025 23:56, Noah Misch wrote: On Tue, Dec 24, 2024 at 12:18:09AM +0200, Heikki Linnakangas wrote: 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,

Re: Recovering from detoast-related catcache invalidations

2025-01-07 Thread Noah Misch
On Tue, Dec 24, 2024 at 12:18:09AM +0200, Heikki Linnakangas wrote: > 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. > > Attache

Re: Recovering from detoast-related catcache invalidations

2024-12-25 Thread Heikki Linnakangas
On 24/12/2024 09:38, Michael Paquier wrote: On Tue, Dec 24, 2024 at 12:18:09AM +0200, Heikki Linnakangas wrote: 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

Re: Recovering from detoast-related catcache invalidations

2024-12-23 Thread Michael Paquier
On Tue, Dec 24, 2024 at 12:18:09AM +0200, Heikki Linnakangas wrote: > 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 > i

Re: Recovering from detoast-related catcache invalidations

2024-12-23 Thread Heikki Linnakangas
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

Re: Recovering from detoast-related catcache invalidations

2024-12-13 Thread Heikki Linnakangas
On 13/12/2024 17:30, Tom Lane wrote: Heikki Linnakangas writes: CatalogCacheCreateEntry() can accept catcache invalidations when it opens the toast table, and it now has recheck logic to detect the case that the tuple it's processing (ntp) is invalidated. However, isn't it also possible that it

Re: Recovering from detoast-related catcache invalidations

2024-12-13 Thread Tom Lane
Heikki Linnakangas writes: > CatalogCacheCreateEntry() can accept catcache invalidations when it > opens the toast table, and it now has recheck logic to detect the case > that the tuple it's processing (ntp) is invalidated. However, isn't it > also possible that it accepts an invalidation mess

Re: Recovering from detoast-related catcache invalidations

2024-12-13 Thread Heikki Linnakangas
On 25/09/2024 00:20, Noah Misch wrote: On Sun, Jan 14, 2024 at 12:14:11PM -0800, Noah Misch wrote: On Fri, Jan 12, 2024 at 03:47:13PM -0500, Tom Lane wrote: Oh! After nosing around a bit more I remembered systable_recheck_tuple, which is meant for exactly this purpose. So v4 attached. systa

Re: Recovering from detoast-related catcache invalidations

2024-09-24 Thread Noah Misch
On Sun, Jan 14, 2024 at 12:14:11PM -0800, Noah Misch wrote: > On Fri, Jan 12, 2024 at 03:47:13PM -0500, Tom Lane wrote: > > Oh! After nosing around a bit more I remembered systable_recheck_tuple, > > which is meant for exactly this purpose. So v4 attached. > > systable_recheck_tuple() is blind t

Re: Recovering from detoast-related catcache invalidations

2024-01-14 Thread Xiaoran Wang
This is an interesting idea. Although some catalog tables are not in catcaches, such as pg_depend, when scanning them, if there is any SharedInvalidationMessage, the CatalogSnapshot will be invalidated and recreated ("RelationInvalidatesSnapshotsOnly" in syscache.c) Maybe during the system_scan,

Re: Recovering from detoast-related catcache invalidations

2024-01-14 Thread Noah Misch
On Fri, Jan 12, 2024 at 03:47:13PM -0500, Tom Lane wrote: > I wrote: > > This is uncomfortably much in bed with the tuple table slot code, > > perhaps, but I don't see a way to do it more cleanly unless we want > > to add some new provisions to that API. Andres, do you have any > > thoughts about

Re: Recovering from detoast-related catcache invalidations

2024-01-13 Thread Tom Lane
I wrote: > Xiaoran Wang writes: >> Hmm, how about first checking if any invalidated shared messages have been >> accepted, then rechecking the tuple's visibility? >> If there is no invalidated shared message accepted during >> 'toast_flatten_tuple', >> there is no need to do then visibility check,

Re: Recovering from detoast-related catcache invalidations

2024-01-13 Thread Tom Lane
Xiaoran Wang writes: > Hmm, how about first checking if any invalidated shared messages have been > accepted, then rechecking the tuple's visibility? > If there is no invalidated shared message accepted during > 'toast_flatten_tuple', > there is no need to do then visibility check, then it can sav

Re: Recovering from detoast-related catcache invalidations

2024-01-13 Thread Xiaoran Wang
Hmm, how about first checking if any invalidated shared messages have been accepted, then rechecking the tuple's visibility? If there is no invalidated shared message accepted during 'toast_flatten_tuple', there is no need to do then visibility check, then it can save several CPU cycles. i

Re: Recovering from detoast-related catcache invalidations

2024-01-12 Thread Xiaoran Wang
Great! That's what exactly we need. The patch LGTM, +1 Tom Lane 于2024年1月13日周六 04:47写道: > I wrote: > > This is uncomfortably much in bed with the tuple table slot code, > > perhaps, but I don't see a way to do it more cleanly unless we want > > to add some new provisions to that API. Andres,

Re: Recovering from detoast-related catcache invalidations

2024-01-12 Thread Tom Lane
I wrote: > This is uncomfortably much in bed with the tuple table slot code, > perhaps, but I don't see a way to do it more cleanly unless we want > to add some new provisions to that API. Andres, do you have any > thoughts about that? Oh! After nosing around a bit more I remembered systable_rec

Re: Recovering from detoast-related catcache invalidations

2024-01-12 Thread Tom Lane
Xiaoran Wang writes: >> Maybe, but that undocumented hack in SetHintBits seems completely >> unacceptable. Isn't there a cleaner way to make this check? > Maybe we don't need to call 'HeapTupleSatisfiesVisibility' to check if the > tuple has been deleted. > As the tuple's xmin must been committe

Re: Recovering from detoast-related catcache invalidations

2024-01-11 Thread Xiaoran Wang
> Also, I'm pretty dubious that GetNonHistoricCatalogSnapshot rather > than GetCatalogSnapshot is the right thing, because the catcaches > use the latter. Yes, you are right, should use GetCatalogSnapshot here. > Maybe, but that undocumented hack in SetHintBits seems completely > unacceptable. Is

Re: Recovering from detoast-related catcache invalidations

2024-01-11 Thread Tom Lane
Xiaoran Wang writes: >>> The detection of "get an invalidation" could be refined: what I did >>> here is to check for any advance of SharedInvalidMessageCounter, >>> which clearly will have a significant number of false positives. > I have reviewed your patch, and it looks good. But instead of c

Re: Recovering from detoast-related catcache invalidations

2024-01-11 Thread Xiaoran Wang
Hi, >> BTW, while nosing around I found what seems like a very nasty related >> bug. Suppose that a catalog tuple being loaded into syscache contains >> some toasted fields. CatalogCacheCreateEntry will flatten the tuple, >> involving fetches from toast tables that will certainly cause >> AcceptI

Re: Recovering from detoast-related catcache invalidations

2023-11-17 Thread Tom Lane
I wrote: > In bug #18163 [1], Alexander proved the misgivings I had in [2] > about catcache detoasting being possibly unsafe: > ... > Attached is a POC patch for fixing this. The cfbot pointed out that this needed a rebase. No substantive changes. regards, tom lane diff

Recovering from detoast-related catcache invalidations

2023-10-26 Thread Tom Lane
In bug #18163 [1], Alexander proved the misgivings I had in [2] about catcache detoasting being possibly unsafe: >> BTW, while nosing around I found what seems like a very nasty related >> bug. Suppose that a catalog tuple being loaded into syscache contains >> some toasted fields. CatalogCacheC