pgsql: Try to acquire relation locks in RangeVarGetRelid.

From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Try to acquire relation locks in RangeVarGetRelid.
Date: 2011-07-09 02:19:48
Message-ID: E1QfN92-00027l-VJ@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Try to acquire relation locks in RangeVarGetRelid.

In the previous coding, we would look up a relation in RangeVarGetRelid,
lock the resulting OID, and then AcceptInvalidationMessages(). While
this was sufficient to ensure that we noticed any changes to the
relation definition before building the relcache entry, it didn't
handle the possibility that the name we looked up no longer referenced
the same OID. This was particularly problematic in the case where a
table had been dropped and recreated: we'd latch on to the entry for
the old relation and fail later on. Now, we acquire the relation lock
inside RangeVarGetRelid, and retry the name lookup if we notice that
invalidation messages have been processed meanwhile. Many operations
that would previously have failed with an error in the presence of
concurrent DDL will now succeed.

There is a good deal of work remaining to be done here: many callers
of RangeVarGetRelid still pass NoLock for one reason or another. In
addition, nothing in this patch guards against the possibility that
the meaning of an unqualified name might change due to the creation
of a relation in a schema earlier in the user's search path than the
one where it was previously found. Furthermore, there's nothing at
all here to guard against similar race conditions for non-relations.
For all that, it's a start.

Noah Misch and Robert Haas

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/4240e429d0c2d889d0cda23c618f94e12c13ade7

Modified Files
--------------
src/backend/access/heap/heapam.c | 42 ++---------
src/backend/catalog/aclchk.c | 7 ++-
src/backend/catalog/index.c | 3 +-
src/backend/catalog/namespace.c | 149 ++++++++++++++++++++++++++++-------
src/backend/commands/alter.c | 7 ++-
src/backend/commands/indexcmds.c | 13 +++-
src/backend/commands/lockcmds.c | 136 +++++++++++++-------------------
src/backend/commands/sequence.c | 15 +++-
src/backend/commands/tablecmds.c | 13 +++-
src/backend/commands/trigger.c | 18 ++++-
src/backend/commands/vacuum.c | 11 +++-
src/backend/parser/parse_relation.c | 8 ++-
src/backend/parser/parse_type.c | 10 ++-
src/backend/rewrite/rewriteDefine.c | 12 ++-
src/backend/rewrite/rewriteRemove.c | 10 ++-
src/backend/storage/ipc/sinval.c | 6 ++
src/backend/storage/lmgr/lmgr.c | 9 +-
src/backend/tcop/utility.c | 17 +++--
src/backend/utils/adt/acl.c | 3 +-
src/backend/utils/adt/regproc.c | 8 ++-
src/backend/utils/adt/ruleutils.c | 11 ++-
src/include/catalog/namespace.h | 4 +-
src/include/commands/trigger.h | 2 +-
src/include/rewrite/rewriteRemove.h | 2 +-
src/include/storage/sinval.h | 4 +
src/pl/plpgsql/src/pl_comp.c | 12 +--
26 files changed, 337 insertions(+), 195 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Simon Riggs 2011-07-10 10:30:05 Re: pgsql: Reset ALTER TABLE lock levels to AccessExclusiveLock in all case
Previous Message Tom Lane 2011-07-08 21:03:32 pgsql: Fix another oversight in logging of changes in postgresql.conf s