OSDN Git Service

Fix a problem introduced by my patch of 2010-01-12 that revised the way
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 14 Apr 2010 21:31:11 +0000 (21:31 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 14 Apr 2010 21:31:11 +0000 (21:31 +0000)
commit73981cb4512a57adcb2f90a9c3cebf5ab13cf0fe
treeb97622ad7de310c07dc980791bed7ae92d85e4fd
parent9d137a756fb7fd7e7f1b2f932009abd0aea4ff79
Fix a problem introduced by my patch of 2010-01-12 that revised the way
relcache reload works.  In the patched code, a relcache entry in process of
being rebuilt doesn't get unhooked from the relcache hash table; which means
that if a cache flush occurs due to sinval queue overrun while we're
rebuilding it, the entry could get blown away by RelationCacheInvalidate,
resulting in crash or misbehavior.  Fix by ensuring that an entry being
rebuilt has positive refcount, so it won't be seen as a target for removal
if a cache flush occurs.  (This will mean that the entry gets rebuilt twice
in such a scenario, but that's okay.)  It appears that the problem can only
arise within a transaction that has previously reassigned the relfilenode of
a pre-existing table, via TRUNCATE or a similar operation.  Per bug #5412
from Rusty Conover.

Back-patch to 8.2, same as the patch that introduced the problem.
I think that the failure can't actually occur in 8.2, since it lacks the
rd_newRelfilenodeSubid optimization, but let's make it work like the later
branches anyway.

Patch by Heikki, slightly editorialized on by me.
src/backend/utils/cache/relcache.c