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 1rTCTf-001524-GJ for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2024 03:02: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 1rTCTe-007tDZ-JJ for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2024 03:01:58 +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 1rTCTe-007tCQ-4Y for pgsql-hackers@lists.postgresql.org; Fri, 26 Jan 2024 03:01:58 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rTCTb-003P3O-2H for pgsql-hackers@lists.postgresql.org; Fri, 26 Jan 2024 03:01:56 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6dbb003be79so1150855b3a.0 for ; Thu, 25 Jan 2024 19:01:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1706238114; x=1706842914; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=8JhHtzIVKb3NlcNQCMdo3TUMfAc3uIIrpcXhdbwc8us=; b=mbrAI1fGKNOQkR98LYGfw+qByGMy8+EpBCL2zA5hc9Se3z5TX5chdMD2TPXODi0ag6 paEB4i8sCt9n1ts61GfI+yTFfE48oAnP3LEhr7T9lvOeJTB44waJSVTOrA79RiWQVKMo q+g4fieZyxpFY+F73YbMuIm+0Tn7v2LKln/W0AATiMx2//nAG/X1do6Wltdda1x3wH3Q nI0to7cjzGEvr9Sm6urMFRQnLph+ZgQXqWAfhhEFf5fOUUnlsXWyS4tUMN25LdVtolZE faPtwv8Y7FQvt+nlvbJgOG2hObC+H1jtaiQ2kWCsQX02tl5oBOyxRIwIHBCYcpWJ2b7W lXSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706238114; x=1706842914; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8JhHtzIVKb3NlcNQCMdo3TUMfAc3uIIrpcXhdbwc8us=; b=JHJBosDitVGO9SvT3mVRhw6fbOu2F/C4ev5nAP5wYf2FXN6DWDHQBhctX0ObcsxnXW Stbw9YFOo7RroqCk9dY+7W7H67RwArOr3XjDozj4616/34gbp2OXlZ3IZN75vn77kzWG Xls14yTTB1/3WeoEgrSuXmiP9FCSRuTXLF4EDDfbcfAOEDOsuLcYACHMDTCiukG4Aqn/ D8DUBZiECIHuMnFVZtWMybvQTKXhl0Gve+1IzuMzM5rZznZQCH3sl5LANCVbS+PxX2L6 szhxYLdgomTyQsXreLlH+oI1tSoBnVF3WZISJsTnOm4lnGfzIBLVS/sjAI6WNu/1KAPs r7EA== X-Gm-Message-State: AOJu0Yz4Acvah+rmK75rQZWNRCQM6ZNcgu5q1sbLIzllrkQ4rlxmoLz5 HPyN2xWvNAZpbH7yCepbHGsD1smLP5+3Vzs/N66zqX451FluTH/qMdK84wr73w== X-Google-Smtp-Source: AGHT+IGu7TyH0aJ0YeGYHj/Y/CZcyKA4FR5Q+rIbMS/y0yeXkXdK3QZhXhznFd1/SXtoPDDS9WUK4g== X-Received: by 2002:a05:6a21:999e:b0:19b:7ff8:8a5e with SMTP id ve30-20020a056a21999e00b0019b7ff88a5emr453609pzb.4.1706238113972; Thu, 25 Jan 2024 19:01:53 -0800 (PST) Received: from [172.18.10.46] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id b2-20020a056a00114200b006dde18ed7dbsm237653pfm.170.2024.01.25.19.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 19:01:53 -0800 (PST) Message-ID: Subject: Re: Improve WALRead() to suck data directly from WAL buffers when possible From: Jeff Davis To: Bharath Rupireddy Cc: Andres Freund , Dilip Kumar , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org, Nathan Bossart , Masahiko Sawada Date: Thu, 25 Jan 2024 19:01:52 -0800 In-Reply-To: References: <20231104004348.zhxzk2p266i3r2z2@awork3.anarazel.de> <20231109205836.zjoawdrn4q77yemv@awork3.anarazel.de> <3750ff9c2a5556808827e7fc5bcc0bd16e9facf4.camel@j-davis.com> <73df9831747b01ced949102610dc44ca6026ee1c.camel@j-davis.com> <20240122201218.bclrdkwpmuk26fl3@awork3.anarazel.de> <2b36bf99e762e65db0dafbf8d338756cf5fa6ece.camel@j-davis.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2024-01-25 at 14:35 +0530, Bharath Rupireddy wrote: >=20 > "expecting zeros at the end" - this can't always be true as the WAL >=20 ... > I think this needs to be discussed separately. If okay, I'll start a > new thread. Thank you for investigating. When the above issue is handled, I'll be more comfortable expanding the call sites for XLogReadFromBuffers(). > > Also, if we've detected that the first requested buffer has been > > evicted, is there any value in continuing the loop to see if more > > recent buffers are available? For example, if the requested LSNs > > range > > over buffers 4, 5, and 6, and 4 has already been evicted, should we > > try > > to return LSN data from 5 and 6 at the proper offset in the dest > > buffer? If so, we'd need to adjust the API so the caller knows what > > parts of the dest buffer were filled in. >=20 > I'd second this capability for now to keep the API simple and clear, > but we can consider expanding it as needed. Agreed. This case doesn't seem important; I just thought I'd ask about it. > If the callers use GetFlushRecPtr() to determine how far to read, > LogwrtResult will be *reasonably* latest It will be up-to-date enough that we'd never go through WaitXLogInsertionsToFinish(), which is all we care about. > As far as the current WAL readers are concerned, we don't need an > explicit spinlock to determine LogwrtResult because all of them use > GetFlushRecPtr() to determine how far to read. If there's any caller > that's not updating LogwrtResult at all, we can consider reading > LogwrtResult it ourselves in future. So we don't actually need that path yet, right? > 5. I think the two requirements specified at > https://www.postgresql.org/message-id/20231109205836.zjoawdrn4q77yemv%40a= work3.anarazel.de > still hold with the v19j. Agreed. > PSA v20 patch set. 0001 is very close. I have the following suggestions: * Don't just return zero. If the caller is doing something we don't expect, we want to fix the caller. I understand you'd like this to be more like a transparent optimization, and we may do that later, but I don't think it's a good idea to do that now. * There's currently no use for reading LSNs between Write and Insert, so remove the WaitXLogInsertionsToFinish() code path. That also means we don't need the extra emitLog parameter, so we can remove that. When we have a use case, we can bring it all back. If you agree, I can just make those adjustments (and do some final checking) and commit 0001. Otherwise let me know what you think. 0002: How does the test control whether the data requested is before the Flush pointer, the Write pointer, or the Insert pointer? What if the walwriter comes in and moves one of those pointers before the next statement is executed? Also, do you think a test module is required for the basic functionality in 0001, or only when we start doing more complex things like reading past the Flush pointer? 0003: can you explain why this is useful for wal summarizer to read from the buffers? Regards, Jeff Davis