Skip to content

Commit 9b92ad7

Browse files
committed
handle case of no networks and/or no members
1 parent 17c7ae2 commit 9b92ad7

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

controller/PostgreSQL.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,16 @@ void PostgreSQL::initializeNetworks(PGconn *conn)
437437

438438
PQclear(res);
439439

440-
if (_rc && _rc->clusterMode) {
441-
auto tx = _cluster->transaction(_myAddressStr, true);
442-
tx.sadd(setKey, networkSet.begin(), networkSet.end());
443-
tx.exec();
444-
} else if (_rc && !_rc->clusterMode) {
445-
auto tx = _redis->transaction(true);
446-
tx.sadd(setKey, networkSet.begin(), networkSet.end());
447-
tx.exec();
440+
if(!networkSet.empty()) {
441+
if (_rc && _rc->clusterMode) {
442+
auto tx = _cluster->transaction(_myAddressStr, true);
443+
tx.sadd(setKey, networkSet.begin(), networkSet.end());
444+
tx.exec();
445+
} else if (_rc && !_rc->clusterMode) {
446+
auto tx = _redis->transaction(true);
447+
tx.sadd(setKey, networkSet.begin(), networkSet.end());
448+
tx.exec();
449+
}
448450
}
449451

450452
if (++this->_ready == 2) {
@@ -643,19 +645,21 @@ void PostgreSQL::initializeMembers(PGconn *conn)
643645

644646
PQclear(res);
645647

646-
if (_rc != NULL) {
647-
if (_rc->clusterMode) {
648-
auto tx = _cluster->transaction(_myAddressStr, true);
649-
for (auto it : networkMembers) {
650-
tx.sadd(it.first, it.second);
651-
}
652-
tx.exec();
653-
} else {
654-
auto tx = _redis->transaction(true);
655-
for (auto it : networkMembers) {
656-
tx.sadd(it.first, it.second);
648+
if (!networkMembers.empty()) {
649+
if (_rc != NULL) {
650+
if (_rc->clusterMode) {
651+
auto tx = _cluster->transaction(_myAddressStr, true);
652+
for (auto it : networkMembers) {
653+
tx.sadd(it.first, it.second);
654+
}
655+
tx.exec();
656+
} else {
657+
auto tx = _redis->transaction(true);
658+
for (auto it : networkMembers) {
659+
tx.sadd(it.first, it.second);
660+
}
661+
tx.exec();
657662
}
658-
tx.exec();
659663
}
660664
}
661665
if (++this->_ready == 2) {

0 commit comments

Comments
 (0)