pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@2ndquadrant.com>
To: Heikki Linnakangas <hlinnakangas@vmware.com>
Cc: levertond@googlemail.com
Cc: pgsql-bugs@postgresql.org
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Subject: Re: BUG #10533: 9.4 beta1 assertion failure in autovacuum process
Date: Fri, 20 Jun 2014 01:59:57 +0200
Message-ID: <20140619235957.GG16260@awork2.anarazel.de> (raw)
In-Reply-To: <5395B0C6.2070000@vmware.com>
References: <20140605180121.3061.28250@wrigleys.postgresql.org>
	<5390BA0F.2030103@vmware.com>
	<20140605213436.GA17217@awork2.anarazel.de>
	<20140609124616.GC3149@alap3.anarazel.de>
	<5395B0C6.2070000@vmware.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Hi Heikki, all,

On 2014-06-09 16:04:06 +0300, Heikki Linnakangas wrote:
> On 06/09/2014 03:46 PM, Andres Freund wrote:
> >>>I haven't thought particularly much about this, but I don't really see
> >>>why the heap_page_is_all_visible() bit needs to be in a critical
> >>>section? Can't we just do that entire bit after the log_heap_clean()?
> >>>Then the heap_page_is_all_visible() can be done outside a critical
> >>>section.
> >Before I start working on a patch along those lines, do you see any
> >problems with making the critical section smaller?
> 
> One subtle difference is that the PD_ALL_VISIBLE flag will not be included
> in the full-page-image that log_heap_page() might take. But that seems OK.
> visibilitymap_set() writes a WAL record that sets it at replay.

Heikki, you've changed things around a bit in 2a8e1ac598. That commit
message mentions that there's still a difference in which order things
happen on the master vs. the standby. Am I seeing it correctly that
reordering things like hinted at above (and in the attached patch) fully
gets rid of that problem? And doesn't reintroduce what you fixed?

I've verified that the crash occurs without the patch and doesn't with
it applied. I'm too tired right now to think enough about my fix to push
it.

Greetings,

Andres Freund

-- 
 Andres Freund	                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

0001-Do-all-visible-handling-in-lazy_vacuum_page-outside-.patch (text/x-patch, 3.1K) download From ed6cf7928eaa6a724fc2a6d96cd59db65afc6a8b Mon Sep 17 00:00:00 2001 From: Andres Freund <andres@anarazel.de> Date: Fri, 20 Jun 2014 01:17:33 +0200 Subject: [PATCH] Do all-visible handling in lazy_vacuum_page() outside its critical section. Since fdf9e21196a lazy_vacuum_page() rechecks the all-visible status of pages in the second pass over the heap. It does so inside a critical section, but both visibilitymap_test() and heap_page_is_all_visible() perform operations that should not happen inside one. The former potentially performs IO and both potentially do memory allocations. To fix, simply move all the all-visible handling outside the critical section. Doing so means that the PD_ALL_VISIBLE on the page won't be included in the full page image of the HEAP2_CLEAN record anymore. But that's fine, the flag will be set by the HEAP2_VISIBLE logged later. Backpatch to 9.3 where the problem was introduced. The bug only came to light due to the assertion added in 4a170ee9 and isn't likely to cause problems in production scenarios. The worst outcome is a avoidable PANIC restart. This also gets rid of the difference in the order of operations between master and standby mentioned in 2a8e1ac5. Per reports from David Leverton and Keith Fiske in bug #10533. --- src/backend/commands/vacuumlazy.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/backend/commands/vacuumlazy.c b/src/backend/commands/vacuumlazy.c index b4abeed..5d6d031 100644 --- a/src/backend/commands/vacuumlazy.c +++ b/src/backend/commands/vacuumlazy.c @@ -1214,13 +1214,6 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer, PageRepairFragmentation(page); /* - * Now that we have removed the dead tuples from the page, once again - * check if the page has become all-visible. - */ - if (heap_page_is_all_visible(onerel, buffer, &visibility_cutoff_xid)) - PageSetAllVisible(page); - - /* * Mark buffer dirty before we write WAL. */ MarkBufferDirty(buffer); @@ -1238,6 +1231,23 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer, } /* + * End critical section, so we safely can do visibility tests (which + * possibly need to perform IO and allocate memory!). If we crash now the + * page (including the corresponding vm bit) might not be marked all + * visible, but that's fine. A later vacuum will fix that. + */ + END_CRIT_SECTION(); + + /* + * Now that we have removed the dead tuples from the page, once again + * check if the page has become all-visible. The page is already marked + * dirty, exclusively locked, and, if needed, a full page image has been + * emitted in the log_heap_clean() above. + */ + if (heap_page_is_all_visible(onerel, buffer, &visibility_cutoff_xid)) + PageSetAllVisible(page); + + /* * All the changes to the heap page have been done. If the all-visible * flag is now set, also set the VM bit. */ @@ -1249,8 +1259,6 @@ lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer, visibility_cutoff_xid); } - END_CRIT_SECTION(); - return tupindex; } -- 2.0.0.rc2.4.g1dc51c6.dirty

view thread (21+ messages)  latest in thread

Message-ID: <20140619235957.GG16260@awork2.anarazel.de>
Permalink:  ../20140619235957.GG16260@awork2.anarazel.de/
Also on:    postgresql.org/message-id/20140619235957.GG16260@awork2.anarazel.de

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andres@2ndquadrant.com, hlinnakangas@vmware.com, levertond@googlemail.com, alvherre@2ndquadrant.com
  Subject: Re: BUG #10533: 9.4 beta1 assertion failure in autovacuum process
  In-Reply-To: <20140619235957.GG16260@awork2.anarazel.de>
  References: <20140605180121.3061.28250@wrigleys.postgresql.org> <5390BA0F.2030103@vmware.com> <20140605213436.GA17217@awork2.anarazel.de> <20140609124616.GC3149@alap3.anarazel.de> <5395B0C6.2070000@vmware.com> <20140619235957.GG16260@awork2.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox