First acquire locks on the modified tables, then the reference ones

rebalance_move_notice
eaydingol 2024-03-04 11:19:47 +00:00
parent 1b8ed32189
commit 2d92aac347
1 changed files with 15 additions and 5 deletions

View File

@ -709,6 +709,21 @@ SerializeNonCommutativeWrites(List *shardIntervalList, LOCKMODE lockMode)
List *replicatedShardList = NIL;
bool anyTableReplicated = AnyTableReplicated(shardIntervalList, &replicatedShardList);
/*
* Acquire locks on the modified table.
* If the table is replicated, the locks are first acquired on the first worker node then locally.
*/
if (anyTableReplicated && ClusterHasKnownMetadataWorkers() && !IsFirstWorkerNode())
{
LockShardListResourcesOnFirstWorker(lockMode, replicatedShardList);
}
LockShardListResources(shardIntervalList, lockMode);
/*
* Next, acquire locks on the reference tables if there is any.
* Note that LockReferencedReferenceShardResources() first acquires locks on the first worker,
* then locally.
*/
if (anyTableReplicated)
{
ShardInterval *firstShardInterval =
@ -725,11 +740,6 @@ SerializeNonCommutativeWrites(List *shardIntervalList, LOCKMODE lockMode)
LockReferencedReferenceShardResources(firstShardInterval->shardId, lockMode);
}
}
if (anyTableReplicated && ClusterHasKnownMetadataWorkers() && !IsFirstWorkerNode())
{
LockShardListResourcesOnFirstWorker(lockMode, replicatedShardList);
}
LockShardListResources(shardIntervalList, lockMode);
}