Release lock on CoordinatorAddedAsWorkerNode()

Because master_add_node(or others) might acquire ExclusiveLock
and their initiated sessions may call CoordinatorAddedAsWorkerNode().

With this we prevent potential deadlocks.
pull/4480/head
Onder Kalaci 2021-01-14 19:10:44 +03:00
parent e718d24868
commit ed58a404d5
2 changed files with 3 additions and 7 deletions

View File

@ -413,8 +413,8 @@ PreprocessAlterTableStmt(Node *node, const char *alterTableCommand,
}
if (processUtilityContext != PROCESS_UTILITY_SUBCOMMAND &&
AlterTableDefinesFKeyBetweenPostgresAndNonDistTable(alterTableStatement) &&
CoordinatorAddedAsWorkerNode())
CoordinatorAddedAsWorkerNode() &&
AlterTableDefinesFKeyBetweenPostgresAndNonDistTable(alterTableStatement))
{
/*
* We don't process subcommands generated by postgres.

View File

@ -418,17 +418,13 @@ NodeIsPrimaryWorker(WorkerNode *node)
/*
* CoordinatorAddedAsWorkerNode returns true if coordinator is added to the
* pg_dist_node. This function also acquires ShareLock on pg_dist_node
* and does not release it to ensure that existency of the coordinator in
* metadata won't be changed until the end of transaction.
* pg_dist_node.
*/
bool
CoordinatorAddedAsWorkerNode()
{
bool groupContainsNodes = false;
LockRelationOid(DistNodeRelationId(), ShareLock);
PrimaryNodeForGroup(COORDINATOR_GROUP_ID, &groupContainsNodes);
return groupContainsNodes;