Add cassert-only checks against unlocked use of relations - Mailing list pgsql-hackers

From Andres Freund
Subject Add cassert-only checks against unlocked use of relations
Date
Msg-id 20131105211052.GH14819@awork2.anarazel.de
Whole thread Raw
Responses Re: Add cassert-only checks against unlocked use of relations  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

There frequently have been bugs where (heap|relation|index)_open(NoLock)
was used without a previous locks which in some circumstances is an easy
mistake to make and which is hard to notice.

The attached patch adds --use-cassert only WARNINGs against doing so:

    Add cassert-only checks against unlocked use of relations.

    Specifically relation_open(), which also covers heap/index_open(), and
    RelationIdGetRelation() WARN if the relation is opened without being
    locked. index_open() now checks whether the heap relation the index is
    covering is locked.

    To make those checks possible add StrongestLocalRelationLock() which
    returns the strongest locally held lock over a relation. It relies on
    the also added StrongestLocalLock() which searches the local locktable
    sequentially for matching locks.

After
1) 2a781d57dcd027df32d15ee2378b84d0c4d005d1
2) http://archives.postgresql.org/message-id/1383681385.79520.YahooMailNeo%40web162902.mail.bf1.yahoo.com
3) http://archives.postgresql.org/message-id/CAEZATCVCgboHKu_%2BK0nakrXW-AFEz_18icE0oWEQHsM-OepWhw%40mail.gmail.com

HEAD doesn't generate warnings anymore. I think Kevin will commit
something akin to 2), but 3) is an actual open bug, so that patch will
need to get applied beforehand.

Greetings,

Andres Freund

--
 Andres Freund                       http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: missing locking in at least INSERT INTO view WITH CHECK
Next
From: Tom Lane
Date:
Subject: Re: Window functions can be created with defaults, but they don't work