Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEpCE-0000yh-PG for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Oct 2018 05:25:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gEpCA-0000l6-TH for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Oct 2018 05:25:34 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEpCA-0000je-HH for pgsql-hackers@lists.postgresql.org; Tue, 23 Oct 2018 05:25:34 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gEpC6-0006RK-9r for pgsql-hackers@postgresql.org; Tue, 23 Oct 2018 05:25:32 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id CF9CB21C2318; Tue, 23 Oct 2018 08:25:28 +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.0.103] (unknown [5.79.142.119]) (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 8C3B421C212D; Tue, 23 Oct 2018 08:25:28 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1540272328; bh=B57ppIhz7Ju6tsjsaHSNSXLq2okfm21gm3vempy1Vws=; h=Subject:To:References:From:Date:In-Reply-To; b=XSSdPDdIcBJUhkhSNFozeDPFQLBnBrJ5x6ERHZYjLLv/FRZZSlO54VOzs6tI7w7+3 AB8DQthHSgncij36t1MeugXlChrWH+nmqcV6GD6JrB784VwjYtI0fW0hQbEkO168Fn 9RyRbo9aGifb1Jrge25nBEFBNtYr5meQLTR8X+3c= Subject: Re: [PATCH] XLogReadRecord returns pointer to currently read page To: Heikki Linnakangas , PostgreSQL-Dev References: <25cc0d31-a5c7-2b7d-e66e-f5cc9f2d4985@iki.fi> <5f701ad0-6c3c-67f2-e5ce-dbf2f60a7d2d@postgrespro.ru> <57759569-fa21-4a09-9f79-b1d257a48849@iki.fi> From: Andrey Lepikhov Organization: Postgres Professional Message-ID: <2553f2b0-0e39-eb0e-d382-6c0ed08ca8ae@postgrespro.ru> Date: Tue, 23 Oct 2018 10:25:27 +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: <57759569-fa21-4a09-9f79-b1d257a48849@iki.fi> Content-Type: multipart/mixed; boundary="------------236781EFBD62D9C388E8C063" 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. --------------236781EFBD62D9C388E8C063 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 23.10.2018 0:53, Heikki Linnakangas wrote: > I'd expect the decompression to read from the on-disk buffer, and unpack > to readRecordBuf, I still don't see a need to copy the packed record to > readRecordBuf. If there is a need for that, though, the patch that > implements the packing or compression can add the memcpy() where it > needs it. I agree with it. Eventually, placement of the WAL-record can be defined by comparison the record, readBuf and readRecordBuf pointers. In attachment new version of the patch. -- Andrey Lepikhov Postgres Professional https://postgrespro.com The Russian Postgres Company --------------236781EFBD62D9C388E8C063 Content-Type: text/x-patch; name="0001-WAL-record-buffer-pointer-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-WAL-record-buffer-pointer-fix.patch" From 36fd35dc75658f471efbc64fe2a3f204f0aa27e4 Mon Sep 17 00:00:00 2001 From: "Andrey V. Lepikhov" Date: Tue, 23 Oct 2018 10:17:55 +0500 Subject: [PATCH] WAL-record-buffer-pointer-fix --- src/backend/access/transam/xlogreader.c | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c index 0768ca7822..c5e019bf77 100644 --- a/src/backend/access/transam/xlogreader.c +++ b/src/backend/access/transam/xlogreader.c @@ -353,19 +353,6 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg) gotheader = false; } - /* - * Enlarge readRecordBuf as needed. - */ - if (total_len > state->readRecordBufSize && - !allocate_recordbuf(state, total_len)) - { - /* We treat this as a "bogus data" condition */ - report_invalid_record(state, "record length %u at %X/%X too long", - total_len, - (uint32) (RecPtr >> 32), (uint32) RecPtr); - goto err; - } - len = XLOG_BLCKSZ - RecPtr % XLOG_BLCKSZ; if (total_len > len) { @@ -375,6 +362,19 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg) char *buffer; uint32 gotlen; + /* + * Enlarge readRecordBuf as needed. + */ + if (total_len > state->readRecordBufSize && + !allocate_recordbuf(state, total_len)) + { + /* We treat this as a "bogus data" condition */ + report_invalid_record(state, "record length %u at %X/%X too long", + total_len, + (uint32) (RecPtr >> 32), (uint32) RecPtr); + goto err; + } + /* Copy the first fragment of the record from the first page. */ memcpy(state->readRecordBuf, state->readBuf + RecPtr % XLOG_BLCKSZ, len); @@ -479,7 +479,6 @@ XLogReadRecord(XLogReaderState *state, XLogRecPtr RecPtr, char **errormsg) state->EndRecPtr = RecPtr + MAXALIGN(total_len); state->ReadRecPtr = RecPtr; - memcpy(state->readRecordBuf, record, total_len); } /* -- 2.17.1 --------------236781EFBD62D9C388E8C063--