aboutsummaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-06-11 11:50:24 +0000
committerArne Juul <arnej@verizonmedia.com>2021-06-11 11:53:03 +0000
commit7e8a78afef9702419bdc5ad38b3a33247276fb56 (patch)
tree1aaae66f8267ca9db39217dc9ae56d23d9359a58 /configd
parent6b0b774e1cccb73f036a00d3271c025a3be81192 (diff)
rename and refactor
* make a proper Accumulator class * rename some internal variables
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/connectivity.cpp27
-rw-r--r--configd/src/apps/sentinel/connectivity.h13
2 files changed, 22 insertions, 18 deletions
diff --git a/configd/src/apps/sentinel/connectivity.cpp b/configd/src/apps/sentinel/connectivity.cpp
index 2cdd6f8a914..0e91b583868 100644
--- a/configd/src/apps/sentinel/connectivity.cpp
+++ b/configd/src/apps/sentinel/connectivity.cpp
@@ -145,7 +145,7 @@ Connectivity::checkConnectivity(RpcServer &rpcServer) {
}
checkContext.latch.await();
classifyConnFails(connectivityMap, _checkSpecs, rpcServer);
- Accumulated accumulated;
+ Accumulator accumulated;
for (const auto & [hostname, check] : connectivityMap) {
std::string detail = toString(check.result());
std::string prev = _detailsPerHost[hostname];
@@ -154,42 +154,43 @@ Connectivity::checkConnectivity(RpcServer &rpcServer) {
}
_detailsPerHost[hostname] = detail;
LOG_ASSERT(check.result() != CcResult::UNKNOWN);
- accumulate(accumulated, check.result());
+ accumulated.handleResult(check.result());
}
- return enoughOk(accumulated, clusterSize);
+ return accumulated.enoughOk(_config);
}
-void Connectivity::accumulate(Accumulated &target, CcResult value) {
+void Connectivity::Accumulator::handleResult(CcResult value) {
+ ++_numHandled;
switch (value) {
case CcResult::UNKNOWN:
case CcResult::UNREACHABLE_UP:
case CcResult::INDIRECT_PING_FAIL:
- ++target.numSeriousIssues;
+ ++_numBad;
break;
case CcResult::CONN_FAIL:
// not OK, but not a serious issue either
break;
case CcResult::INDIRECT_PING_UNAVAIL:
case CcResult::ALL_OK:
- ++target.numUpAndOk;
+ ++_numOk;
break;
}
}
-bool Connectivity::enoughOk(const Accumulated &results, size_t clusterSize) {
+bool Connectivity::Accumulator::enoughOk(const SentinelConfig::Connectivity &config) const {
bool enough = true;
- if (results.numSeriousIssues > size_t(_config.maxBadCount)) {
+ if (_numBad > size_t(config.maxBadCount)) {
LOG(warning, "%zu of %zu nodes up but with network connectivity problems (max is %d)",
- results.numSeriousIssues, clusterSize, _config.maxBadCount);
+ _numBad, _numHandled, config.maxBadCount);
enough = false;
}
- if (results.numUpAndOk * 100.0 < _config.minOkPercent * clusterSize) {
- double pct = results.numUpAndOk * 100.0 / clusterSize;
+ if (_numOk * 100.0 < config.minOkPercent * _numHandled) {
+ double pct = _numOk * 100.0 / _numHandled;
LOG(warning, "Only %zu of %zu nodes are up and OK, %.1f%% (min is %d%%)",
- results.numUpAndOk, clusterSize, pct, _config.minOkPercent);
+ _numOk, _numHandled, pct, config.minOkPercent);
enough = false;
}
- if (results.numUpAndOk == clusterSize) {
+ if (_numOk == _numHandled) {
LOG(info, "All connectivity checks OK, proceeding with service startup");
} else if (enough) {
LOG(info, "Enough connectivity checks OK, proceeding with service startup");
diff --git a/configd/src/apps/sentinel/connectivity.h b/configd/src/apps/sentinel/connectivity.h
index 6b0e2d7523e..c1e41249dd5 100644
--- a/configd/src/apps/sentinel/connectivity.h
+++ b/configd/src/apps/sentinel/connectivity.h
@@ -27,12 +27,15 @@ public:
void configure(const SentinelConfig::Connectivity &config);
bool checkConnectivity(RpcServer &rpcServer);
private:
- struct Accumulated {
- size_t numUpAndOk = 0;
- size_t numSeriousIssues = 0;
+ class Accumulator {
+ private:
+ size_t _numOk = 0;
+ size_t _numBad = 0;
+ size_t _numHandled = 0;
+ public:
+ void handleResult(CcResult value);
+ bool enoughOk(const SentinelConfig::Connectivity &config) const;
};
- void accumulate(Accumulated &target, CcResult value);
- bool enoughOk(const Accumulated &results, size_t clusterSize);
SentinelConfig::Connectivity _config;
SpecMap _checkSpecs;
std::map<std::string, std::string> _detailsPerHost;