Use channel as telemetry data key (#4697)

* Use channel as telemetry data key

* Erase dead channels
This commit is contained in:
Piotr Wójcik 2024-10-15 13:03:38 +02:00 committed by GitHub
commit 885447fedb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 13 deletions

View file

@ -369,6 +369,7 @@ enum class detail
failed_send_telemetry_req,
empty_payload,
cleanup_outdated,
erase_stale,
// vote generator
generator_broadcasts,

View file

@ -96,14 +96,11 @@ void nano::telemetry::process (const nano::telemetry_ack & telemetry, const std:
nano::unique_lock<nano::mutex> lock{ mutex };
const auto endpoint = channel->get_endpoint ();
if (auto it = telemetries.get<tag_endpoint> ().find (endpoint); it != telemetries.get<tag_endpoint> ().end ())
if (auto it = telemetries.get<tag_channel> ().find (channel); it != telemetries.get<tag_channel> ().end ())
{
stats.inc (nano::stat::type::telemetry, nano::stat::detail::update);
telemetries.get<tag_endpoint> ().modify (it, [&telemetry, &endpoint] (auto & entry) {
debug_assert (entry.endpoint == endpoint);
telemetries.get<tag_channel> ().modify (it, [&telemetry, &channel] (auto & entry) {
entry.data = telemetry.data;
entry.last_updated = std::chrono::steady_clock::now ();
});
@ -111,7 +108,7 @@ void nano::telemetry::process (const nano::telemetry_ack & telemetry, const std:
else
{
stats.inc (nano::stat::type::telemetry, nano::stat::detail::insert);
telemetries.get<tag_endpoint> ().insert ({ endpoint, telemetry.data, std::chrono::steady_clock::now (), channel });
telemetries.get<tag_channel> ().insert ({ channel, telemetry.data, std::chrono::steady_clock::now () });
if (telemetries.size () > max_size)
{
@ -247,10 +244,14 @@ void nano::telemetry::cleanup ()
// Remove if telemetry data is stale
if (!check_timeout (entry))
{
stats.inc (nano::stat::type::telemetry, nano::stat::detail::cleanup_outdated);
stats.inc (nano::stat::type::telemetry, nano::stat::detail::erase_stale);
return true; // Erase
}
if (!entry.channel->alive ())
{
stats.inc (nano::stat::type::telemetry, nano::stat::detail::erase_dead);
return true; // Erase
}
return false; // Do not erase
});
}
@ -283,7 +284,7 @@ std::unordered_map<nano::endpoint, nano::telemetry_data> nano::telemetry::get_al
{
if (check_timeout (entry))
{
result[entry.endpoint] = entry.data;
result[entry.endpoint ()] = entry.data;
}
}
return result;

View file

@ -86,10 +86,14 @@ private: // Dependencies
private:
struct entry
{
nano::endpoint endpoint;
std::shared_ptr<nano::transport::channel> channel;
nano::telemetry_data data;
std::chrono::steady_clock::time_point last_updated;
std::shared_ptr<nano::transport::channel> channel;
nano::endpoint endpoint () const
{
return channel->get_endpoint ();
}
};
private:
@ -110,13 +114,16 @@ private:
private:
// clang-format off
class tag_sequenced {};
class tag_channel {};
class tag_endpoint {};
using ordered_telemetries = boost::multi_index_container<entry,
mi::indexed_by<
mi::sequenced<mi::tag<tag_sequenced>>,
mi::hashed_unique<mi::tag<tag_endpoint>,
mi::member<entry, nano::endpoint, &entry::endpoint>>
mi::ordered_unique<mi::tag<tag_channel>,
mi::member<entry, std::shared_ptr<nano::transport::channel>, &entry::channel>>,
mi::hashed_non_unique<mi::tag<tag_endpoint>,
mi::const_mem_fun<entry, nano::endpoint, &entry::endpoint>>
>>;
// clang-format on