From fa297614fef1c12b1a50a0afe0d753cfbc041b88 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Wed, 2 Jun 2021 11:11:40 +0000 Subject: add timeout parameter --- configd/src/apps/sentinel/peer-check.cpp | 4 ++-- configd/src/apps/sentinel/peer-check.h | 3 +-- configd/src/apps/sentinel/rpchooks.cpp | 10 ++++++---- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'configd') diff --git a/configd/src/apps/sentinel/peer-check.cpp b/configd/src/apps/sentinel/peer-check.cpp index 841d32c9631..60c3d9c96c9 100644 --- a/configd/src/apps/sentinel/peer-check.cpp +++ b/configd/src/apps/sentinel/peer-check.cpp @@ -10,7 +10,7 @@ using vespalib::make_string_short::fmt; namespace config::sentinel { -PeerCheck::PeerCheck(StatusCallback &callback, const std::string &host, int port, FRT_Supervisor &orb) +PeerCheck::PeerCheck(StatusCallback &callback, const std::string &host, int port, FRT_Supervisor &orb, int timeout_ms) : _callback(callback), _hostname(host), _portnum(port), @@ -21,7 +21,7 @@ PeerCheck::PeerCheck(StatusCallback &callback, const std::string &host, int port _target = orb.GetTarget(spec.c_str()); _req = orb.AllocRPCRequest(); _req->SetMethodName("frt.rpc.ping"); - _target->InvokeAsync(_req, 0.500, this); + _target->InvokeAsync(_req, timeout_ms * 0.001, this); } PeerCheck::~PeerCheck() { diff --git a/configd/src/apps/sentinel/peer-check.h b/configd/src/apps/sentinel/peer-check.h index 145552a9ab1..096f304467b 100644 --- a/configd/src/apps/sentinel/peer-check.h +++ b/configd/src/apps/sentinel/peer-check.h @@ -4,7 +4,6 @@ #include "status-callback.h" #include -#include #include #include #include @@ -15,7 +14,7 @@ namespace config::sentinel { class PeerCheck : public FRT_IRequestWait { public: - PeerCheck(StatusCallback &callback, const std::string &host, int portnum, FRT_Supervisor &orb); + PeerCheck(StatusCallback &callback, const std::string &host, int portnum, FRT_Supervisor &orb, int timeout_ms); ~PeerCheck(); PeerCheck(const PeerCheck &) = delete; diff --git a/configd/src/apps/sentinel/rpchooks.cpp b/configd/src/apps/sentinel/rpchooks.cpp index d364e74154c..24e3cd53509 100644 --- a/configd/src/apps/sentinel/rpchooks.cpp +++ b/configd/src/apps/sentinel/rpchooks.cpp @@ -45,11 +45,12 @@ RPCHooks::initRPC(FRT_Supervisor *supervisor) FRT_METHOD(RPCHooks::rpc_startService), this); rb.MethodDesc("start a service"); //------------------------------------------------------------------------- - rb.DefineMethod("sentinel.check.connectivity", "si", "s", + rb.DefineMethod("sentinel.check.connectivity", "sii", "s", FRT_METHOD(RPCHooks::rpc_checkConnectivity), this); rb.MethodDesc("check connectivity for peer sentinel"); rb.ParamDesc("name", "Hostname of peer sentinel"); rb.ParamDesc("port", "Port number of peer sentinel"); + rb.ParamDesc("timeout", "Timeout for check in milliseconds"); rb.ReturnDesc("status", "Status (ok, bad, or unknown) for peer"); //------------------------------------------------------------------------- } @@ -97,11 +98,12 @@ RPCHooks::rpc_checkConnectivity(FRT_RPCRequest *req) { FRT_Values &args = *req->GetParams(); const char *hostname = args[0]._string._str; - uint32_t portnum = args[1]._intval32; - LOG(debug, "got checkConnectivity %s [port %d]", hostname, portnum); + int portnum = args[1]._intval32; + int timeout = args[2]._intval32; + LOG(debug, "got checkConnectivity %s [port %d] timeout %d", hostname, portnum, timeout); req->Detach(); auto & completionHandler = req->getStash().create(req); - req->getStash().create(completionHandler, hostname, portnum, _orb); + req->getStash().create(completionHandler, hostname, portnum, _orb, timeout); } } // namespace slobrok -- cgit v1.2.3