Re: Concurrent deadlock scenario with DROP INDEX on partitioned index

2022-03-21 Thread Jimmy Yih
Tom Lane wrote: > Hence, I propose the attached. 0001 is pure refactoring: it hopefully > clears up the confusion about which "relkind" is which, and it also > saves a couple of redundant syscache fetches in RemoveRelations. > Then 0002 adds the actual bug fix as well as a test case that does > d

Re: Concurrent deadlock scenario with DROP INDEX on partitioned index

2022-03-20 Thread Tom Lane
Jimmy Yih writes: > Tom Lane wrote: >> Actually though, maybe you *don't* want to do this in >> RangeVarCallbackForDropRelation. Because of point 2, it might be >> better to run find_all_inheritors after we've successfully >> identified and locked the direct target relation, ie do it back >> in

Re: Concurrent deadlock scenario with DROP INDEX on partitioned index

2022-03-16 Thread Jimmy Yih
Zhihong Yu wrote: > Hi, > For RangeVarCallbackForDropRelation(): > > + LockRelationOid(indexRelationOid, heap_lockmode); > > Since the above is called for both if and else blocks, it can be lifted > outside. Thanks for the feedback. Attached new v3 patch with feedback addressed.

Re: Concurrent deadlock scenario with DROP INDEX on partitioned index

2022-03-16 Thread Zhihong Yu
On Wed, Mar 16, 2022 at 11:20 AM Jimmy Yih wrote: > Tom Lane wrote: > > 1. RangeVarCallbackForDropRelation can get called more than once > > during a lookup (in case of concurrent rename and suchlike). > > If so it needs to be prepared to drop the lock(s) it got last time. > > You have not imple

Re: Concurrent deadlock scenario with DROP INDEX on partitioned index

2022-03-16 Thread Jimmy Yih
Tom Lane wrote: > 1. RangeVarCallbackForDropRelation can get called more than once > during a lookup (in case of concurrent rename and suchlike). > If so it needs to be prepared to drop the lock(s) it got last time. > You have not implemented any such logic. This doesn't seem hard > to fix, just

Re: Concurrent deadlock scenario with DROP INDEX on partitioned index

2022-03-10 Thread Tom Lane
Jimmy Yih writes: > When dropping a partitioned index, the locking order starts with the > partitioned table, then its partitioned index, then the partition > indexes dependent on that partitioned index, and finally the dependent > partition indexes' parent tables. This order allows a deadlock > s