Skip to content

Commit

Permalink
[core] Change entity_id type from std::string to uint64_t (#1872)
Browse files Browse the repository at this point in the history
* [core] monitoring map indices based solely on entity ids (as they are unique within the system)
  • Loading branch information
KerstinKeller authored Jan 7, 2025
1 parent 379e75a commit 6e7ffce
Show file tree
Hide file tree
Showing 43 changed files with 219 additions and 196 deletions.
16 changes: 8 additions & 8 deletions ecal/core/include/ecal/ecal_callback.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,13 +74,13 @@ namespace eCAL
**/
struct SServiceAttr
{
std::string key; //!< unique service key (internal)
std::string hname; //!< host name
std::string pname; //!< process name
std::string uname; //!< process unit name
std::string sname; //!< service name
std::string sid; //!< service id
int pid = 0; //!< process id
std::string key; //!< unique service key (internal)
std::string hname; //!< host name
std::string pname; //!< process name
std::string uname; //!< process unit name
std::string sname; //!< service name
Registration::EntityIdT sid = 0; //!< service id
int pid = 0; //!< process id

// internal protocol specifics
unsigned int version = 0; //!< service protocol version
Expand Down
9 changes: 6 additions & 3 deletions ecal/core/include/ecal/ecal_types.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,9 +23,10 @@
**/

#pragma once
#include <cstdint>
#include <iostream>
#include <string>
#include <tuple>
#include <iostream>

namespace eCAL
{
Expand Down Expand Up @@ -103,9 +104,11 @@ namespace eCAL

namespace Registration
{
using EntityIdT = uint64_t;

struct SEntityId
{
std::string entity_id; // unique id within that process (it should already be unique within the whole system)
EntityIdT entity_id = 0; // unique id within that process (it should already be unique within the whole system)
int32_t process_id = 0; // process id which produced the sample
std::string host_name; // host which produced the sample

Expand Down
22 changes: 11 additions & 11 deletions ecal/core/include/ecal/types/monitoring.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,7 +77,7 @@ namespace eCAL
int32_t pid{0}; //!< process id
std::string pname; //!< process name
std::string uname; //!< unit name
std::string tid; //!< topic id
Registration::EntityIdT tid{0}; //!< topic id
std::string tname; //!< topic name
std::string direction; //!< direction (publisher, subscriber)
SDataTypeInformation tdatatype; //!< topic datatype information (name, encoding, descriptor)
Expand Down Expand Up @@ -155,7 +155,7 @@ namespace eCAL
int32_t pid{0}; //<! process id

std::string sname; //<! service name
std::string sid; //<! service id
Registration::EntityIdT sid{0}; //<! service id

uint32_t version{0}; //<! service protocol version
uint32_t tcp_port_v0{0}; //<! the tcp port protocol version 0 used for that service
Expand All @@ -166,18 +166,18 @@ namespace eCAL

struct SClientMon //<! eCAL Client struct
{
int32_t rclock{0}; //<! registration clock
std::string hname; //<! host name
std::string pname; //<! process name
std::string uname; //<! unit name
int32_t pid{0}; //<! process id
int32_t rclock{0}; //<! registration clock
std::string hname; //<! host name
std::string pname; //<! process name
std::string uname; //<! unit name
int32_t pid{0}; //<! process id

std::string sname; //<! service name
std::string sid; //<! service id
std::string sname; //<! service name
Registration::EntityIdT sid{0}; //<! service id

std::vector<SMethodMon> methods; //<! list of methods

uint32_t version{0}; //<! client protocol version
uint32_t version{0}; //<! client protocol version
};

struct SMonitoring //<! eCAL Monitoring struct
Expand Down
62 changes: 20 additions & 42 deletions ecal/core/src/monitoring/ecal_monitoring_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -213,7 +213,7 @@ namespace eCAL
const std::string& host_group_name = sample_topic.hgname;
const std::string& process_name = sample_topic.pname;
const std::string& unit_name = sample_topic.uname;
const std::string& topic_id = sample_.identifier.entity_id;
const auto& topic_id = sample_.identifier.entity_id;
std::string direction;
switch (pubsub_type_)
{
Expand All @@ -232,8 +232,8 @@ namespace eCAL
auto attr = sample_topic.attr;

// try to get topic info
const std::string topic_name_id = topic_name + topic_id;
Monitoring::STopicMon& TopicInfo = (*pTopicMap->map)[topic_name_id];
const auto& topic_map_key = topic_id;
Monitoring::STopicMon& TopicInfo = (*pTopicMap->map)[topic_map_key];

// set static content
TopicInfo.hname = host_name;
Expand Down Expand Up @@ -292,9 +292,7 @@ namespace eCAL

bool CMonitoringImpl::UnregisterTopic(const Registration::Sample& sample_, enum ePubSub pubsub_type_)
{
const auto& sample_topic = sample_.topic;
const std::string& topic_name = sample_topic.tname;
const std::string& topic_id = sample_.identifier.entity_id;
const auto& topic_map_key = sample_.identifier.entity_id;

// unregister from topic map
STopicMonMap* pTopicMap = GetMap(pubsub_type_);
Expand All @@ -304,8 +302,7 @@ namespace eCAL
const std::lock_guard<std::mutex> lock(pTopicMap->sync);

// remove topic info
const std::string topic_name_id = topic_name + topic_id;
pTopicMap->map->erase(topic_name_id);
pTopicMap->map->erase(topic_map_key);
}

return(true);
Expand All @@ -331,13 +328,13 @@ namespace eCAL
const std::string& ecal_runtime_version = sample_process.ecal_runtime_version;

// create map key
const std::string process_name_id = process_name + std::to_string(process_id);
const auto& process_map_key = sample_.identifier.entity_id;

// acquire access
const std::lock_guard<std::mutex> lock(m_process_map.sync);

// try to get process info
Monitoring::SProcessMon& ProcessInfo = (*m_process_map.map)[process_name_id];
Monitoring::SProcessMon& ProcessInfo = (*m_process_map.map)[process_map_key];

// set static content
ProcessInfo.hname = host_name;
Expand All @@ -363,26 +360,21 @@ namespace eCAL

bool CMonitoringImpl::UnregisterProcess(const Registration::Sample& sample_)
{
const auto& sample_process = sample_.process;
const std::string& process_name = sample_process.pname;
const int process_id = sample_.identifier.process_id;

// create map key
const std::string process_name_id = process_name + std::to_string(process_id);
const auto& process_map_key = sample_.identifier.entity_id;

// acquire access
const std::lock_guard<std::mutex> lock(m_process_map.sync);

// remove process info
m_process_map.map->erase(process_name_id);
m_process_map.map->erase(process_map_key);

return(true);
}

bool CMonitoringImpl::RegisterServer(const Registration::Sample& sample_)
{
const auto& sample_identifier = sample_.identifier;
const std::string& service_id = sample_identifier.entity_id;
const auto& service_id = sample_.identifier.entity_id;
const int32_t process_id = sample_identifier.process_id;
const std::string& host_name = sample_identifier.host_name;

Expand All @@ -395,13 +387,13 @@ namespace eCAL
const uint32_t tcp_port_v1 = sample_service.tcp_port_v1;

// create map key
const std::string service_name_id = service_name + service_id + std::to_string(process_id);
const auto& service_map_key = service_id;

// acquire access
const std::lock_guard<std::mutex> lock(m_server_map.sync);

// try to get service info
Monitoring::SServerMon& ServerInfo = (*m_server_map.map)[service_name_id];
Monitoring::SServerMon& ServerInfo = (*m_server_map.map)[service_map_key];

// set static content
ServerInfo.hname = host_name;
Expand Down Expand Up @@ -433,29 +425,22 @@ namespace eCAL

bool CMonitoringImpl::UnregisterServer(const Registration::Sample& sample_)
{
const auto& sample_service = sample_.service;
const auto& sample_identifier = sample_.identifier;

const std::string& service_name = sample_service.sname;
const std::string& service_id = sample_identifier.entity_id;
const int process_id = sample_identifier.process_id;

// create map key
const std::string service_name_id = service_name + service_id + std::to_string(process_id);
const auto& service_map_key = sample_.identifier.entity_id;

// acquire access
const std::lock_guard<std::mutex> lock(m_server_map.sync);

// remove service info
m_server_map.map->erase(service_name_id);
m_server_map.map->erase(service_map_key);

return(true);
}

bool CMonitoringImpl::RegisterClient(const Registration::Sample& sample_)
{
const auto& sample_identifier = sample_.identifier;
const std::string& service_id = sample_identifier.entity_id;
const auto& service_id = sample_identifier.entity_id;
const int32_t process_id = sample_identifier.process_id;
const std::string& host_name = sample_identifier.host_name;

Expand All @@ -465,13 +450,13 @@ namespace eCAL
const std::string& unit_name = sample_client.uname;

// create map key
const std::string service_name_id = service_name + service_id + std::to_string(process_id);
const auto& client_map_key = service_id;

// acquire access
const std::lock_guard<std::mutex> lock(m_clients_map.sync);

// try to get service info
Monitoring::SClientMon& ClientInfo = (*m_clients_map.map)[service_name_id];
Monitoring::SClientMon& ClientInfo = (*m_clients_map.map)[client_map_key];

// set static content
ClientInfo.hname = host_name;
Expand Down Expand Up @@ -501,21 +486,14 @@ namespace eCAL

bool CMonitoringImpl::UnregisterClient(const Registration::Sample& sample_)
{
const auto& sample_identifier = sample_.identifier;
const std::string& service_id = sample_identifier.entity_id;
const int32_t process_id = sample_identifier.process_id;

const auto& sample_client = sample_.client;
const std::string& service_name = sample_client.sname;

// create map key
const std::string service_name_id = service_name + service_id + std::to_string(process_id);
const auto& client_map_key = sample_.identifier.entity_id;

// acquire access
const std::lock_guard<std::mutex> lock(m_clients_map.sync);

// remove service info
m_clients_map.map->erase(service_name_id);
m_clients_map.map->erase(client_map_key);

return(true);
}
Expand Down
10 changes: 5 additions & 5 deletions ecal/core/src/monitoring/ecal_monitoring_impl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -79,7 +79,7 @@ namespace eCAL
bool RegisterTopic(const Registration::Sample& sample_, enum ePubSub pubsub_type_);
bool UnregisterTopic(const Registration::Sample& sample_, enum ePubSub pubsub_type_);

using TopicMonMapT = std::map<std::string, Monitoring::STopicMon>;
using TopicMonMapT = std::map<Registration::EntityIdT, Monitoring::STopicMon>;
struct STopicMonMap
{
explicit STopicMonMap() :
Expand All @@ -90,7 +90,7 @@ namespace eCAL
std::unique_ptr<TopicMonMapT> map;
};

using ProcessMonMapT = std::map<std::string, Monitoring::SProcessMon>;
using ProcessMonMapT = std::map<Registration::EntityIdT, Monitoring::SProcessMon>;
struct SProcessMonMap
{
explicit SProcessMonMap() :
Expand All @@ -101,7 +101,7 @@ namespace eCAL
std::unique_ptr<ProcessMonMapT> map;
};

using ServerMonMapT = std::map<std::string, Monitoring::SServerMon>;
using ServerMonMapT = std::map<Registration::EntityIdT, Monitoring::SServerMon>;
struct SServerMonMap
{
explicit SServerMonMap() :
Expand All @@ -112,7 +112,7 @@ namespace eCAL
std::unique_ptr<ServerMonMapT> map;
};

using ClientMonMapT = std::map<std::string, Monitoring::SClientMon>;
using ClientMonMapT = std::map<Registration::EntityIdT, Monitoring::SClientMon>;
struct SClientMonMap
{
explicit SClientMonMap() :
Expand Down
14 changes: 6 additions & 8 deletions ecal/core/src/pubsub/ecal_publisher_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2024 Continental Corporation
* Copyright (C) 2016 - 2025 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,9 +51,9 @@

struct SSndHash
{
SSndHash(std::string t, long long c) : topic_id(t), snd_clock(c) {}
std::string topic_id;
long long snd_clock;
SSndHash(const eCAL::Registration::EntityIdT& t, long long c) : topic_id(t), snd_clock(c) {}
eCAL::Registration::EntityIdT topic_id;
long long snd_clock;
};

namespace std
Expand All @@ -63,7 +63,7 @@ namespace std
public:
size_t operator()(const SSndHash& h) const
{
const size_t h1 = std::hash<std::string>()(h.topic_id);
const size_t h1 = std::hash<eCAL::Registration::EntityIdT>()(h.topic_id);
const size_t h2 = std::hash<long long>()(h.snd_clock);
return h1 ^ (h2 << 1);
}
Expand Down Expand Up @@ -109,9 +109,7 @@ namespace eCAL
#endif

// build topic id
std::stringstream counter;
counter << std::chrono::steady_clock::now().time_since_epoch().count();
m_topic_id = counter.str();
m_topic_id = std::chrono::steady_clock::now().time_since_epoch().count();

// mark as created
m_created = true;
Expand Down
Loading

0 comments on commit 6e7ffce

Please sign in to comment.