aboutsummaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-06-08 13:48:56 +0000
committerArne Juul <arnej@verizonmedia.com>2021-06-09 07:39:53 +0000
commitbb0ab05d9bb4f0bafed9708f3ba11b7e358cf474 (patch)
treeb8563ea18825b2b2594f8624e2ac43b2a36f1b66 /configd
parent047b641beec9ea62b54789374bae41948bae5d54 (diff)
simpler SpecMap
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/connectivity.cpp22
-rw-r--r--configd/src/apps/sentinel/connectivity.h8
2 files changed, 13 insertions, 17 deletions
diff --git a/configd/src/apps/sentinel/connectivity.cpp b/configd/src/apps/sentinel/connectivity.cpp
index 84c03d5f3c1..6a9d8686d8d 100644
--- a/configd/src/apps/sentinel/connectivity.cpp
+++ b/configd/src/apps/sentinel/connectivity.cpp
@@ -40,6 +40,10 @@ using ConnectivityMap = std::map<std::string, OutwardCheck>;
using HostAndPort = Connectivity::HostAndPort;
using SpecMap = Connectivity::SpecMap;
+std::string spec(const SpecMap::value_type &host_and_port) {
+ return fmt("tcp/%s:%d", host_and_port.first.c_str(), host_and_port.second);
+}
+
SpecMap specsFrom(const ModelConfig &model) {
SpecMap checkSpecs;
for (const auto & h : model.hosts) {
@@ -48,7 +52,7 @@ SpecMap specsFrom(const ModelConfig &model) {
if (s.name == "config-sentinel") {
for (const auto & p : s.ports) {
if (p.tags.find("rpc") != p.tags.npos) {
- checkSpecs[h.name] = HostAndPort{h.name, p.number};
+ checkSpecs[h.name] = p.number;
foundSentinelPort = true;
}
}
@@ -73,18 +77,18 @@ size_t countUnreachable(const ConnectivityMap &connectivityMap,
auto iter = specMap.find(hostname);
LOG_ASSERT(iter != specMap.end());
if ((check.result() == CcResult::ALL_OK) && (hostname != myHostname)) {
- goodNeighborSpecs.push_back(iter->second);
+ goodNeighborSpecs.push_back(*iter);
}
if (check.result() == CcResult::CONN_FAIL) {
- failedConnSpecs.push_back(iter->second);
+ failedConnSpecs.push_back(*iter);
}
}
size_t counter = 0;
for (const auto & toCheck : failedConnSpecs) {
- OutwardCheckContext checkContext(goodNeighborSpecs.size(), toCheck.host, toCheck.port, rpcServer.orb());
+ OutwardCheckContext checkContext(goodNeighborSpecs.size(), toCheck.first, toCheck.second, rpcServer.orb());
ConnectivityMap cornerProbes;
for (const auto & hp : goodNeighborSpecs) {
- cornerProbes.try_emplace(hp.host, hp.spec(), checkContext);
+ cornerProbes.try_emplace(hp.first, spec(hp), checkContext);
}
checkContext.latch.await();
size_t numReportsUp = 0;
@@ -102,10 +106,6 @@ size_t countUnreachable(const ConnectivityMap &connectivityMap,
}
-std::string Connectivity::HostAndPort::spec() const {
- return fmt("tcp/%s:%d", host.c_str(), port);
-}
-
void Connectivity::configure(const SentinelConfig::Connectivity &config) {
_config = config;
LOG(config, "connectivity.maxBadReverseCount = %d", _config.maxBadReverseCount);
@@ -128,8 +128,8 @@ Connectivity::checkConnectivity(RpcServer &rpcServer) {
rpcServer.getPort(),
rpcServer.orb());
ConnectivityMap connectivityMap;
- for (const auto & [ hn, host_and_port ] : _checkSpecs) {
- connectivityMap.try_emplace(hn, host_and_port.spec(), checkContext);
+ for (const auto &host_and_port : _checkSpecs) {
+ connectivityMap.try_emplace(host_and_port.first, spec(host_and_port), checkContext);
}
checkContext.latch.await();
size_t numAllGood = 0;
diff --git a/configd/src/apps/sentinel/connectivity.h b/configd/src/apps/sentinel/connectivity.h
index 93bc2c865b5..03abd3dfc7a 100644
--- a/configd/src/apps/sentinel/connectivity.h
+++ b/configd/src/apps/sentinel/connectivity.h
@@ -18,12 +18,8 @@ namespace config::sentinel {
**/
class Connectivity {
public:
- struct HostAndPort {
- std::string host;
- int port;
- std::string spec() const;
- };
- using SpecMap = std::map<std::string, HostAndPort>;
+ using SpecMap = std::map<std::string, int>;
+ using HostAndPort = SpecMap::value_type;
Connectivity();
~Connectivity();