0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-11 06:28:55 +02:00

ircd::server: Add preliminary node error state; keep erroneous node in map as cache.

This commit is contained in:
Jason Volk 2018-03-02 22:37:52 -08:00
parent a99fff0988
commit b840156b37
3 changed files with 53 additions and 7 deletions

View file

@ -17,8 +17,10 @@ struct ircd::server::node
:std::enable_shared_from_this<ircd::server::node>
{
net::remote remote;
std::exception_ptr eptr;
std::list<link> links;
std::exception_ptr eptr;
string_view emsg; // points to eptr->what()
steady_point etime; // time of error
std::string server_name;
template<class F> size_t accumulate_links(F&&) const;
@ -74,6 +76,11 @@ struct ircd::server::node
// request panel
void submit(request &);
// Error related
bool err_has() const;
string_view err_msg() const;
void err_clear();
// control panel
void interrupt();
void close();

View file

@ -33,6 +33,7 @@ namespace ircd::server
size_t link_count();
size_t node_count();
string_view errmsg(const net::hostport &);
bool exists(const net::hostport &);
node &find(const net::hostport &);
node &get(const net::hostport &);

View file

@ -90,6 +90,20 @@ ircd::server::exists(const net::hostport &hostport)
return nodes.find(host(hostport)) != end(nodes);
}
ircd::string_view
ircd::server::errmsg(const net::hostport &hostport)
{
const auto it
{
nodes.find(host(hostport))
};
if(it == end(nodes))
return {};
return it->second->err_msg();
}
size_t
ircd::server::node_count()
{
@ -296,6 +310,28 @@ ircd::server::node::interrupt()
link.close(net::close_opts_default);
}
void
ircd::server::node::err_clear()
{
eptr = std::exception_ptr{};
emsg = string_view{};
etime = steady_point{};
}
ircd::string_view
ircd::server::node::err_msg()
const
{
return err_has()? emsg : string_view{};
}
bool
ircd::server::node::err_has()
const
{
return bool(eptr);
}
void
ircd::server::node::submit(request &request)
try
@ -700,7 +736,10 @@ try
const life_guard<node> lg(wp);
if(eptr)
std::rethrow_exception(std::move(eptr));
{
this->eptr = eptr;
std::rethrow_exception(this->eptr);
}
static_cast<net::ipport &>(this->remote) = ipport;
for(auto &link : links)
@ -715,14 +754,13 @@ catch(const std::exception &e)
if(wp.expired())
return;
close();
log.error("Removing node(%p): during name resolution: %s",
this->emsg = e.what();
this->etime = now<steady_point>();
log.error("node(%p): during name resolution: %s",
this,
e.what());
const auto it(nodes.find(remote.hostname));
assert(it != end(nodes));
nodes.erase(it);
close();
}
size_t