From 9b92ad7772d9ae0d5e5333743a5443406fca540c Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 4 Jun 2020 14:06:30 -0700 Subject: [PATCH] handle case of no networks and/or no members --- controller/PostgreSQL.cpp | 44 +++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/controller/PostgreSQL.cpp b/controller/PostgreSQL.cpp index a9f9500bb..87d3db7e4 100644 --- a/controller/PostgreSQL.cpp +++ b/controller/PostgreSQL.cpp @@ -437,14 +437,16 @@ void PostgreSQL::initializeNetworks(PGconn *conn) PQclear(res); - if (_rc && _rc->clusterMode) { - auto tx = _cluster->transaction(_myAddressStr, true); - tx.sadd(setKey, networkSet.begin(), networkSet.end()); - tx.exec(); - } else if (_rc && !_rc->clusterMode) { - auto tx = _redis->transaction(true); - tx.sadd(setKey, networkSet.begin(), networkSet.end()); - tx.exec(); + if(!networkSet.empty()) { + if (_rc && _rc->clusterMode) { + auto tx = _cluster->transaction(_myAddressStr, true); + tx.sadd(setKey, networkSet.begin(), networkSet.end()); + tx.exec(); + } else if (_rc && !_rc->clusterMode) { + auto tx = _redis->transaction(true); + tx.sadd(setKey, networkSet.begin(), networkSet.end()); + tx.exec(); + } } if (++this->_ready == 2) { @@ -643,19 +645,21 @@ void PostgreSQL::initializeMembers(PGconn *conn) PQclear(res); - if (_rc != NULL) { - if (_rc->clusterMode) { - auto tx = _cluster->transaction(_myAddressStr, true); - for (auto it : networkMembers) { - tx.sadd(it.first, it.second); + if (!networkMembers.empty()) { + if (_rc != NULL) { + if (_rc->clusterMode) { + auto tx = _cluster->transaction(_myAddressStr, true); + for (auto it : networkMembers) { + tx.sadd(it.first, it.second); + } + tx.exec(); + } else { + auto tx = _redis->transaction(true); + for (auto it : networkMembers) { + tx.sadd(it.first, it.second); + } + tx.exec(); } - tx.exec(); - } else { - auto tx = _redis->transaction(true); - for (auto it : networkMembers) { - tx.sadd(it.first, it.second); - } - tx.exec(); } } if (++this->_ready == 2) {