make selection.hosts a shared_ptr

Differential Revision: D17412196

fbshipit-source-id: 872e7e6332284fa00b52e03ce237adeea32fd852
This commit is contained in:
Misha Shneerson 2019-09-25 13:55:09 -07:00 committed by Facebook Github Bot
parent ad930efa69
commit 9a0585ba15
2 changed files with 6 additions and 5 deletions

View File

@ -45,13 +45,13 @@ std::optional<SocketAddressWithHostname> ServiceAddress::addressFromSMCTier(
#ifdef EDEN_HAVE_SERVICEROUTER
auto selection = selector->getSelection(std::get<std::string>(name_));
if (selection.hosts.empty()) {
if (selection.hosts->empty()) {
return std::nullopt;
}
// TODO(zeyi, t42568801): better host selection algorithm
auto selected = folly::Random::rand32(selection.hosts.size());
const auto& host = selection.hosts[selected];
auto selected = folly::Random::rand32(selection.hosts->size());
const auto& host = selection.hosts->at(selected);
auto location = host->location();
return std::make_pair(

View File

@ -50,8 +50,9 @@ class MockServiceCacheIf : public ServiceCacheIf {
auto location = std::make_shared<HostInfoLocation>("::1", 1234);
location->setHostname("some-hostname");
selection.hosts.push_back(std::make_shared<HostInfo>(
std::make_unique<HostInfoProperties>(), std::move(location)));
const_cast<ServiceHosts*>(selection.hosts.get())
->push_back(std::make_shared<HostInfo>(
std::make_unique<HostInfoProperties>(), std::move(location)));
}
return selection;