Re: [HACKERS] Moving relation extension locks out of heavyweight lock manager
Dilip Kumar <dilipbalaut@gmail.com>
From: Dilip Kumar <dilipbalaut@gmail.com>
To: Amit Kapila <amit.kapila16@gmail.com>
Cc: Masahiko Sawada <masahiko.sawada@2ndquadrant.com>,
Andres Freund <andres@anarazel.de>, Tom Lane <tgl@sss.pgh.pa.us>, Robert Haas <robertmhaas@gmail.com>, Masahiko Sawada <sawada.mshk@gmail.com>,
Michael Paquier <michael@paquier.xyz>, Mithun Cy <mithun.cy@enterprisedb.com>,
Thomas Munro <thomas.munro@enterprisedb.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2020-03-12T05:45:36Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Allow page lock to conflict among parallel group members.
- 3ba59ccc896e 13.0 landed
-
Allow relation extension lock to conflict among parallel group members.
- 85f6b49c2c53 13.0 landed
-
Add assert to ensure that page locks don't participate in deadlock cycle.
- 72e78d831ab5 13.0 landed
-
Assert that we don't acquire a heavyweight lock on another object after
- 15ef6ff4b985 13.0 landed
-
Fix unsafe usage of strerror(errno) within ereport().
- 81256cd05f07 11.0 cited
Attachments
- v4-0001-Add-assert-to-check-that-we-should-not-acquire-an.patch (application/octet-stream) patch v4-0001
- v4-0003-Conflict-Extension-Page-lock-in-group-member.patch (application/octet-stream) patch v4-0003
- v4-0002-WIP-Extend-the-patch-for-handling-PageLock.patch (application/octet-stream) patch v4-0002
On Wed, Mar 11, 2020 at 2:23 PM Amit Kapila <amit.kapila16@gmail.com> wrote: > > On Tue, Mar 10, 2020 at 8:53 AM Dilip Kumar <dilipbalaut@gmail.com> wrote: > > > > Please find the updated patch (summary of the changes) > > - Instead of searching the lock hash table for assert, it maintains a counter. > > - Also, handled the case where we can acquire the relation extension > > lock while holding the relation extension lock on the same relation. > > - Handled the error case. > > > > In addition to that prepared a WIP patch for handling the PageLock. > > First, I thought that we can use the same counter for the PageLock and > > the RelationExtensionLock because in assert we just need to check > > whether we are trying to acquire any other heavyweight lock while > > holding any of these locks. But, the exceptional case where we > > allowed to acquire a relation extension lock while holding any of > > these locks is a bit different. Because, if we are holding a relation > > extension lock then we allowed to acquire the relation extension lock > > on the same relation but it can not be any other relation otherwise it > > can create a cycle. But, the same is not true with the PageLock, > > i.e. while holding the PageLock you can acquire the relation extension > > lock on any relation and that will be safe because the relation > > extension lock guarantee that, it will never create the cycle. > > However, I agree that we don't have any such cases where we want to > > acquire a relation extension lock on the different relations while > > holding the PageLock. > > > > Right, today, we don't have such cases where after acquiring relation > extension or page lock for a particular relation, we need to acquire > any of those for other relation and I am not able to offhand think of > many cases where we might have such a need in the future. The one > theoretical possibility is to include fork_num in the lock tag while > acquiring extension lock for fsm/vm, but that will also have the same > relation. Similarly one might say it is valid to acquire extension > lock in share mode after we have acquired it exclusive mode. I am not > sure how much futuristic we want to make these Asserts. > > I feel we should cover the current possible cases (which I think will > make the asserts more strict then required) and if there is a need to > relax them in the future for any particular use case, then we will > consider those. In general, if we consider the way Mahendra has > written a patch which is to find the entry via the local hash table to > check for an Assert condition, then it will be a bit easier to extend > the checks if required in future as that way we have more information > about the particular lock. However, it will make the check more > expensive which might be okay considering that it is only for Assert > enabled builds. > > One minor comment: > /* > + * We should not acquire any other lock if we are already holding the > + * relation extension lock. Only exception is that if we are trying to > + * acquire the relation extension lock then we can hold the relation > + * extension on the same relation. > + */ > + Assert(!IsRelExtLockHeld() || > + ((locktag->locktag_type == LOCKTAG_RELATION_EXTEND) && found)); I have fixed this in the attached patch set. -- Regards, Dilip Kumar EnterpriseDB: http://www.enterprisedb.com