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.96) (envelope-from ) id 1w6H7l-0048GN-0C for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2026 00:01:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w6H7j-00D0on-1i for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2026 00:01:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w6H7i-00D0oX-2E for pgsql-hackers@lists.postgresql.org; Sat, 28 Mar 2026 00:01:55 +0000 Received: from fhigh-b8-smtp.messagingengine.com ([202.12.124.159]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w6H7g-00000001Pby-31LI for pgsql-hackers@postgresql.org; Sat, 28 Mar 2026 00:01:54 +0000 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 8501E7A012C; Fri, 27 Mar 2026 20:01:51 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Fri, 27 Mar 2026 20:01:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1774656111; x=1774742511; bh=sHvT+68y/C LmPD6YlQFUbUamtg6qP+1m2zwlgMFy7BU=; b=iu00VhN10aiUq/aKGlRlD7qYau wT4yQKoV1wb4ftFIXuDfjtlQV7SczXQP50QCX6dgrjoj0EJpiv5GHOSn7RQBEBKO BjB8YZwDRFLs2WuvnQyfp/xT7f4A5dIbYC1X2IZtJSHxKZMfSl1p5SbVYRo1+lbG 6ThwnGDMFo8Gvc+Wh7URB6608eLn8yWsIQaEobfUc/XAFg4kHErVHabqntovxgU+ 1/iWz4FKo17YWN2FdW5sxgGPx5mCHIPiMwioVL0selldwafVSgwoulbGF9Y6qGTt 01J5+Finm5UQ7nmU1mh/Au+BUl6Q7U/QwRyf6YHKN3roSwICy/UrJS19F2bQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1774656111; x=1774742511; bh=sHvT+68y/CLmPD6YlQFUbUamtg6qP+1m2zw lgMFy7BU=; b=ID8F2VmCuZV+pTABqa81yCnl7JEJ16ebeF83eXEhGOdZSWgJYWM jlQsglgmNWwHKWfgIiQ1fC8EepUAix5e9YPTowBobixvJCN5x6LMiye2whR4Ocbc pcXNBOKcG+f20jJyvB6SBmqRmtiPGB8PjCWw/EOHM7cz9VXUWivaC2wYNIDeVnzq Tjitc7SZzNY3CSXPGE5gf28j6tBoFIHTYBxnEIC/T0BxF5DQMIyIxArw81ASK0jH Of4gwKP0BncJBr9n6V18kIz0nqIWRaa+Mzn0ONfRxifOmb4eVBduOA1pG+oCNMTZ TKx8ryHAcG7znevoWikmwmmhVwExe7Ik3AA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdeffeduieejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtsfdttddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepfeffgfelvdffgedtveelgfdtgefghfdvkefggeetieevjeekteduleevjefh ueegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeeipdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehpghessghofihtrdhivgdprhgtphhtthhopehtvh esfhhuiiiihidrtgiipdhrtghpthhtohepsgihrghvuhiikedusehgmhgrihhlrdgtohhm pdhrtghpthhtohepmhgvlhgrnhhivghplhgrghgvmhgrnhesghhmrghilhdrtghomhdprh gtphhtthhopehthhhomhgrshdrmhhunhhrohesghhmrghilhdrtghomhdprhgtphhtthho pehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Mar 2026 20:01:50 -0400 (EDT) Date: Fri, 27 Mar 2026 20:01:49 -0400 From: Andres Freund To: Melanie Plageman Cc: Nazir Bilal Yavuz , Thomas Munro , pgsql-hackers@postgresql.org, Peter Geoghegan , Tomas Vondra Subject: Re: Don't synchronously wait for already-in-progress IO in read stream Message-ID: References: <42rdu4q44kvsq53fz5qgzuawqpaytvnemsnquynlfch5mqhc2m@6ytnlgivtzro> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-03-27 18:59:36 -0400, Melanie Plageman wrote: > Review of 0004: > > I noticed I use the word "backend" _a lot_ in this commit message. > Here is an attempt at using it less: Mostly adopted. > Code and test stuff: > > in query_wait_block() > > - $node->poll_query_until('postgres', > - qq(SELECT wait_event FROM pg_stat_activity WHERE pid = $pid), > - $waitfor); > + my $waitquery; > + if ($wait_current_session) > + { > + $waitquery = > + qq(SELECT wait_event FROM pg_stat_activity WHERE pid = $pid); > + } > + else > + { > + $waitquery = > + qq(SELECT wait_event FROM pg_stat_activity WHERE wait_event > = '$waitfor'); > + } > + > + note "polling for completion with $waitquery"; > + $node->poll_query_until('postgres', $waitquery, $waitfor); > > I guess you need WHERE wait_event = $waitfor to keep from getting more > than one row returned and then failing to parse properly. Right. For some reason poll_query_until() doesn't allow pattern matching, so there's a pretty hard limit to allowing any variability in output. > But I got tripped up on this thinking won't poll_query_until() already give > you that? Not as far as I can tell. > I started thinking maybe wait_current_session should be a hash so we > can pass it with a name and it will make the query_wait_block() call > sites less inscrutable, but maybe that's over-engineering. I'm not even seeing how that would work - the problem is that the wait event might be in an IO worker (in case of io_method=worker) or in the frontend process (in case of io_method=io_uring). > # Because no IO wref was assigned, block 2 should not report foreign IO > pump_until($psql_a->{run}, $psql_a->{timeout}, \$psql_a->{stdout}, > qr/0\|1\|t\|f\|2\n2\|3\|t\|f\|3/); > > you mean block 3 > > # Because no IO wref was assigned, block 2 should not report foreign IO > pump_until($psql_a->{run}, $psql_a->{timeout}, \$psql_a->{stdout}, > > should say block 3 Ooops. > You could change the first test > # Test if a read buffers encounters AIO in progress by another backend, it > # recognizes that other IO as a foreign IO. > > To have 0 as the foreign IO (which is a slightly different code path > than non-head blocks being the foreign IO) and then you still > basically have coverage of a non-head block being a foreign IO in the > following test case that looks for multiple contiguous blocks being > foreign IO. Did that, except I also offset to start reading from 1, in the unlikely case we have something in the path loosing track of block numbers. > In test_read_buffers_inject: > # recognizes that other IO as a foreign IO. This time we encounter the > # foreign IO multiple times. > > I find "foriegn IO multiple times" hard to parse. I prefer something > like "multiple > buffers undergoing foreign IO" Somehow the modified version seemed harder to read to me, so I left it as is. > # B: Read block 2 and wait for the completion hook to be reached (which could > # be in B itself or in an IO worker) > > should say blocks 2-3 Fixed. > I wonder if it is also worth testing a failed foreign IO (i.e. > operation->foreign_io && !(buf_state & BM_VALID) in > WaitReadBuffers()). I don't know that it is much different than the > other failed IO_IN_PROGRESS cases you are already testing. It might be, but it's getting late, and I would like to see this go in, to unblock the prefetching thread. And it'd be somewhat cumbersome to write, unfortunately. So I'll forgo that for now. > Otherwise, I think we're ready to go! Yay. Pushed. Thanks for the collab! Greetings, Andres Freund