diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-16 15:53:42 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-09-16 15:53:42 +0000 |
commit | 8e90ea18a1b85011707739af5c2e64e4f894770c (patch) | |
tree | f6f7b457e07afaf73ab823b541ffb84887c96963 /filedistribution | |
parent | 4c95a1613a8777a0e72f258d0ebc8d3cc277bfcb (diff) |
catching connection loss exception.
Diffstat (limited to 'filedistribution')
3 files changed, 30 insertions, 15 deletions
diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.cpp b/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.cpp index 7eb0ab957ff..6420dfd6006 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.cpp +++ b/filedistribution/src/vespa/filedistribution/distributor/filedistributortrackerimpl.cpp @@ -5,17 +5,14 @@ #include <libtorrent/tracker_manager.hpp> #include <libtorrent/torrent.hpp> #include <vespa/filedistribution/model/filedistributionmodel.h> +#include <vespa/filedistribution/model/zkfacade.h> #include "filedownloader.h" #include "hostname.h" #include <vespa/log/log.h> LOG_SETUP(".filedistributiontrackerimpl"); -using filedistribution::FileDistributorTrackerImpl; -using filedistribution::FileDownloader; -using filedistribution::FileDistributionModel; -using filedistribution::Scheduler; -using filedistribution::TorrentSP; +using namespace filedistribution; typedef FileDistributionModel::PeerEntries PeerEntries; @@ -162,6 +159,17 @@ FileDistributorTrackerImpl::trackingRequest( } } +void asioWorker(asio::io_service& ioService) +{ + while (!ioService.stopped()) { + try { + ioService.run(); + } catch (const ZKConnectionLossException & e) { + LOG(info, "Connection loss in asioWorker thread, resuming. %s", e.what()); + } + } +} + void FileDistributorTrackerImpl::setDownloader(const std::shared_ptr<FileDownloader>& downloader) { @@ -171,6 +179,6 @@ FileDistributorTrackerImpl::setDownloader(const std::shared_ptr<FileDownloader>& _downloader = downloader; if (downloader) { - _scheduler.reset(new Scheduler([] (asio::io_service& ioService) { ioService.run(); })); + _scheduler.reset(new Scheduler([] (asio::io_service& ioService) { asioWorker(ioService); })); } } diff --git a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp index b6204067e10..72c4f2cbb4a 100644 --- a/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp +++ b/filedistribution/src/vespa/filedistribution/distributor/filedownloader.cpp @@ -1,5 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> +#include <vespa/filedistribution/model/zkfacade.h> #include "filedownloader.h" #include "hostname.h" @@ -19,7 +20,7 @@ #include <vespa/log/log.h> LOG_SETUP(".filedownloader"); -using filedistribution::FileDownloader; +using namespace filedistribution; namespace fs = boost::filesystem; using libtorrent::sha1_hash; @@ -137,7 +138,7 @@ struct FileDownloader::EventHandler } void operator()(const libtorrent::listen_failed_alert& alert) const { - BOOST_THROW_EXCEPTION(FailedListeningException(alert.endpoint.address().to_string(), alert.endpoint.port(), alert.message())); + throw FailedListeningException(alert.endpoint.address().to_string(), alert.endpoint.port(), alert.message()); } void operator()(const libtorrent::fastresume_rejected_alert& alert) const { LOG(debug, "alert %s: %s", alert.what(), alert.message().c_str()); @@ -250,7 +251,7 @@ FileDownloader::listen() { if (!ec && (_session.listen_port() == _port)) { return; } - BOOST_THROW_EXCEPTION(FailedListeningException(_hostName, _port)); + throw FailedListeningException(_hostName, _port); } boost::optional< fs::path > @@ -374,9 +375,13 @@ FileDownloader::removeAllTorrentsBut(const std::set<std::string> & filesToRetain void FileDownloader::runEventLoop() { EventHandler eventHandler(this); while ( ! closed() ) { - if (_session.wait_for_alert(libtorrent::milliseconds(100))) { - std::unique_ptr<libtorrent::alert> alert = _session.pop_alert(); - eventHandler.handle(std::move(alert)); + try { + if (_session.wait_for_alert(libtorrent::milliseconds(100))) { + std::unique_ptr<libtorrent::alert> alert = _session.pop_alert(); + eventHandler.handle(std::move(alert)); + } + } catch (const ZKConnectionLossException & e) { + LOG(info, "Connection loss in downloader event loop, resuming. %s", e.what()); } } } diff --git a/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp b/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp index adff69cfc6c..62cd4af940c 100644 --- a/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp +++ b/filedistribution/src/vespa/filedistribution/model/filedistributionmodelimpl.cpp @@ -219,12 +219,14 @@ FileDistributionModelImpl::addConfigServersAsPeers( } } - - void FileDistributionModelImpl::configure(std::unique_ptr<FilereferencesConfig> config) { const bool changed = updateActiveFileReferences(config->filereferences); if (changed) { - _filesToDownloadChanged(); + try { + _filesToDownloadChanged(); + } catch (const ZKConnectionLossException & e) { + LOG(info, "Connection loss in reconfigure of file references, resuming. %s", e.what()); + } } } |