From a7e735a64852f8661bbfec5e8186366be740fd75 Mon Sep 17 00:00:00 2001 From: SaitTalhaNisanci Date: Wed, 12 Feb 2020 11:46:38 +0300 Subject: [PATCH] use a utility method to get event size --- .../distributed/executor/adaptive_executor.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/backend/distributed/executor/adaptive_executor.c b/src/backend/distributed/executor/adaptive_executor.c index 415c26d2a..e53d80ea3 100644 --- a/src/backend/distributed/executor/adaptive_executor.c +++ b/src/backend/distributed/executor/adaptive_executor.c @@ -618,6 +618,7 @@ static bool HasDependentJobs(Job *mainJob); static void ExtractParametersForRemoteExecution(ParamListInfo paramListInfo, Oid **parameterTypes, const char ***parameterValues); +static int GetEventSetSize(List *sessionList); /* * AdaptiveExecutor is called via CitusExecScan on the @@ -2007,8 +2008,7 @@ RunDistributedExecution(DistributedExecution *execution) { bool cancellationReceived = false; - /* additional 2 is for postmaster and latch */ - int eventSetSize = list_length(execution->sessionList) + 2; + int eventSetSize = GetEventSetSize(execution->sessionList); /* always (re)build the wait event set the first time */ execution->connectionSetChanged = true; @@ -2045,7 +2045,7 @@ RunDistributedExecution(DistributedExecution *execution) execution->waitEventSet = BuildWaitEventSet(execution->sessionList); /* recalculate (and allocate) since the sessions have changed */ - eventSetSize = list_length(execution->sessionList) + 2; + eventSetSize = GetEventSetSize(execution->sessionList); events = palloc0(eventSetSize * sizeof(WaitEvent)); @@ -3766,7 +3766,7 @@ static WaitEventSet * BuildWaitEventSet(List *sessionList) { /* additional 2 is for postmaster and latch */ - int eventSetSize = list_length(sessionList) + 2; + int eventSetSize = GetEventSetSize(sessionList); WaitEventSet *waitEventSet = CreateWaitEventSet(CurrentMemoryContext, eventSetSize); @@ -3807,6 +3807,17 @@ BuildWaitEventSet(List *sessionList) } +/* + * GetEventSetSize returns the event set size. + */ +static int +GetEventSetSize(List *sessionList) +{ + /* additional 2 is for postmaster and latch */ + return list_length(sessionList) + 2; +} + + /* * UpdateWaitEventSetFlags modifies the given waitEventSet with the wait flags * for connections in the sessionList.