Add some asserts to pass static analysis (#3805)

pull/3811/head
Jelte Fennema 2020-04-29 11:19:11 +02:00 committed by GitHub
parent cbda951395
commit c6f5d5fe88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 1 deletions

View File

@ -193,7 +193,16 @@ GetNodeConnection(uint32 flags, const char *hostname, int32 port)
MultiConnection * MultiConnection *
StartNodeConnection(uint32 flags, const char *hostname, int32 port) StartNodeConnection(uint32 flags, const char *hostname, int32 port)
{ {
return StartNodeUserDatabaseConnection(flags, hostname, port, NULL, NULL); MultiConnection *connection = StartNodeUserDatabaseConnection(flags, hostname, port,
NULL, NULL);
/*
* connection can only be NULL for optional connections, which we don't
* support in this codepath.
*/
Assert((flags & OPTIONAL_CONNECTION) == 0);
Assert(connection != NULL);
return connection;
} }
@ -209,6 +218,13 @@ GetNodeUserDatabaseConnection(uint32 flags, const char *hostname, int32 port,
MultiConnection *connection = StartNodeUserDatabaseConnection(flags, hostname, port, MultiConnection *connection = StartNodeUserDatabaseConnection(flags, hostname, port,
user, database); user, database);
/*
* connection can only be NULL for optional connections, which we don't
* support in this codepath.
*/
Assert((flags & OPTIONAL_CONNECTION) == 0);
Assert(connection != NULL);
FinishConnectionEstablishment(connection); FinishConnectionEstablishment(connection);
return connection; return connection;
@ -236,6 +252,13 @@ StartWorkerListConnections(List *workerNodeList, uint32 flags, const char *user,
nodeName, nodePort, nodeName, nodePort,
user, database); user, database);
/*
* connection can only be NULL for optional connections, which we don't
* support in this codepath.
*/
Assert((flags & OPTIONAL_CONNECTION) == 0);
Assert(connection != NULL);
connectionList = lappend(connectionList, connection); connectionList = lappend(connectionList, connection);
} }

View File

@ -294,6 +294,13 @@ StartPlacementListConnection(uint32 flags, List *placementAccessList,
chosenConnection = StartNodeUserDatabaseConnection(flags, nodeName, nodePort, chosenConnection = StartNodeUserDatabaseConnection(flags, nodeName, nodePort,
userName, NULL); userName, NULL);
/*
* chosenConnection can only be NULL for optional connections, which we
* don't support in this codepath.
*/
Assert((flags & OPTIONAL_CONNECTION) == 0);
Assert(chosenConnection != NULL);
if ((flags & CONNECTION_PER_PLACEMENT) && if ((flags & CONNECTION_PER_PLACEMENT) &&
ConnectionAccessedDifferentPlacement(chosenConnection, placement)) ConnectionAccessedDifferentPlacement(chosenConnection, placement))
{ {
@ -314,6 +321,13 @@ StartPlacementListConnection(uint32 flags, List *placementAccessList,
nodeName, nodePort, nodeName, nodePort,
userName, NULL); userName, NULL);
/*
* chosenConnection can only be NULL for optional connections,
* which we don't support in this codepath.
*/
Assert((flags & OPTIONAL_CONNECTION) == 0);
Assert(chosenConnection != NULL);
Assert(!ConnectionAccessedDifferentPlacement(chosenConnection, placement)); Assert(!ConnectionAccessedDifferentPlacement(chosenConnection, placement));
} }
} }

View File

@ -150,6 +150,13 @@ MultiClientConnectStart(const char *nodeName, uint32 nodePort, const char *nodeD
MultiConnection *connection = StartNodeUserDatabaseConnection(connectionFlags, MultiConnection *connection = StartNodeUserDatabaseConnection(connectionFlags,
nodeName, nodePort, nodeName, nodePort,
userName, nodeDatabase); userName, nodeDatabase);
/*
* connection can only be NULL for optional connections, which we don't
* support in this codepath.
*/
Assert((connectionFlags & OPTIONAL_CONNECTION) == 0);
Assert(connection != NULL);
ConnStatusType connStatusType = PQstatus(connection->pgConn); ConnStatusType connStatusType = PQstatus(connection->pgConn);
/* /*

View File

@ -409,6 +409,13 @@ OpenConnectionsToWorkersInParallel(TargetWorkerSet targetWorkerSet, const char *
MultiConnection *connection = StartNodeUserDatabaseConnection(connectionFlags, MultiConnection *connection = StartNodeUserDatabaseConnection(connectionFlags,
nodeName, nodePort, nodeName, nodePort,
user, NULL); user, NULL);
/*
* connection can only be NULL for optional connections, which we don't
* support in this codepath.
*/
Assert((connectionFlags & OPTIONAL_CONNECTION) == 0);
Assert(connection != NULL);
connectionList = lappend(connectionList, connection); connectionList = lappend(connectionList, connection);
} }
return connectionList; return connectionList;
@ -476,6 +483,12 @@ SendCommandToWorkersParamsInternal(TargetWorkerSet targetWorkerSet, const char *
nodeName, nodePort, nodeName, nodePort,
user, NULL); user, NULL);
/*
* connection can only be NULL for optional connections, which we don't
* support in this codepath.
*/
Assert((connectionFlags & OPTIONAL_CONNECTION) == 0);
Assert(connection != NULL);
MarkRemoteTransactionCritical(connection); MarkRemoteTransactionCritical(connection);
connectionList = lappend(connectionList, connection); connectionList = lappend(connectionList, connection);