@@ -692,19 +692,41 @@ void AgencyCommManager::addEndpoint(std::string const& endpoint) {
692
692
if (iter == _endpoints.end ()) {
693
693
LOG_TOPIC (DEBUG, Logger::AGENCYCOMM) << " using agency endpoint '"
694
694
<< normalized << " '" ;
695
-
696
695
_endpoints.emplace_back (normalized);
697
696
}
698
697
}
699
698
700
- void AgencyCommManager::removeEndpoint (std::string const & endpoint) {
699
+ void AgencyCommManager::updateEndpoints (std::vector<std::string> const & newEndpoints) {
700
+ std::set<std::string> updatedSet;
701
+ for (std::string const & endp : newEndpoints) {
702
+ updatedSet.emplace (Endpoint::unifiedForm (endp));
703
+ }
704
+
701
705
MUTEX_LOCKER (locker, _lock);
702
-
703
- std::string normalized = Endpoint::unifiedForm (endpoint);
704
-
705
- _endpoints.erase (
706
- std::remove (_endpoints.begin (), _endpoints.end (), normalized),
707
- _endpoints.end ());
706
+
707
+ std::set<std::string> currentSet;
708
+ currentSet.insert (_endpoints.begin (), _endpoints.end ());
709
+
710
+ std::set<std::string> toRemove;
711
+ std::set_difference (currentSet.begin (), currentSet.end (),
712
+ updatedSet.begin (), updatedSet.end (),
713
+ std::inserter (toRemove, toRemove.begin ()));
714
+
715
+ std::set<std::string> toAdd;
716
+ std::set_difference (updatedSet.begin (), updatedSet.end (),
717
+ currentSet.begin (), currentSet.end (),
718
+ std::inserter (toAdd, toAdd.begin ()));
719
+
720
+ for (std::string const & rem : toRemove) {
721
+ LOG_TOPIC (INFO, Logger::AGENCYCOMM) << " Removing endpoint " << rem << " from agent pool" ;
722
+ _endpoints.erase (std::remove (_endpoints.begin (), _endpoints.end (), rem),
723
+ _endpoints.end ());
724
+ }
725
+
726
+ for (std::string const & add : toAdd) {
727
+ LOG_TOPIC (INFO, Logger::AGENCYCOMM) << " Adding endpoint " << add << " to agent pool" ;
728
+ _endpoints.emplace_back (add);
729
+ }
708
730
}
709
731
710
732
std::string AgencyCommManager::endpointsString () const {
@@ -745,6 +767,7 @@ AgencyCommManager::createNewConnection() {
745
767
}
746
768
747
769
void AgencyCommManager::switchCurrentEndpoint () {
770
+ _lock.assertLockedByCurrentThread ();
748
771
if (_endpoints.empty ()) {
749
772
return ;
750
773
}
@@ -130
10000
1,29 +1324,6 @@ bool AgencyComm::unlock(std::string const& key, VPackSlice const& slice,
1301
1324
}
1302
1325
1303
1326
1304
- void AgencyComm::updateEndpoints (arangodb::velocypack::Slice const & current) {
1305
-
1306
- auto stored = AgencyCommManager::MANAGER->endpoints ();
1307
-
1308
- for (const auto & i : VPackObjectIterator (current)) {
1309
- auto const endpoint = Endpoint::unifiedForm (i.value .copyString ());
1310
- if (std::find (stored.begin (), stored.end (), endpoint) == stored.end ()) {
1311
- LOG_TOPIC (INFO, Logger::AGENCYCOMM)
1312
- << " Adding endpoint " << endpoint << " to agent pool" ;
1313
- AgencyCommManager::MANAGER->addEndpoint (endpoint);
1314
- }
1315
- stored.erase (
1316
- std::remove (stored.begin (), stored.end (), endpoint), stored.end ());
1317
- }
1318
-
1319
- for (const auto & i : stored) {
1320
- LOG_TOPIC (INFO, Logger::AGENCYCOMM)
1321
- << " Removing endpoint " << i << " from agent pool" ;
1322
- AgencyCommManager::MANAGER->removeEndpoint (i);
1323
- }
1324
- }
1325
-
1326
-
1327
1327
AgencyCommResult AgencyComm::sendWithFailover (
1328
1328
arangodb::rest::RequestType method, double const timeout,
1329
1329
std::string const & initialUrl, VPackSlice inBody) {
0 commit comments