pgsql: Fix incorrect order of operations during sinval reset processing

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix incorrect order of operations during sinval reset processing
Date: 2011-08-16 18:38:55
Message-ID: E1QtOXP-0004Uw-0K@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix incorrect order of operations during sinval reset processing.

We have to be sure that we have revalidated each nailed-in-cache relcache
entry before we try to use it to load data for some other relcache entry.
The introduction of "mapped relations" in 9.0 broke this, because although
we updated the state kept in relmapper.c early enough, we failed to
propagate that information into relcache entries soon enough; in
particular, we could try to fetch pg_class rows out of pg_class before
we'd updated its relcache entry's rd_node.relNode value from the map.

This bug accounts for Dave Gould's report of failures after "vacuum full
pg_class", and I believe that there is risk for other system catalogs
as well.

The core part of the fix is to copy relmapper data into the relcache
entries during "phase 1" in RelationCacheInvalidate(), before they'll be
used in "phase 2". To try to future-proof the code against other similar
bugs, I also rearranged the order in which nailed relations are visited
during phase 2: now it's pg_class first, then pg_class_oid_index, then
other nailed relations. This should ensure that RelationClearRelation can
apply RelationReloadIndexInfo to all nailed indexes without risking use
of not-yet-revalidated relcache entries.

Back-patch to 9.0 where the relation mapper was introduced.

Branch
------
REL9_0_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/38ef2e2fba79573f4ed37d572ea19217c8cf47ac

Modified Files
--------------
src/backend/utils/cache/relcache.c | 57 +++++++++++++++++++++--------------
1 files changed, 34 insertions(+), 23 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2011-08-16 19:26:53 pgsql: Forget about targeting catalog cache invalidations by tuple TID.
Previous Message Tom Lane 2011-08-16 17:48:41 pgsql: Preserve toast value OIDs in toast-swap-by-content for CLUSTER/V