Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W2oJT-0006jF-Ev for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Jan 2014 20:40:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W2oJS-0001tT-Mw for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Jan 2014 20:40:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W2oJP-0001p6-Dm for pgsql-bugs@postgresql.org; Mon, 13 Jan 2014 20:40:43 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W2oJL-0002Iv-PY for pgsql-bugs@postgresql.org; Mon, 13 Jan 2014 20:40:43 +0000 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 5ADBC284B9; Mon, 13 Jan 2014 12:40:36 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 3F0EB1844E; Mon, 13 Jan 2014 12:40:36 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 1FC31C005A; Mon, 13 Jan 2014 12:41:11 -0800 (PST) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA; Mon, 13 Jan 2014 12:41:09 -0800 (PST) Message-ID: <52D44F40.1000803@vmware.com> Date: Mon, 13 Jan 2014 22:40:32 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10 MIME-Version: 1.0 To: Andres Freund CC: Tom Lane , Sergey Konoplev , matioli.matheus@gmail.com, pgsql-bugs , Maxim Boguk , =?UTF-8?B?0JzQsNC60YHQuNC8INCf0LDQvdGH0LXQvdC60L4=?= , =?UTF-8?B?0KHQuNC30L7QsiDQodC10YDQs9C10Lkg0J/QsA==?= =?UTF-8?B?0LLQu9C+0LLQuNGH?= Subject: Re: Hot standby 9.2.6 -> 9.2.6 PANIC: WAL contains references to invalid pages References: <20140106134815.GE28320@alap2.anarazel.de> <52CABF3E.2050004@vmware.com> <17450.1389644346@sss.pgh.pa.us> <20140113202600.GB14861@awork2.anarazel.de> In-Reply-To: <20140113202600.GB14861@awork2.anarazel.de> Content-Type: multipart/mixed; boundary="------------000709020801020806040206" X-Pg-Spam-Score: -7.0 (-------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------000709020801020806040206 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 01/13/2014 10:26 PM, Andres Freund wrote: > On 2014-01-13 15:19:06 -0500, Tom Lane wrote: >> I concur that the right fix requires a >> new operating mode for XLogReadBufferExtended, perhaps RBM_NORMAL_ZERO_OK. >> I think the spec for this should be that if the page doesn't exist or >> contains zeroes, we return InvalidBuffer without logging the page number >> as invalid. The doesn't-exist case is justified by the expectation that >> there will be a later RBM_NORMAL call for a larger page number, which will >> result in a suitable complaint if the page range isn't there. I think it's more natural to return the empty page to the caller, rather than InvalidBuffer. > That's a sensible way to go, yes. But I wonder if we wouldn't end up > with less complicated code if we added a variant of ReadBuffer that only > returns a buffer from cache if already present in s_b. > I started to prototype something like RBM_NORMAL_ZERO_OK shortly after > Heikki's message and it seems to quickly turn a bit ugly because the > surrounding code isn't really ready to deal with not returning a > buffer. And for the purpose of that redo routine, that'd actually be > better. If it's trivial to add such a mode to buffer cache, then sure, let's do that by all means. But I seriously doubt it's really simple enough to be back-patchable. With RBM_NORMAL_ZERO_OK, AFAICS we're talking about a tiny patch to XLogReadBufferExtended. bufmgr.c doesn't need to do anything about the new mode, as it's XLogReadBuffer that does the the check for zero pages. Per attached patch (for demonstration purposes only, you also need to add the new mode to the header file and adjust comments). - Heikki --------------000709020801020806040206 Content-Type: text/x-diff; name="rbm_normal_zero_ok-1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="rbm_normal_zero_ok-1.patch" diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 59f4233..958bcaa 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -296,6 +296,19 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, BlockNumber lastblock; Buffer buffer; SMgrRelation smgr; + bool zero_page_allowed; + + if (mode == RBM_NORMAL_ZERO_OK) + { + /* + * Treat RBM_NORMAL_ZERO_OK just like RBM_NORMAL, except for the + * PageIsNew() check at the end. + */ + mode = RBM_NORMAL; + zero_page_allowed = true; + } + else + zero_page_allowed = false; Assert(blkno != P_NEW); @@ -343,7 +356,7 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, Assert(BufferGetBlockNumber(buffer) == blkno); } - if (mode == RBM_NORMAL) + if (mode == RBM_NORMAL && !zero_page_allowed) { /* check that page has been initialized */ Page page = (Page) BufferGetPage(buffer); --------------000709020801020806040206 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------000709020801020806040206--