@@ -839,15 +839,38 @@ void RequestManager::requestFailure(std::shared_ptr<XrdAdaptor::ClientRequest> c
839
839
m_disabledSources.insert (source_ptr);
840
840
841
841
std::unique_lock<std::recursive_mutex> sentry (m_source_mutex);
842
+ // Remove the failed source from the container of active sources
842
843
if (auto found = std::ranges::find_if (
843
- m_activeSources, [&source_ptr](std::shared_ptr<Source> const &src) { return src.get () == source_ptr.get (); });
844
+ m_activeSources, [&source_ptr](const std::shared_ptr<Source> &src) { return src.get () == source_ptr.get (); });
844
845
found != m_activeSources.end ()) {
845
846
auto oldSources = m_activeSources;
846
847
m_activeSources.erase (found);
847
848
reportSiteChange (oldSources, m_activeSources);
848
849
}
850
+ // Find a new source to send the request to
851
+ // - First, if there is another active source, use it
852
+ // - Then, if there are no active sources, if there are inactive
853
+ // sources, use the best inactive source
854
+ // - Then, if there are no active or inactice sources, try to open a
855
+ // new connection for a new source
849
856
std::shared_ptr<Source> new_source;
850
- if (m_activeSources.empty ()) {
857
+ if (not m_activeSources.empty ()) {
858
+ new_source = m_activeSources[0 ];
859
+ } else if (not m_inactiveSources.empty ()) {
860
+ // similar logic as in checkSourcesImpl()
861
+ // assume the "sort open delay" doesn't matter in case of a request failure
862
+ auto bestInactiveSource =
863
+ std::min_element (m_inactiveSources.begin (),
864
+ m_inactiveSources.end (),
865
+ [](const std::shared_ptr<Source> &s1, const std::shared_ptr<Source> &s2) {
866
+ return s1->getQuality () < s2->getQuality ();
867
+ });
868
+
869
+ auto oldSources = m_activeSources;
870
+ m_activeSources.push_back (*bestInactiveSource);
871
+ m_inactiveSources.erase (bestInactiveSource);
872
+ reportSiteChange (oldSources, m_activeSources);
873
+ } else {
851
874
std::shared_future<std::shared_ptr<Source>> future = m_open_handler->open ();
852
875
timespec now;
853
876
GET_CLOCK_MONOTONIC (now);
@@ -891,8 +914,6 @@ void RequestManager::requestFailure(std::shared_ptr<XrdAdaptor::ClientRequest> c
891
914
auto oldSources = m_activeSources;
892
915
m_activeSources.push_back (new_source);
893
916
reportSiteChange (oldSources, m_activeSources);
894
- } else {
895
- new_source = m_activeSources[0 ];
896
917
}
897
918
new_source->handle (c_ptr);
898
919
}
0 commit comments