pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: Peter Geoghegan <pg@bowt.ie>
Cc: Luca Ferrari <fluca1978@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: could not read block 0 in file : read only 0 of 8192 bytes when doing nasty on immutable index function
Date: Tue, 31 Jul 2018 19:02:11 -0700
Message-ID: <20180801020211.fqrubprbstrdcg6p@alap3.anarazel.de> (raw)
In-Reply-To: <CAH2-WzmgqMxL5X0saGkAGYE2AU3xYgrtoAUmX_fwrEP1SaBzAg@mail.gmail.com>
References: <CAKoxK+5fVodiCtMsXKV_1YAKXbzwSfp7DgDqUmcUAzeAhf=HEQ@mail.gmail.com>
	<20180627204439.4b7miflyolm4qtcz@alap3.anarazel.de>
	<CAKoxK+5bCn5d0R5v6j8SQQtUobu9R+m1xTTat8zsD1jH3izeDA@mail.gmail.com>
	<CAKoxK+7gQjxWYZiUm5q9M9dxd1mBgi=1rDwN0UNZbkXvB37Eiw@mail.gmail.com>
	<20180628150209.n2qch5jtn3vt2xaa@alap3.anarazel.de>
	<CAH2-Wzn1DDZ6HSDwOpD2b964mqpPDqsE1nAfbHr+TU5cBo219A@mail.gmail.com>
	<20180709183201.zn53uwiwqozhettk@alap3.anarazel.de>
	<CAH2-WzmgqMxL5X0saGkAGYE2AU3xYgrtoAUmX_fwrEP1SaBzAg@mail.gmail.com>

On 2018-07-31 18:48:23 -0700, Peter Geoghegan wrote:
> On Mon, Jul 9, 2018 at 11:32 AM, Andres Freund <andres@anarazel.de> wrote:
> > I assume we'll have to backpatch this issue, so I think it'd probably a
> > good idea to put a specific CacheInvalidateHeapTuple() in there
> > explicitly in the back branches, and do the larger fix in 12. ISTM
> > there's some risks that it'd cause issues.
> 
> What do you think of the attached?
> 
> The is a new CacheInvalidateRelcache() call, rather than a new call to
> CacheInvalidateRelcacheByTuple(), but those two things are equivalent
> (I assume that you actually meant to say
> CacheInvalidateRelcacheByTuple(), not CacheInvalidateHeapTuple()).

Right.


> From 18ffbcc81c75525c73930ad3b5a63ae0873d2381 Mon Sep 17 00:00:00 2001
> From: Peter Geoghegan <pg@bowt.ie>
> Date: Tue, 31 Jul 2018 18:33:30 -0700
> Subject: [PATCH] Add table relcache invalidation to index builds.
> 
> It's necessary to make sure that owning tables have a relcache
> invalidation prior to advancing the command counter to make
> newly-entered catalog tuples for the index visible.  inval.c must be
> able to roll back the local caches in the event of transaction abort.
> There is only a problem when CREATE INDEX transactions abort, since
> there is a generic invalidation once we reach index_update_stats().
> 
> This bug is of long standing.  Problems were made much more likely by
> the addition of parallel CREATE INDEX (commit 9da0cc35284), but it is
> strongly suspected that similar problems can be triggered without
> involving plan_create_index_workers().

Maybe expand a bit on this by saying that it's more likely "because
plan_create_index_workers() triggers a relcache entry to be (re-)built,
which previously did only happen in edge cases" or such?

> Bug diagnosed by Andres Freund.
> 
> Author: Peter Geoghegan
> Reported-By: Luca Ferrari
> Discussion: https://postgr.es/m/CAKoxK+5fVodiCtMsXKV_1YAKXbzwSfp7DgDqUmcUAzeAhf=HEQ@mail.gmail.com
> Backpatch: 9.3-
> ---
>  src/backend/catalog/index.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
> index 8b276bc430..7036d72bd6 100644
> --- a/src/backend/catalog/index.c
> +++ b/src/backend/catalog/index.c
> @@ -1137,6 +1137,19 @@ index_create(Relation heapRelation,
>  	InvokeObjectPostCreateHookArg(RelationRelationId,
>  								  indexRelationId, 0, is_internal);
>  
> +	/*
> +	 * Invalidate the relcache for the owning table, so that any local
> +	 * relcache entry for the new index built after CommandCounterIncrement
> +	 * won't become inconsistent in the event of transaction abort.  inval.c
> +	 * must be able to roll back the local caches when aborting.  Clearly it
> +	 * isn't useful to create an index whose definition results in a relcache
> +	 * entry for the index being allocated before commit, but the local caches
> +	 * cannot be allowed to become inconsistent under any circumstances.
> +	 * (There is only an issue when transactions abort because we'll reach
> +	 * index_update_stats when they commit.)
> +	 */

Not a fan of this comment. It doesn't really explain that well why it's
needed here, but then goes on to a relatively general explanation of why
cache invalidation is necessary.  Why not just go for something like
"register relcache invalidation on the indexes' heap relation, to
maintain consistency of its index list"?

I wonder if it wouldn't be more appropriately placed closer to the
UpdateIndexRelation(), given that that's essentially what necessitates
the relcache flush?

Greetings,

Andres Freund




view thread (20+ messages)  latest in thread

Message-ID: <20180801020211.fqrubprbstrdcg6p@alap3.anarazel.de>
Permalink:  ../20180801020211.fqrubprbstrdcg6p@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20180801020211.fqrubprbstrdcg6p@alap3.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@anarazel.de, pg@bowt.ie, fluca1978@gmail.com, pgsql-general@postgresql.org
  Subject: Re: could not read block 0 in file : read only 0 of 8192 bytes when doing nasty on immutable index function
  In-Reply-To: <20180801020211.fqrubprbstrdcg6p@alap3.anarazel.de>
  References: <CAKoxK+5fVodiCtMsXKV_1YAKXbzwSfp7DgDqUmcUAzeAhf=HEQ@mail.gmail.com> <20180627204439.4b7miflyolm4qtcz@alap3.anarazel.de> <CAKoxK+5bCn5d0R5v6j8SQQtUobu9R+m1xTTat8zsD1jH3izeDA@mail.gmail.com> <CAKoxK+7gQjxWYZiUm5q9M9dxd1mBgi=1rDwN0UNZbkXvB37Eiw@mail.gmail.com> <20180628150209.n2qch5jtn3vt2xaa@alap3.anarazel.de> <CAH2-Wzn1DDZ6HSDwOpD2b964mqpPDqsE1nAfbHr+TU5cBo219A@mail.gmail.com> <20180709183201.zn53uwiwqozhettk@alap3.anarazel.de> <CAH2-WzmgqMxL5X0saGkAGYE2AU3xYgrtoAUmX_fwrEP1SaBzAg@mail.gmail.com> <20180801020211.fqrubprbstrdcg6p@alap3.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