From 6d849cf3949f4893c1504d5f002c0f4880d9621e Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Thu, 2 Dec 2021 00:05:12 +0300 Subject: [PATCH] Allow delegating function from worker nodes We've both allowed delegating functions and procedures from worker nodes and also prevented delegation if a function/procedure has already been propagated from another node. --- src/backend/distributed/commands/call.c | 7 ++++++- .../distributed/planner/function_call_delegation.c | 13 +++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/backend/distributed/commands/call.c b/src/backend/distributed/commands/call.c index ac5ffc84b..dda4eb3de 100644 --- a/src/backend/distributed/commands/call.c +++ b/src/backend/distributed/commands/call.c @@ -62,7 +62,12 @@ CallDistributedProcedureRemotely(CallStmt *callStmt, DestReceiver *dest) DistObjectCacheEntry *procedure = LookupDistObjectCacheEntry(ProcedureRelationId, functionId, 0); - if (procedure == NULL || !procedure->isDistributed) + /* + * If procedure is not distributed or already delegated from another + * node, do not call the procedure remotely. + */ + if (procedure == NULL || !procedure->isDistributed || + IsCitusInitiatedRemoteBackend()) { return false; } diff --git a/src/backend/distributed/planner/function_call_delegation.c b/src/backend/distributed/planner/function_call_delegation.c index 83d7ad741..6618e49e1 100644 --- a/src/backend/distributed/planner/function_call_delegation.c +++ b/src/backend/distributed/planner/function_call_delegation.c @@ -112,9 +112,18 @@ TryToDelegateFunctionCall(DistributedPlanningContext *planContext) } int32 localGroupId = GetLocalGroupId(); - if (localGroupId != COORDINATOR_GROUP_ID || localGroupId == GROUP_ID_UPGRADING) + if (localGroupId != COORDINATOR_GROUP_ID && IsCitusInitiatedRemoteBackend()) { - /* do not delegate from workers, or while upgrading */ + /* + * Do not delegate from workers if it is initiated by Citus already. + * It means that this function has already been delegated to this node. + */ + return NULL; + } + + if (localGroupId == GROUP_ID_UPGRADING) + { + /* do not delegate while upgrading */ return NULL; }