pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Abhijit Menon-Sen <ams@2ndQuadrant.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Haribabu Kommi <kommi.haribabu@gmail.com>
Cc: Thom Brown <thom@linux.com>
Cc: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [BUGS] Breakage with VACUUM ANALYSE + partitions
Date: Thu, 14 Apr 2016 11:09:29 +0530
Message-ID: <20160414053929.GA29751@toroid.org> (raw)
In-Reply-To: <CA+TgmobNCZ_uZhO-mo4ArKWNGyoe8bY+Gvy7egHVSzHMqoiL5Q@mail.gmail.com>
References: <CAJrrPGd5ks_r94FEUBs_EA30o5_oVuO6KvOLcVGcigauKKZHdQ@mail.gmail.com>
	<CA+TgmoZiF3_hG8-M6hq_Z-O=VoyNd9FtbmVTw+YcM+Fn-m_rfw@mail.gmail.com>
	<CAB7nPqSBFmh5cQjpRbFBp9Rkv1nF=Nh2o1FxKkJ6yvOBtvYDBA@mail.gmail.com>
	<CA+TgmobDyysoEX0GQVaPwYHk-joMJWyUkpiuyc6w656ewB_Hig@mail.gmail.com>
	<20160326123942.qnuwqg3yg2y7ae4p@alap3.anarazel.de>
	<CA+TgmoYEku8CGaQ7me5+T0Q82jKMrQHPcpOApogag0K2KbiAkQ@mail.gmail.com>
	<20160411165054.r35o4fjicdg4avs7@alap3.anarazel.de>
	<CA+TgmoaX35ui4DVN_74YyxS_gtfMXPo4pkru-AAkBoSCh9FLuA@mail.gmail.com>
	<20160411171742.n5xebjt7tcdy4sxf@alap3.anarazel.de>
	<CA+TgmobNCZ_uZhO-mo4ArKWNGyoe8bY+Gvy7egHVSzHMqoiL5Q@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

At 2016-04-12 09:00:57 -0400, robertmhaas@gmail.com wrote:
>
> On Mon, Apr 11, 2016 at 1:17 PM, Andres Freund <andres@anarazel.de> wrote:
> >
> > 3) Actually handle the case of the last open segment not being
> >    RELSEG_SIZE properly in _mdfd_getseg() - mdnblocks() does so.
> 
> #3 seems like it's probably about 15 years overdue, so let's do that
> anyway.

I don't have anything useful to contribute, I'm just trying to
understand this fix.

_mdfd_getseg() looks like this:

	targetseg = blkno / ((BlockNumber) RELSEG_SIZE);
	for (nextsegno = 1; nextsegno <= targetseg; nextsegno++)
	{
		Assert(nextsegno == v->mdfd_segno + 1);

		if (v->mdfd_chain == NULL)
		{
			/*
			 * Normally we will create new segments only if authorized by the
			 * caller (i.e., we are doing mdextend()). […]
			 */
			if (behavior == EXTENSION_CREATE || InRecovery)
			{
				if (_mdnblocks(reln, forknum, v) < RELSEG_SIZE)
                                    /* mdextend */
				v->mdfd_chain = _mdfd_openseg(reln, forknum, +nextsegno, O_CREAT);
			}
			else
			{
				/* We won't create segment if not existent */
				v->mdfd_chain = _mdfd_openseg(reln, forknum, nextsegno, 0);
			}
			if (v->mdfd_chain == NULL)
                            /* return NULL or ERROR */
		}
		v = v->mdfd_chain;
	}

Do I understand correctly that the case of the "last open segment"
(i.e., the one for which mdfd_chain == NULL) not being RELSEG_SIZE
(i.e., _mdnblocks(reln, forknum, v) < RELSEG_SIZE) should not call
_mfdf_openseg on nextsegno if behaviour is not EXTENSION_CREATE or
InRecovery?

And that "We won't create segment if not existent" should happen, but
doesn't only because the next segment file wasn't removed earlier, so
we have to add an extra check for that case?

In other words, is something like the following what's needed here, or
is there more to it?

-- Abhijit

inline patch 1: src/backend/storage/smgr/md.c (+4/-2 lines) download inline-1.patchdiff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index 578276d..58ea5a0 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -1783,6 +1783,8 @@ _mdfd_getseg(SMgrRelation reln, ForkNumber forknum, BlockNumber blkno, if (v->mdfd_chain == NULL) { + bool thisSegNeedsExtension = _mdnblocks(reln, forknum, v) < RELSEG_SIZE; + /* * Normally we will create new segments only if authorized by the * caller (i.e., we are doing mdextend()). But when doing WAL @@ -1799,7 +1801,7 @@ _mdfd_getseg(SMgrRelation reln, ForkNumber forknum, BlockNumber blkno, */ if (behavior == EXTENSION_CREATE || InRecovery) { - if (_mdnblocks(reln, forknum, v) < RELSEG_SIZE) + if (thisSegNeedsExtension) { char *zerobuf = palloc0(BLCKSZ); @@ -1810,7 +1812,7 @@ _mdfd_getseg(SMgrRelation reln, ForkNumber forknum, BlockNumber blkno, } v->mdfd_chain = _mdfd_openseg(reln, forknum, +nextsegno, O_CREAT); } - else + else if (!thisSegNeedsExtension) { /* We won't create segment if not existent */ v->mdfd_chain = _mdfd_openseg(reln, forknum, nextsegno, 0);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers

view thread (64+ messages)  latest in thread

Message-ID: <20160414053929.GA29751@toroid.org>
Permalink:  ../20160414053929.GA29751@toroid.org/
Also on:    postgresql.org/message-id/20160414053929.GA29751@toroid.org

 ·  · 

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: ams@2ndQuadrant.com, robertmhaas@gmail.com, andres@anarazel.de, michael.paquier@gmail.com, kommi.haribabu@gmail.com, thom@linux.com, coelho@cri.ensmp.fr, pgsql-hackers@postgresql.org
  Subject: Re: [BUGS] Breakage with VACUUM ANALYSE + partitions
  In-Reply-To: <20160414053929.GA29751@toroid.org>
  References: <CAJrrPGd5ks_r94FEUBs_EA30o5_oVuO6KvOLcVGcigauKKZHdQ@mail.gmail.com> <CA+TgmoZiF3_hG8-M6hq_Z-O=VoyNd9FtbmVTw+YcM+Fn-m_rfw@mail.gmail.com> <CAB7nPqSBFmh5cQjpRbFBp9Rkv1nF=Nh2o1FxKkJ6yvOBtvYDBA@mail.gmail.com> <CA+TgmobDyysoEX0GQVaPwYHk-joMJWyUkpiuyc6w656ewB_Hig@mail.gmail.com> <20160326123942.qnuwqg3yg2y7ae4p@alap3.anarazel.de> <CA+TgmoYEku8CGaQ7me5+T0Q82jKMrQHPcpOApogag0K2KbiAkQ@mail.gmail.com> <20160411165054.r35o4fjicdg4avs7@alap3.anarazel.de> <CA+TgmoaX35ui4DVN_74YyxS_gtfMXPo4pkru-AAkBoSCh9FLuA@mail.gmail.com> <20160411171742.n5xebjt7tcdy4sxf@alap3.anarazel.de> <CA+TgmobNCZ_uZhO-mo4ArKWNGyoe8bY+Gvy7egHVSzHMqoiL5Q@mail.gmail.com> <20160414053929.GA29751@toroid.org>

* 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