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 1tvMJw-003rpI-T6 for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 20:16:53 +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 1tvMJv-008G0i-K0 for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Mar 2025 20:16:51 +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 1tvMJv-008Fza-A3 for pgsql-hackers@lists.postgresql.org; Thu, 20 Mar 2025 20:16:51 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tvMJs-000CPt-2v for pgsql-hackers@postgresql.org; Thu, 20 Mar 2025 20:16:50 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-22435603572so24015565ad.1 for ; Thu, 20 Mar 2025 13:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1742501807; x=1743106607; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=tJzQDLs16IMDJqxWiaGoXGJ+T3smVBAFIBguLa6ZQHM=; b=QLK/6Je+rx5xZXXkeVNboPdpiU3LQwxqpMocDkvQRAQaTIq/b6K+grutfqylzBOXNq w1a3vNasQCWmnOxT3btxVd/hzVd10356/OKza5dVp4tl5UBUgifEH/lkUJ7ag4tAbaO2 SWHnk7qh2Q5/pclpfEy9QSfmg6Zmrxb2LAplY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742501807; x=1743106607; h=user-agent:in-reply-to: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=tJzQDLs16IMDJqxWiaGoXGJ+T3smVBAFIBguLa6ZQHM=; b=ZjDru1wDLOXNg7sbzTMJod2BJ5lrVngQVqXcjSXbOZOGM1BTk5ZtzjjX76LS9BzGJ5 7CKxL8ystS6Wwlmi46TY644QV/qd9uGhzDuFctYNHwzHahjmO5Pa13dlOjCV7yIGr1Q7 o/UvK1OVfrOeP73glSrdg76xDlB0UEDQqaRBk/ifKqAqxGIgF9ISK3j+Fv7GHBm6tmXF 65UanN7e3ZN8G9X2sM9nqEZYXypsoLzg3JWUsH0Lq7gNk1BFg9c3w4+QtGldnuqp2dLK 4qfk8X2fP3LWHJOQ9UWCc7hKDc0IqTP/jmk7JDiyl5ntZbNhb2ZVxPpzWrMmHf7BQka9 VGgg== X-Forwarded-Encrypted: i=1; AJvYcCVPrCRj+03s9nm+qqVXBli2y2iQKWhDosUAQ1QxglXvJBJTfBmiGoRDZ/l+w93+QzAaqhIBDiXiBDlI8gx5@postgresql.org X-Gm-Message-State: AOJu0Yx/CU/28CHuFuneUtKDNtZUrcp9WLQGiFRxS+FG+n+NL7vogS+w +BTEX1ft29ryTHiaQ7GBNyXktnu4uj5YNQf6TGHjcuKJSvMGg+zei2AQ6Wy1dA== X-Gm-Gg: ASbGnct8TFTfBN0YjFUDv3G0qF6MlHhH5kb4gBHvI22vu3iEXwYx0c4n5YrWlM/Vp2H 7Dby4/0OzqQJh592pookBrxwxXaHdOCplEuq5bU50JgW/jfLzgz0WKDiQo5UJUUWsQFYjP5+ozA 0mfP2eLVW1jRlKRpEX4V3OihsuAXawfZbB2pv2hco9esS0fiIWbFmCAM/K68kHucCA6/ZtO6ss1 ceTHRH36u+S3DOnh/sBJRDo6LOJtwGdAJx7B/bWu+T2y1OCYnS7iCq7Sh9WtUy3laWoPlclOHBv bcxlSddNG0jgQ5w1bDWCtwulOhTuqnLDVd9UGUzMMg== X-Google-Smtp-Source: AGHT+IELr3PuioUkGhKB0fDZSICLRpyXJa7Fs3W5BbocaAdsp4Pw4THgrrWxQ5Q0/C0Wmsa4taJ8IQ== X-Received: by 2002:a05:6a00:2e24:b0:736:55ec:ea8b with SMTP id d2e1a72fcca58-73905a65919mr1587436b3a.24.1742501806520; Thu, 20 Mar 2025 13:16:46 -0700 (PDT) Received: from google.com ([2601:647:5600:80d0::31cd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73905ffc5f9sm244508b3a.72.2025.03.20.13.16.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Mar 2025 13:16:45 -0700 (PDT) Date: Thu, 20 Mar 2025 13:16:44 -0700 From: Noah Misch To: Andres Freund Cc: Thomas Munro , pgsql-hackers@postgresql.org Subject: Re: md.c vs elog.c vs smgrreleaseall() in barrier Message-ID: <20250320201644.3d.nmisch@google.com> References: <3vae7l5ozvqtxmd7rr7zaeq3qkuipz365u3rtim5t5wdkr6f4g@vkgf2fogjirl> <4qtmksxdbbp3pb7dqmn6lnzzdv7ujnizmbqtfbwm7c25waavtk@i6iyjrhk5eh5> <20250319195553.ef.nmisch@google.com> <20250320004514.95.nmisch@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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, Mar 20, 2025 at 03:53:11PM -0400, Andres Freund wrote: > I updated the patch with the following changes: > > - Remove the assertion from smgrtruncate() - it would need to assert that it's > called in a critical section. > > Not sure why it's not already asserting that? > > The function header says: > * ... This function should normally > * be called in a critical section, but the current size must be checked > * outside the critical section, and no interrupts or smgr functions relating > * to this relation should be called in between. > > The "should normally" is bit weird imo, when would it be safe to *not* use > it in a critical section? I expect it would be okay in recovery, which is a crypto-critical-section IIRC. All callers, including smgr_redo(), do have an explicit critical section around the call. Hence, I gather we're no longer relying on any exceptions to this one's need for a critical section. > - added comments about the reason for HOLD_INTERRUPTS to smgrdounlinkall(), > smgrdestroyall() and smgrreleaseall() Perfect. > I still am leaning against backpatching, but I'm not sure that's not just > laziness. It's also some risk reduction. One of these smgr APIs might have a useful interruptibility that we're now blocking. (I'm not aware of one.) > On 2025-03-19 17:45:14 -0700, Noah Misch wrote: > > On Wed, Mar 19, 2025 at 06:45:20PM -0400, Andres Freund wrote: > > > On 2025-03-19 12:55:53 -0700, Noah Misch wrote: > > > > On Mon, Mar 17, 2025 at 07:52:02PM -0400, Andres Freund wrote: > > > > > @@ -434,6 +481,8 @@ smgrdosyncall(SMgrRelation *rels, int nrels) > > > > > if (nrels == 0) > > > > > return; > > > > > > > > > > + HOLD_INTERRUPTS(); > > > > > + > > > > > FlushRelationsAllBuffers(rels, nrels); > > > > > > > > FlushRelationsAllBuffers() isn't part of smgr or md.c, so it's unlikely to > > > > become sensitive to smgrrelease(). It may do a ton of I/O. Hence, I'd > > > > HOLD_INTERRUPTS() after FlushRelationsAllBuffers(), not before. > > > > > > Hm - we never would want to process interrupts while in > > > FlushRelationsAllBuffers() or such, would we? I'm ok with changing it, I > > > guess I just didn't see a reason not to use a wider scope. > > > > If we get a query cancel or fast shutdown, it's better for the user to abort > > the transaction rather than keep flushing. smgrDoPendingSyncs() calls here > > rather late in the pre-commit actions, so failing is still supposed to be > > fine. I think the code succeeds at making it fine to fail here. > > But we don't actually intentionally accept interrupts in > FlushRelationsAllBuffers()? Yes. It would be reasonable for future work to add that. > It would only happen as a side-effect of a > non-error elog/ereport() processing interrupts, right? Likely yes. > It also looks like we couldn't accept interrupts when called by > AbortTransaction(), because there we already are in a HOLD_INTERRUPTS() > region. I'm pretty sure an error would trigger at least an assertion. But > that's really an independent issue. The only smgrdosyncall() caller is smgrDoPendingSyncs(), which doesn't call it in the abort case. So I think we're good. > Moved. Thanks. > > > I suspect it's always called with interrupts held already though. > > > > Ah, confirmed. If I put this assert at the top of smgrdounlinkall(), > > check-world passes: > > > > Assert(IsBinaryUpgrade || InRecovery || !INTERRUPTS_CAN_BE_PROCESSED()); > > I just made it hold interrupts for now, hope that makes sense? Yep. Patch looks perfect.