fix/distributed_deadlock1
Sait Talha Nisanci 2021-08-13 17:15:18 +03:00
parent d3faf974ad
commit 11d5301d35
2 changed files with 5 additions and 20 deletions

View File

@ -1560,20 +1560,6 @@ LockPartitionsForDistributedPlan(DistributedPlan *distributedPlan)
Oid targetRelationId = distributedPlan->targetRelationId;
LockPartitionsInRelationList(list_make1_oid(targetRelationId), RowExclusiveLock);
if (PartitionTable(targetRelationId))
{
Oid parentRelationId = PartitionParentOid(targetRelationId);
/*
* Postgres only takes the lock on parent when the session accesses the
* partition for the first time. So it should be okay to get this lock from
* PG perspective. Even though we diverge from PG behavior for concurrent
* modifications on partitions vs CREATE/DROP partitions, we consider this as
* a reasonable trade-off to avoid distributed deadlocks.
*/
LockRelationOid(parentRelationId, AccessShareLock);
}
}
/*
@ -1663,13 +1649,8 @@ LockParentShardResouceIfPartitionTaskList(List *taskList)
return;
}
ShardInterval *shardInterval = LoadShardInterval(shardId);
Oid relationId = shardInterval->relationId;
if (PartitionTable(relationId))
{
LockParentShardResourceIfPartition(shardId, AccessExclusiveLock);
}
}
/*

View File

@ -45,6 +45,7 @@
#include "distributed/placement_connection.h"
#include "distributed/relay_utility.h"
#include "distributed/remote_commands.h"
#include "distributed/resource_lock.h"
#include "distributed/worker_protocol.h"
#include "distributed/worker_transaction.h"
#include "lib/stringinfo.h"
@ -332,11 +333,14 @@ DropShards(Oid relationId, char *schemaName, char *relationName,
deletableShardIntervalList);
bool shouldExecuteTasksLocally = ShouldExecuteTasksLocally(dropTaskList);
Task *task = NULL;
foreach_ptr(task, dropTaskList)
{
uint64 shardId = task->anchorShardId;
LockParentShardResourceIfPartition(shardId, AccessExclusiveLock);
ShardPlacement *shardPlacement = NULL;
foreach_ptr(shardPlacement, task->taskPlacementList)
{