From 15511f6ba14e6d9287d19138cc3bdc8b016118bc Mon Sep 17 00:00:00 2001 From: Brian Cloutier Date: Tue, 30 Jan 2018 14:47:20 -0800 Subject: [PATCH] Dynamically allocate connection metadata in WaitForAllConnections --- .../distributed/connection/remote_commands.c | 23 +++++++++++-------- src/include/distributed/remote_commands.h | 2 -- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/backend/distributed/connection/remote_commands.c b/src/backend/distributed/connection/remote_commands.c index 35c78b419..f6d08d383 100644 --- a/src/backend/distributed/connection/remote_commands.c +++ b/src/backend/distributed/connection/remote_commands.c @@ -744,16 +744,12 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts) int connectionIndex = 0; ListCell *connectionCell = NULL; - MultiConnection *allConnections[REMOTE_MAX_CONNECTIONS]; - WaitEvent events[REMOTE_MAX_CONNECTIONS]; - bool connectionReady[REMOTE_MAX_CONNECTIONS]; + MultiConnection **allConnections = + palloc(totalConnectionCount * sizeof(MultiConnection *)); + WaitEvent *events = palloc(totalConnectionCount * sizeof(WaitEvent)); + bool *connectionReady = palloc(totalConnectionCount * sizeof(bool)); 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 */ foreach(connectionCell, connectionList) { @@ -765,8 +761,7 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts) } /* make an initial pass to check for failed and idle connections */ - for (connectionIndex = pendingConnectionsStartIndex; - connectionIndex < totalConnectionCount; connectionIndex++) + for (connectionIndex = 0; connectionIndex < totalConnectionCount; connectionIndex++) { MultiConnection *connection = allConnections[connectionIndex]; @@ -953,6 +948,10 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts) FreeWaitEventSet(waitEventSet); waitEventSet = NULL; } + + pfree(allConnections); + pfree(events); + pfree(connectionReady); } PG_CATCH(); { @@ -963,6 +962,10 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts) waitEventSet = NULL; } + pfree(allConnections); + pfree(events); + pfree(connectionReady); + PG_RE_THROW(); } PG_END_TRY(); diff --git a/src/include/distributed/remote_commands.h b/src/include/distributed/remote_commands.h index 658706c49..9cab423fd 100644 --- a/src/include/distributed/remote_commands.h +++ b/src/include/distributed/remote_commands.h @@ -17,8 +17,6 @@ #define QUERY_SEND_FAILED 1 #define RESPONSE_NOT_OKAY 2 -#define REMOTE_MAX_CONNECTIONS 1024 - struct pg_result; /* target of the PGresult typedef */ /* GUC, determining whether statements sent to remote nodes are logged */