Dynamically allocate connection metadata in WaitForAllConnections

pull/1965/head
Brian Cloutier 2018-01-30 14:47:20 -08:00 committed by Brian Cloutier
parent e6ebfc1f53
commit 15511f6ba1
2 changed files with 13 additions and 12 deletions

View File

@ -744,16 +744,12 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts)
int connectionIndex = 0; int connectionIndex = 0;
ListCell *connectionCell = NULL; ListCell *connectionCell = NULL;
MultiConnection *allConnections[REMOTE_MAX_CONNECTIONS]; MultiConnection **allConnections =
WaitEvent events[REMOTE_MAX_CONNECTIONS]; palloc(totalConnectionCount * sizeof(MultiConnection *));
bool connectionReady[REMOTE_MAX_CONNECTIONS]; WaitEvent *events = palloc(totalConnectionCount * sizeof(WaitEvent));
bool *connectionReady = palloc(totalConnectionCount * sizeof(bool));
WaitEventSet *waitEventSet = NULL; WaitEventSet *waitEventSet = NULL;
if (totalConnectionCount > REMOTE_MAX_CONNECTIONS)
{
ereport(ERROR, (errmsg("too many connections")));
}
/* convert connection list to an array such that we can move items around */ /* convert connection list to an array such that we can move items around */
foreach(connectionCell, connectionList) foreach(connectionCell, connectionList)
{ {
@ -765,8 +761,7 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts)
} }
/* make an initial pass to check for failed and idle connections */ /* make an initial pass to check for failed and idle connections */
for (connectionIndex = pendingConnectionsStartIndex; for (connectionIndex = 0; connectionIndex < totalConnectionCount; connectionIndex++)
connectionIndex < totalConnectionCount; connectionIndex++)
{ {
MultiConnection *connection = allConnections[connectionIndex]; MultiConnection *connection = allConnections[connectionIndex];
@ -953,6 +948,10 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts)
FreeWaitEventSet(waitEventSet); FreeWaitEventSet(waitEventSet);
waitEventSet = NULL; waitEventSet = NULL;
} }
pfree(allConnections);
pfree(events);
pfree(connectionReady);
} }
PG_CATCH(); PG_CATCH();
{ {
@ -963,6 +962,10 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts)
waitEventSet = NULL; waitEventSet = NULL;
} }
pfree(allConnections);
pfree(events);
pfree(connectionReady);
PG_RE_THROW(); PG_RE_THROW();
} }
PG_END_TRY(); PG_END_TRY();

View File

@ -17,8 +17,6 @@
#define QUERY_SEND_FAILED 1 #define QUERY_SEND_FAILED 1
#define RESPONSE_NOT_OKAY 2 #define RESPONSE_NOT_OKAY 2
#define REMOTE_MAX_CONNECTIONS 1024
struct pg_result; /* target of the PGresult typedef */ struct pg_result; /* target of the PGresult typedef */
/* GUC, determining whether statements sent to remote nodes are logged */ /* GUC, determining whether statements sent to remote nodes are logged */