Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gOcQ8-0006I7-4G for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Nov 2018 05:48:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gOcQ3-0007Je-RL for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Nov 2018 05:48:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gOcQ3-0007JX-Go for pgsql-hackers@lists.postgresql.org; Mon, 19 Nov 2018 05:48:23 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gOcPv-000153-JN for pgsql-hackers@postgresql.org; Mon, 19 Nov 2018 05:48:22 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 3E89E21C8498; Mon, 19 Nov 2018 08:48:14 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.129.217] (unknown [94.25.177.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 81DC521C6DC3; Mon, 19 Nov 2018 08:48:13 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1542606494; bh=7IZ4PAz5IuFA2gtKu4HQ9sie0EFfc5qvQdH/ZctJnIQ=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=TLVs0nyt2tt4SSykNNTeAm+xOER/0MyQeuE4y5JF2E2P6AwtB56HyIAmbUZii5AIC BbQ0yN7IhsWKIcTbJ7egAtz+3urUXjAAmCZQabO0659emYUBg1T9MyGjJsrYXndAIn BFgKwUNNh5wCOWxEfg0yK5eRVrwP13U//+oIHRY4= Subject: Re: [PATCH] XLogReadRecord returns pointer to currently read page To: Michael Paquier , Kyotaro HORIGUCHI Cc: hlinnaka@iki.fi, pgsql-hackers@postgresql.org References: <2553f2b0-0e39-eb0e-d382-6c0ed08ca8ae@postgrespro.ru> <20181026.143300.212568635.horiguchi.kyotaro@lab.ntt.co.jp> <20181115.181238.258013477.horiguchi.kyotaro@lab.ntt.co.jp> <20181116062355.GE6613@paquier.xyz> From: Andrey Lepikhov Organization: Postgres Professional Message-ID: <49518b48-2036-5e43-1818-0f594e375e76@postgrespro.ru> Date: Mon, 19 Nov 2018 10:48:06 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181116062355.GE6613@paquier.xyz> Content-Type: multipart/mixed; boundary="------------275E80DB405E777FD9980AC2" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------275E80DB405E777FD9980AC2 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On 16.11.2018 11:23, Michael Paquier wrote: > On Thu, Nov 15, 2018 at 06:12:38PM +0900, Kyotaro HORIGUCHI wrote: >> This patch eliminates unnecessary copying that was done for >> non-continued records. Now the return value of XLogReadRecord >> directly points into page buffer holded in XLogReaderStats. It is >> safe because no caller site uses the returned pointer beyond the >> replacement of buffer content at the next call to the same >> function. > > I was looking at this patch, and shouldn't we worry about compatibility > with plugins or utilities which look directly at what's in readRecordBuf > for the record contents? Let's not forget that the contents of > XLogReaderState are public. According to my experience, I clarify some comments to avoid this mistakes in the future (see attachment). -- Andrey Lepikhov Postgres Professional https://postgrespro.com The Russian Postgres Company --------------275E80DB405E777FD9980AC2 Content-Type: text/x-patch; name="0001-Some-clarifications-on-readRecordBuf-comments.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Some-clarifications-on-readRecordBuf-comments.patch" From 7de252405ef5d5979fe2711515c0c6402abc0e06 Mon Sep 17 00:00:00 2001 From: "Andrey V. Lepikhov" Date: Mon, 19 Nov 2018 07:08:28 +0500 Subject: [PATCH] Some clarifications on readRecordBuf comments --- src/backend/access/transam/xlogreader.c | 4 ++-- src/include/access/xlogreader.h | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index c5e019bf77..88d0bcf48a 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -209,8 +209,8 @@ allocate_recordbuf(XLogReaderState *state, uint32 reclength) * If the reading fails for some other reason, NULL is also returned, and * *errormsg is set to a string with details of the failure. * - * The returned pointer (or *errormsg) points to an internal buffer that's - * valid until the next call to XLogReadRecord. + * The returned pointer (or *errormsg) points to an internal read-only buffer + * that's valid until the next call to XLogReadRecord. */ XLogRecord * XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg) diff --git a/src/include/access/xlogreader.h b/src/include/access/xlogreader.h index 40116f8ecb..0837625b95 100644 --- a/src/include/access/xlogreader.h +++ b/src/include/access/xlogreader.h @@ -185,7 +185,11 @@ struct XLogReaderState */ TimeLineID nextTLI; - /* Buffer for current ReadRecord result (expandable) */ + /* + * Buffer for current ReadRecord result (expandable). + * Used in the case, than current ReadRecord result don't fit on the + * currently read WAL page. + */ char *readRecordBuf; uint32 readRecordBufSize; -- 2.17.1 --------------275E80DB405E777FD9980AC2--