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 1rZfr7-005nt7-Vx for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Feb 2024 23:36:58 +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 1rZfr6-00EDQJ-Gb for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Feb 2024 23:36:56 +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.94.2) (envelope-from ) id 1rZfr6-00EDQB-7A for pgsql-hackers@lists.postgresql.org; Mon, 12 Feb 2024 23:36:56 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rZfr3-006ReU-IA for pgsql-hackers@lists.postgresql.org; Mon, 12 Feb 2024 23:36:54 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id A36083200A62; Mon, 12 Feb 2024 18:36:50 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 12 Feb 2024 18:36:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-transfer-encoding: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=fm3; t=1707781010; x=1707867410; bh=AhFGnnLqkW+dA1lTcii32tWPmIr1CGd0PnWLt0Ib4s4=; b= EZrGZZNoHbu2Z7Y9CltyIAo+AnZk63euYVAHxcybDTzEdI+F14xZvBMBvtqgoFDx XrpzzHEvor0U/TnTQOwbaYLDN/uW61o3/DDtcDZbAYIoHpZfDC7xDojolI/QgzUz saVD9kWRiQnMI2V9x6J8EQUMmL03QxlOS7aRTsWNtN042JS9c6MFF183Te4LxKml 3yHDou2o18NRL+z6gcIhHgh488pb3NXXpbydL8FMao4FAongg8KDDVemf4m7A++1 aldYorHIZTv8gSkPhAClE+glibAw2NrEMswZ91mP1CluDsLc53A9f6j9wxigHoKg WZYbjNIZ5qcVvSFDKH/72g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1707781010; x= 1707867410; bh=AhFGnnLqkW+dA1lTcii32tWPmIr1CGd0PnWLt0Ib4s4=; b=l soMy92ptyndfTZWuH0D0i3kWRWJ45gHG/MwAo8oWV9K4vsW6IGusM6hQ8TKkrBmS EAEhqVSgXN4/eoIRRKFJ9v1grznSyP89RaYVAkBHtXsg0Y6Pb7X6P8fxVGXNPrOi 20mTRfiYc383dm5pDsfrJF6oLjhYubjavDF0DLyx0fRlmsLjcJIkyUcHbXDdGLVI OHeUNyj8nDre7gxpRdXFEjm1IhgqOywl5YC8BDSnThDRmwwb83ZOjP6X8T+DdotS c5M1q3hMlhw1d8W9cpMQe02HKZIDX5JAUfg168ZDZCCj9MlGAqnfdkiVDy7fSSXs Kahdufvm8BGtB2i8gqLZA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeggddufecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtugfgjgesthekredttddtudenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepuddtieegleejheeujeeiveegueelhfekleeuffdukeduleduffehfffg teeivefhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Feb 2024 18:36:49 -0500 (EST) Date: Mon, 12 Feb 2024 15:36:48 -0800 From: Andres Freund To: Jeff Davis Cc: Bharath Rupireddy , Alvaro Herrera , Dilip Kumar , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org, Nathan Bossart , Masahiko Sawada Subject: Re: Improve WALRead() to suck data directly from WAL buffers when possible Message-ID: <20240212233648.4ephivkh7ukkiv2k@awork3.anarazel.de> References: <202401301731.o3cthlcry4ve@alvherre.pgsql> <20240212201853.r6dl25onohrwagxt@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2024-02-12 12:46:00 -0800, Jeff Davis wrote: > On Mon, 2024-02-12 at 12:18 -0800, Andres Freund wrote: > > +    upto = Min(startptr + count, LogwrtResult.Write); > > +    nbytes = upto - startptr; > > > > Shouldn't it pretty much be a bug to ever encounter this? > > In the current code it's impossible, though Bharath hinted at an > extension which could reach that path. > > What I committed was a bit of a compromise -- earlier versions of the > patch supported reading right up to the Insert pointer (which requires > a call to WaitXLogInsertionsToFinish()). I wasn't ready to commit that > code without seeing a more about how that would be used, but I thought > it was reasonable to have some simple code in there to allow reading up > to the Write pointer. I doubt there's a sane way to use WALRead() without *first* ensuring that the range of data is valid. I think we're better of moving that responsibility explicitly to the caller and adding an assertion verifying that. > It seems closer to the structure that we will ultimately need to > replicate unflushed data, right? It doesn't really seem like a necessary, or even particularly useful, part. You couldn't just call WALRead() for that, since the caller would need to know the range up to which WAL is valid but not yet flushed as well. Thus the caller would need to first use WaitXLogInsertionsToFinish() or something like it anyway - and then there's no point in doing the WALRead() anymore. Note that for replicating unflushed data, we *still* might need to fall back to reading WAL data from disk. In which case not asserting in WALRead() would just make it hard to find bugs, because not using WaitXLogInsertionsToFinish() would appear to work as long as data is in wal buffers, but as soon as we'd fall back to on-disk (but unflushed) data, we'd send bogus WAL. Greetings, Andres Freund