summaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-06-02 12:05:14 +0000
committerArne Juul <arnej@verizonmedia.com>2021-06-02 12:05:14 +0000
commit2b1964dd62942c7d75920357454937e374331320 (patch)
tree6fdbb2bd6d31675faca6b88ed15495ba52dd4fcf /configd
parent6a0ead14e709bf3ef93e75612b8f47ecab5cba66 (diff)
cleanup
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/env.cpp39
-rw-r--r--configd/src/apps/sentinel/outward-check.cpp26
-rw-r--r--configd/src/apps/sentinel/outward-check.h30
3 files changed, 65 insertions, 30 deletions
diff --git a/configd/src/apps/sentinel/env.cpp b/configd/src/apps/sentinel/env.cpp
index cec3157ac61..43ee263fb8f 100644
--- a/configd/src/apps/sentinel/env.cpp
+++ b/configd/src/apps/sentinel/env.cpp
@@ -93,7 +93,21 @@ void Env::respondAsEmpty() {
}
}
-void Env::waitForConnectivity(const ModelConfig &model) {
+namespace {
+
+const char *toString(CcResult value) {
+ switch (value) {
+ case CcResult::UNKNOWN: return "unknown";
+ case CcResult::CONN_FAIL: return "failed to connect";
+ case CcResult::REVERSE_FAIL: return "connect OK, but reverse check FAILED";
+ case CcResult::REVERSE_UNAVAIL: return "connect OK, but reverse check unavailable";
+ case CcResult::ALL_OK: return "both ways connectivity OK";
+ }
+ LOG(error, "Unknown CcResult enum value: %d", (int)value);
+ LOG_ABORT("Unknown CcResult enum value");
+}
+
+std::map<std::string, std::string> specsFrom(const ModelConfig &model) {
std::map<std::string, std::string> checkSpecs;
for (const auto & h : model.hosts) {
bool foundSentinelPort = false;
@@ -113,20 +127,25 @@ void Env::waitForConnectivity(const ModelConfig &model) {
h.name.c_str(), h.services.size());
}
}
- vespalib::CountDownLatch latch(checkSpecs.size());
- const char *myName = vespa::Defaults::vespaHostname();
- int myPort = _rpcServer->getPort();
+ return checkSpecs;
+}
+
+}
+
+void Env::waitForConnectivity(const ModelConfig &model) {
+ auto checkSpecs = specsFrom(model);
+ OutwardCheckContext checkContext(checkSpecs.size(),
+ vespa::Defaults::vespaHostname(),
+ _rpcServer->getPort(),
+ _rpcServer->orb());
std::map<std::string, OutwardCheck> connectivityMap;
for (const auto & [ hn, spec ] : checkSpecs) {
- connectivityMap.try_emplace(hn, spec, myName, myPort, _rpcServer->orb(), latch);
+ connectivityMap.try_emplace(hn, spec, checkContext);
}
- latch.await();
+ checkContext.latch.await();
for (const auto & [hostname, check] : connectivityMap) {
- const char *s = "unknown";
- if (check.ok()) { s = "ok"; }
- if (check.bad()) { s = "bad"; }
LOG(info, "outward check status for host %s is: %s",
- hostname.c_str(), s);
+ hostname.c_str(), toString(check.result()));
}
}
diff --git a/configd/src/apps/sentinel/outward-check.cpp b/configd/src/apps/sentinel/outward-check.cpp
index 07ff7dc90f9..ebdd723cb76 100644
--- a/configd/src/apps/sentinel/outward-check.cpp
+++ b/configd/src/apps/sentinel/outward-check.cpp
@@ -7,16 +7,15 @@ LOG_SETUP(".outward-check");
namespace config::sentinel {
-OutwardCheck::OutwardCheck(const std::string &spec, const char * myHostname, int myPortnum,
- FRT_Supervisor &orb, vespalib::CountDownLatch &latch)
+OutwardCheck::OutwardCheck(const std::string &spec, OutwardCheckContext &context)
: _spec(spec),
- _countDownLatch(latch)
+ _context(context)
{
- _target = orb.GetTarget(spec.c_str());
- _req = orb.AllocRPCRequest();
+ _target = context.orb.GetTarget(spec.c_str());
+ _req = context.orb.AllocRPCRequest();
_req->SetMethodName("sentinel.check.connectivity");
- _req->GetParams()->AddString(myHostname);
- _req->GetParams()->AddInt32(myPortnum);
+ _req->GetParams()->AddString(context.myHostname);
+ _req->GetParams()->AddInt32(context.myPortnum);
_req->GetParams()->AddInt32(500);
_target->InvokeAsync(_req, 1.500, this);
}
@@ -29,27 +28,28 @@ void OutwardCheck::RequestDone(FRT_RPCRequest *req) {
std::string answer = _req->GetReturn()->GetValue(0)._string._str;
if (answer == "ok") {
LOG(info, "ping to %s with reverse connectivity OK", _spec.c_str());
- _wasOk = true;
+ _result = CcResult::ALL_OK;
} else {
LOG(warning, "connected to %s, but reverse connectivity fails: %s",
_spec.c_str(), answer.c_str());
- _wasBad = true;
+ _result = CcResult::REVERSE_FAIL;
}
} else if (req->GetErrorCode() == FRTE_RPC_NO_SUCH_METHOD ||
req->GetErrorCode() == FRTE_RPC_WRONG_PARAMS)
{
- _wasOk = true;
LOG(info, "Connected OK to %s but no reverse connectivity check available", _spec.c_str());
+ _result = CcResult::REVERSE_UNAVAIL;
} else {
- _wasBad = true;
- LOG(warning, "error on ping to %s : %s (%d)", _spec.c_str(),
+ LOG(warning, "error on request to %s : %s (%d)", _spec.c_str(),
req->GetErrorMessage(), req->GetErrorCode());
+ _result = CcResult::CONN_FAIL;
+
}
_req->SubRef();
_req = nullptr;
_target->SubRef();
_target = nullptr;
- _countDownLatch.countDown();
+ _context.latch.countDown();
}
}
diff --git a/configd/src/apps/sentinel/outward-check.h b/configd/src/apps/sentinel/outward-check.h
index 8a0b036ac49..01a298aee18 100644
--- a/configd/src/apps/sentinel/outward-check.h
+++ b/configd/src/apps/sentinel/outward-check.h
@@ -10,21 +10,37 @@
namespace config::sentinel {
+struct OutwardCheckContext {
+ vespalib::CountDownLatch latch;
+ const char * myHostname;
+ int myPortnum;
+ FRT_Supervisor &orb;
+ OutwardCheckContext(size_t count,
+ const char * hostname,
+ int portnumber,
+ FRT_Supervisor &supervisor)
+ : latch(count),
+ myHostname(hostname),
+ myPortnum(portnumber),
+ orb(supervisor)
+ {}
+};
+
+enum class CcResult { UNKNOWN, CONN_FAIL, REVERSE_FAIL, REVERSE_UNAVAIL, ALL_OK };
+
class OutwardCheck : public FRT_IRequestWait {
private:
- bool _wasOk = false;
- bool _wasBad = false;
+ CcResult _result = CcResult::UNKNOWN;
FRT_Target *_target = nullptr;
FRT_RPCRequest *_req = nullptr;
std::string _spec;
- vespalib::CountDownLatch &_countDownLatch;
+ OutwardCheckContext &_context;
public:
- OutwardCheck(const std::string &spec, const char * myHostname, int myPortnum,
- FRT_Supervisor &orb, vespalib::CountDownLatch &latch);
+ OutwardCheck(const std::string &spec, OutwardCheckContext &context);
virtual ~OutwardCheck();
void RequestDone(FRT_RPCRequest *req) override;
- bool ok() const { return _wasOk; }
- bool bad() const { return _wasBad; }
+ bool ok() const { return _result == CcResult::ALL_OK; }
+ CcResult result() const { return _result; }
};
}