mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 07:20:55 +01:00
ircd::server: Add preliminary node error state; keep erroneous node in map as cache.
This commit is contained in:
parent
a99fff0988
commit
b840156b37
3 changed files with 53 additions and 7 deletions
|
@ -17,8 +17,10 @@ struct ircd::server::node
|
||||||
:std::enable_shared_from_this<ircd::server::node>
|
:std::enable_shared_from_this<ircd::server::node>
|
||||||
{
|
{
|
||||||
net::remote remote;
|
net::remote remote;
|
||||||
std::exception_ptr eptr;
|
|
||||||
std::list<link> links;
|
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;
|
std::string server_name;
|
||||||
|
|
||||||
template<class F> size_t accumulate_links(F&&) const;
|
template<class F> size_t accumulate_links(F&&) const;
|
||||||
|
@ -74,6 +76,11 @@ struct ircd::server::node
|
||||||
// request panel
|
// request panel
|
||||||
void submit(request &);
|
void submit(request &);
|
||||||
|
|
||||||
|
// Error related
|
||||||
|
bool err_has() const;
|
||||||
|
string_view err_msg() const;
|
||||||
|
void err_clear();
|
||||||
|
|
||||||
// control panel
|
// control panel
|
||||||
void interrupt();
|
void interrupt();
|
||||||
void close();
|
void close();
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace ircd::server
|
||||||
size_t link_count();
|
size_t link_count();
|
||||||
size_t node_count();
|
size_t node_count();
|
||||||
|
|
||||||
|
string_view errmsg(const net::hostport &);
|
||||||
bool exists(const net::hostport &);
|
bool exists(const net::hostport &);
|
||||||
node &find(const net::hostport &);
|
node &find(const net::hostport &);
|
||||||
node &get(const net::hostport &);
|
node &get(const net::hostport &);
|
||||||
|
|
|
@ -90,6 +90,20 @@ ircd::server::exists(const net::hostport &hostport)
|
||||||
return nodes.find(host(hostport)) != end(nodes);
|
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
|
size_t
|
||||||
ircd::server::node_count()
|
ircd::server::node_count()
|
||||||
{
|
{
|
||||||
|
@ -296,6 +310,28 @@ ircd::server::node::interrupt()
|
||||||
link.close(net::close_opts_default);
|
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
|
void
|
||||||
ircd::server::node::submit(request &request)
|
ircd::server::node::submit(request &request)
|
||||||
try
|
try
|
||||||
|
@ -700,7 +736,10 @@ try
|
||||||
const life_guard<node> lg(wp);
|
const life_guard<node> lg(wp);
|
||||||
|
|
||||||
if(eptr)
|
if(eptr)
|
||||||
std::rethrow_exception(std::move(eptr));
|
{
|
||||||
|
this->eptr = eptr;
|
||||||
|
std::rethrow_exception(this->eptr);
|
||||||
|
}
|
||||||
|
|
||||||
static_cast<net::ipport &>(this->remote) = ipport;
|
static_cast<net::ipport &>(this->remote) = ipport;
|
||||||
for(auto &link : links)
|
for(auto &link : links)
|
||||||
|
@ -715,14 +754,13 @@ catch(const std::exception &e)
|
||||||
if(wp.expired())
|
if(wp.expired())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
close();
|
this->emsg = e.what();
|
||||||
log.error("Removing node(%p): during name resolution: %s",
|
this->etime = now<steady_point>();
|
||||||
|
log.error("node(%p): during name resolution: %s",
|
||||||
this,
|
this,
|
||||||
e.what());
|
e.what());
|
||||||
|
|
||||||
const auto it(nodes.find(remote.hostname));
|
close();
|
||||||
assert(it != end(nodes));
|
|
||||||
nodes.erase(it);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
|
Loading…
Reference in a new issue