Acquire shard resource locks on parent tables while operating on partitions

pull/1544/head
Burak Yucesoy 2017-08-11 15:14:23 +03:00
parent a321e750c0
commit dfdfb44ebf
3 changed files with 11 additions and 3 deletions

View File

@ -298,6 +298,11 @@ AcquireExecutorMultiShardLocks(List *taskList)
lockMode = ExclusiveLock;
}
/*
* If we are dealing with a partition we are also taking locks on parent table
* to prevent deadlocks on concurrent operations on a partition and its parent.
*/
LockParentShardResourceIfPartition(task->anchorShardId, lockMode);
LockShardResource(task->anchorShardId, lockMode);
/*

View File

@ -321,9 +321,9 @@ LockRelationShardResources(List *relationShardList, LOCKMODE lockMode)
/*
* LockParentShardResourceIfPartition checks whether given shard belongs to a
* partition. If it is, LockParentShardResourceIfPartition acquires a shard
* resource lock on the colocated shard of the parent table.
* LockParentShardResourceIfPartition checks whether the given shard belongs
* to a partition. If it does, LockParentShardResourceIfPartition acquires a
* shard resource lock on the colocated shard of the parent table.
*/
void
LockParentShardResourceIfPartition(uint64 shardId, LOCKMODE lockMode)

View File

@ -84,4 +84,7 @@ extern void LockRelationShardResources(List *relationShardList, LOCKMODE lockMod
extern void LockPartitionsInRelationList(List *relationIdList, LOCKMODE lockmode);
extern void LockPartitionRelations(Oid relationId, LOCKMODE lockMode);
/* Lock parent table's colocated shard resource */
extern void LockParentShardResourceIfPartition(uint64 shardId, LOCKMODE lockMode);
#endif /* RESOURCE_LOCK_H */