Avoid creating a redundant event set at the start

release-8.3
Marco Slot 2019-07-21 01:57:49 +02:00 committed by Hanefi Onaldi
parent 03f7e7479d
commit fc87b8da44
No known key found for this signature in database
GPG Key ID: 95177DABDC09D1F5
1 changed files with 32 additions and 12 deletions

View File

@ -1629,8 +1629,8 @@ RunDistributedExecution(DistributedExecution *execution)
/* additional 2 is for postmaster and latch */
int eventSetSize = list_length(execution->sessionList) + 2;
execution->waitEventSet = BuildWaitEventSet(execution->sessionList);
events = palloc0(eventSetSize * sizeof(WaitEvent));
/* always (re)build the wait event set the first time */
execution->connectionSetChanged = true;
while (execution->unfinishedTaskCount > 0 && !cancellationReceived)
{
@ -1646,16 +1646,24 @@ RunDistributedExecution(DistributedExecution *execution)
}
if (execution->connectionSetChanged)
{
if (execution->waitEventSet != NULL)
{
FreeWaitEventSet(execution->waitEventSet);
execution->waitEventSet = NULL;
}
execution->waitEventSet = BuildWaitEventSet(execution->sessionList);
if (events != NULL)
{
/*
* The execution might take a while, so explicitly free at this point
* because we don't need anymore.
*/
pfree(events);
events = NULL;
}
execution->waitEventSet = BuildWaitEventSet(execution->sessionList);
/* recalculate (and allocate) since the sessions have changed */
eventSetSize = list_length(execution->sessionList) + 2;
@ -1722,8 +1730,16 @@ RunDistributedExecution(DistributedExecution *execution)
}
}
if (events != NULL)
{
pfree(events);
}
if (execution->waitEventSet != NULL)
{
FreeWaitEventSet(execution->waitEventSet);
execution->waitEventSet = NULL;
}
CleanUpSessions(execution);
}
@ -1735,7 +1751,11 @@ RunDistributedExecution(DistributedExecution *execution)
*/
UnclaimAllSessionConnections(execution->sessionList);
if (execution->waitEventSet != NULL)
{
FreeWaitEventSet(execution->waitEventSet);
execution->waitEventSet = NULL;
}
PG_RE_THROW();
}