Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tWmlj-001cGk-GH for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Jan 2025 01:28:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tWmki-00EUI6-K2 for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Jan 2025 01:26:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tWmki-00EUHy-2B for pgsql-hackers@lists.postgresql.org; Sun, 12 Jan 2025 01:26:55 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tWmke-0019qu-0C for pgsql-hackers@lists.postgresql.org; Sun, 12 Jan 2025 01:26:54 +0000 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2166f1e589cso66925265ad.3 for ; Sat, 11 Jan 2025 17:26:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1736645210; x=1737250010; darn=lists.postgresql.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=KXNW+bsTUGrIcah8HPA2VLxsFnIfCHgMZs2Ao83frrM=; b=bFjsARrHoaJFH1oD8X7NvUCZuRd+P3Icl3ioWK28d9N1lVk6t5mGR0TaQ79zOLmjf4 kpEpATE2XmgjQk45vCCph1HBx+isKYhw2VpSgbg/7/J4TZYnxi7MR+8L5JNyFTt5BQCC pEoFE42y0FO9afzwowcPiIYLhsQtZJBx7Uvb0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736645210; x=1737250010; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KXNW+bsTUGrIcah8HPA2VLxsFnIfCHgMZs2Ao83frrM=; b=cgPccokVB313IIXeZMrpKbdot24HTebI1fj7Z4qddfVUChYY1lcAdSDo8VDLk0bmu7 2BNsscV0bF92M97EOqqEgHq707CYbJpN4d2y2wfhDlC1bvwX9H6oMPWbgVA92TkiZgQC d4AxzYKnB5LlUY5R5qmecfWrRT/HTdWWHwE+dDXbbKLdDfgLBaA9q83tgPdpfceoHxFk I6nGk02HnkcyxIJq3lX3egy88j/JjF3M8HCzgpyJOzycPOvipNRuB5++pgRLEnpX8R9k MhJREOqZfDtV6hDM0Z5NC7P0ZJv/uJ6dRR2Gyix4NRmFCg2BGLGV34hscrdCXNLvAVRw 8mZg== X-Forwarded-Encrypted: i=1; AJvYcCXVIcS2CMNlnx5vIYq8W74kn52xU1m0Lek2XTVNCyQY48aL/7jW8PdpHI7msXbLHqXZxKvFcmOaaUdC1gkj@lists.postgresql.org X-Gm-Message-State: AOJu0YxJ+3XNbIbvulxYtVK3zQq2X0Mc+8CMbHtpolLg8AFu860ZEM36 /snMa7M5cykIcsqkFiTF9yVhwI74DmD4ZI59uX5vedAiFSER4mRHnke1J1xxPQ== X-Gm-Gg: ASbGncv7tO8JjskYeZqDRdPZubd9CJb6ZeTxh8voPWYAaAStraaUhrxz8r+vh0MKgmR WRglKrJqYX46PKboG0M9jJkJeYagvaJ85oT/SXQpE8yO1WCsNfOua+tg4/u2iX3UbfFBhk+WIce OnCthJHjASFKDq8vU0n11i46jecaxmOdAhJHGgDvafI3P5I06jHCzbOgta6vVq6Kluay/io+Vxn dbruaVd875IMhf1g4eqS6e2cHBPMBUzUtTDk/CUpiKaY0TRwZk= X-Google-Smtp-Source: AGHT+IEDmiCgAiKxBvCjrBOcrPsSe1LeVXzMjUJHNAEfMrB748GNtEr1ilxUQdZyIbXpj5DzX+4HgA== X-Received: by 2002:a05:6a21:9986:b0:1e1:cd9c:3775 with SMTP id adf61e73a8af0-1e88d10e937mr25320567637.12.1736645210377; Sat, 11 Jan 2025 17:26:50 -0800 (PST) Received: from google.com ([2600:1702:a20:5750::46]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72d4067ee81sm3640799b3a.132.2025.01.11.17.26.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Jan 2025 17:26:49 -0800 (PST) Date: Sat, 11 Jan 2025 17:26:47 -0800 From: Noah Misch To: Heikki Linnakangas Cc: Tom Lane , Xiaoran Wang , pgsql-hackers@lists.postgresql.org, Andres Freund Subject: Re: Recovering from detoast-related catcache invalidations Message-ID: <20250112012647.14.nmisch@google.com> References: <754826.1705090452@sss.pgh.pa.us> <793469.1705092433@sss.pgh.pa.us> <20240114201411.d0@rfd.leadboat.com> <20240924212036.0a.nmisch@google.com> <1066416.1734103822@sss.pgh.pa.us> <2234dc98-06fe-42ed-b5db-ac17384dc880@iki.fi> <1f11aacf-968c-4b8d-a917-31cb207b7a56@iki.fi> <20250107215653.82.nmisch@google.com> <5ef69a0d-8e8f-4104-a770-c77b1872d86d@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5ef69a0d-8e8f-4104-a770-c77b1872d86d@iki.fi> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 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. > > > > That's similar to how relcache has been doing it (in_progress_list). I see no > > problem applying that technique here. > > Oh thanks, I didn't notice that in relcache.c. I adjusted the naming and > comments in the new catcache.c code to be a little closer to the relcache.c > version, just to make it a bit more consistent. > > The main difference is that relcache.c uses an array and an end-of-xact > callback to reset the array on error, while my implementation uses a linked > list of entries allocated on stack and PG_TRY-CATCH for error cleanup. I > considered adopting relcache.c's approach for the sake of consistency, but > decided to keep my original approach in the end. Some of the code in > catcache.c already had a suitable PG_TRY-CATCH block and I didn't want to > add a new end-of-xact callback just for this. That difference is reasonable. catcache will add PG_TRY overhead only in the HEAP_HASEXTERNAL case, which is not a normal benchmark situation. If relcache were to adopt the PG_TRY approach, it would be harder to rule out the significance of the overhead. So a long-term state of using both designs is reasonable. It's not a mere historical accident. > > gcc 4.8.5 warns: > > > > catcache.c: In function ‘CatalogCacheCreateEntry’: > > catcache.c:2159:29: warning: ‘dtp’ may be used uninitialized in this function [-Wmaybe-uninitialized] > > ct->tuple.t_tableOid = dtp->t_tableOid; > > > > I remember some commit of a gcc 4.x warning fix in a recent year, and we do > > have buildfarm representation. Consider silencing it. > > Hmm, I guess the compiler doesn't see that it's initialized with all the > PG_TRY()/CATCH() stuff. I initialized it to NULL to silence the warning. It's warning-free now. > @@ -697,9 +725,14 @@ CreateCacheMemoryContext(void) > * > * This is not very efficient if the target cache is nearly empty. > * However, it shouldn't need to be efficient; we don't invoke it often. > + * > + * If 'debug_discard' is true, we are being called as part of > + * debug_discard_caches. In that case, the cache not reset for correctness, s/cache not/cache is not/ or similar > + PG_TRY(); > { > - matches = equalTuple(before, ntp); > - heap_freetuple(before); > + dtp = toast_flatten_tuple(ntp, cache->cc_tupdesc); > } > - if (!matches || !systable_recheck_tuple(scandesc, ntp)) > + PG_FINALLY(); > { > - heap_freetuple(dtp); Is this an intentional removal of the heap_freetuple(dtp) before return NULL? > - return NULL; > + Assert(catcache_in_progress_stack == &in_progress_ent); > + catcache_in_progress_stack = save_in_progress; > } > + PG_END_TRY(); > + > + if (in_progress_ent.dead) > + return NULL; ... > +$node->append_conf( > + 'postgresql.conf', qq{ > +debug_discard_caches=1 > +}); I'd drop this debug_discard_caches. debug_discard_caches buildfarm runs will still test it, so let's have normal runs test the normal case.