Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficiency get entity search [12001] #110

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
cmake_minimum_required(VERSION 3.10)
cmake_policy(VERSION 3.10...3.20)


# Set CMAKE_BUILD_TYPE to Release by default.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

###############################################################################
# Project
###############################################################################
Expand Down
220 changes: 154 additions & 66 deletions src/cpp/database/database.cpp

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions src/cpp/database/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,13 @@ class Database
* Get an entity given its EntityId
*
* @param entity_id constant reference to the EntityId of the retrieved entity.
* @param entity_kind Kind of the entity to speed up the search. Default/Unknown INVALID.
* @throws eprosima::statistics_backend::BadParameter if there is no entity with the given ID.
* @return A constant shared pointer to the Entity.
*/
const std::shared_ptr<const Entity> get_entity(
const EntityId& entity_id) const;
const EntityId& entity_id,
const EntityKind entity_kind = EntityKind::INVALID) const;

/**
* Get all entities of a given EntityKind related to another entity.
Expand All @@ -229,6 +231,7 @@ class Database
* @param entity_id constant reference to the EntityId of the entity to which the returned
* entities are related.
* @param entity_kind The EntityKind of the fetched entities.
* @param source_entity_kind Kind of the source of the entity to speed up the search. Default/Unknown INVALID.
* @throws eprosima::statistics_backend::BadParameter in the following case:
* * if the \c entity_kind is \c INVALID.
* * if the \c entity_id does not reference a entity contained in the database or is not EntityId::all().
Expand All @@ -237,7 +240,8 @@ class Database
*/
const std::vector<std::shared_ptr<const Entity>> get_entities(
EntityKind entity_kind,
const EntityId& entity_id) const;
const EntityId& entity_id,
const EntityKind source_entity_kind = EntityKind::INVALID) const;

/**
* Get all EntityIds of a given EntityKind related to another entity.
Expand All @@ -247,6 +251,7 @@ class Database
* @param entity_id constant reference to the EntityId of the entity to which the returned
* entities are related.
* @param entity_kind The EntityKind of the fetched entities.
* @param source_entity_kind Kind of the source of the entity to speed up the search. Default/Unknown INVALID.
* @throws eprosima::statistics_backend::BadParameter in the following case:
* * if the \c entity_kind is \c INVALID.
* * if the \c entity_id does not reference a entity contained in the database or is not EntityId::all().
Expand All @@ -255,7 +260,8 @@ class Database
*/
std::vector<EntityId> get_entity_ids(
EntityKind entity_type,
const EntityId& entity_id) const;
const EntityId& entity_id,
const EntityKind source_entity_kind = EntityKind::INVALID) const;

/**
* @brief Generate an EntityId that is unique for the database.
Expand Down
8 changes: 5 additions & 3 deletions src/cpp/database/database_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ void DatabaseDataQueue::process_sample()
{
// Host name reported by Fast DDS are considered unique
std::shared_ptr<const Host> const_host = std::dynamic_pointer_cast<const Host>(database_->get_entity(
hosts.front().second));
hosts.front().second, EntityKind::HOST));
host = std::const_pointer_cast<Host>(const_host);
}

Expand All @@ -709,7 +709,7 @@ void DatabaseDataQueue::process_sample()
for (const auto& it : users)
{
std::shared_ptr<const User> const_user =
std::dynamic_pointer_cast<const User>(database_->get_entity(it.second));
std::dynamic_pointer_cast<const User>(database_->get_entity(it.second, EntityKind::USER));

// The user name is unique within the host
if (const_user->host == host)
Expand All @@ -731,7 +731,9 @@ void DatabaseDataQueue::process_sample()
for (const auto& it : processes)
{
std::shared_ptr<const Process> const_process =
std::dynamic_pointer_cast<const Process>(database_->get_entity(it.second));
std::dynamic_pointer_cast<const Process>(database_->get_entity(
it.second,
EntityKind::PROCESS));

// There is only one process with the same name for a given user
if (const_process->user == user)
Expand Down
30 changes: 20 additions & 10 deletions src/cpp/subscriber/StatisticsParticipantListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void StatisticsParticipantListener::process_endpoint_discovery(
// This may throw if the domain does not exist
// The database MUST contain the domain, or something went wrong upstream
std::shared_ptr<database::Domain> domain = std::const_pointer_cast<database::Domain>(
std::static_pointer_cast<const database::Domain>(database_->get_entity(domain_id_)));
std::static_pointer_cast<const database::Domain>(database_->get_entity(domain_id_, EntityKind::DOMAIN)));

// Get the participant from the database
GUID_t endpoint_guid = info.info.guid();
Expand All @@ -86,7 +86,7 @@ void StatisticsParticipantListener::process_endpoint_discovery(
std::shared_ptr<database::DomainParticipant> participant =
std::const_pointer_cast<database::DomainParticipant>(
std::static_pointer_cast<const database::DomainParticipant>(database_->get_entity(
participant_id.second)));
participant_id.second, EntityKind::PARTICIPANT)));

assert(participant_id.first == domain_id_);

Expand All @@ -100,7 +100,9 @@ void StatisticsParticipantListener::process_endpoint_discovery(
if (topic_id.first == domain_id_)
{
topic = std::const_pointer_cast<database::Topic>(
std::static_pointer_cast<const database::Topic>(database_->get_entity(topic_id.second)));
std::static_pointer_cast<const database::Topic>(database_->get_entity(
topic_id.second,
EntityKind::TOPIC)));

if (topic->data_type == info.info.typeName().to_string())
{
Expand Down Expand Up @@ -134,7 +136,6 @@ void StatisticsParticipantListener::process_endpoint_discovery(
auto endpoint = create_endpoint(endpoint_guid, info, participant, topic);

/* Start processing the locator info */

// Routine to process one locator from the locator list of the endpoint
auto process_locators = [&](const Locator_t& dds_locator)
{
Expand All @@ -149,8 +150,9 @@ void StatisticsParticipantListener::process_endpoint_discovery(
{
// The locator exists.
locator = std::const_pointer_cast<database::Locator>(
std::static_pointer_cast<const database::Locator>(database_->get_entity(locator_ids.front().
second)));
std::static_pointer_cast<const database::Locator>(database_->get_entity(
locator_ids.front().second,
EntityKind::LOCATOR)));
}
else
{
Expand Down Expand Up @@ -319,7 +321,9 @@ void StatisticsParticipantListener::on_participant_discovery(
database::EntityDiscoveryInfo entity_discovery_info;
entity_discovery_info.domain_id = domain_id_;
entity_discovery_info.entity = std::const_pointer_cast<database::DomainParticipant>(
std::static_pointer_cast<const database::DomainParticipant>(database_->get_entity(participant_id)));
std::static_pointer_cast<const database::DomainParticipant>(database_->get_entity(
participant_id,
EntityKind::PARTICIPANT)));

switch (info.status)
{
Expand Down Expand Up @@ -352,7 +356,9 @@ void StatisticsParticipantListener::on_participant_discovery(
// This may throw if the domain does not exist
// The database MUST contain the domain, or something went wrong upstream
std::shared_ptr<database::Domain> domain = std::const_pointer_cast<database::Domain>(
std::static_pointer_cast<const database::Domain>(database_->get_entity(domain_id_)));
std::static_pointer_cast<const database::Domain>(database_->get_entity(
domain_id_,
EntityKind::DOMAIN)));

std::string name = info.info.m_participantName.to_string();

Expand Down Expand Up @@ -418,7 +424,9 @@ void StatisticsParticipantListener::on_subscriber_discovery(
database::EntityDiscoveryInfo entity_discovery_info;
entity_discovery_info.domain_id = domain_id_;
entity_discovery_info.entity = std::const_pointer_cast<database::DataReader>(
std::static_pointer_cast<const database::DataReader>(database_->get_entity(datareader_id)));
std::static_pointer_cast<const database::DataReader>(database_->get_entity(
datareader_id,
EntityKind::DATAREADER)));

switch (info.status)
{
Expand Down Expand Up @@ -488,7 +496,9 @@ void StatisticsParticipantListener::on_publisher_discovery(
database::EntityDiscoveryInfo entity_discovery_info;
entity_discovery_info.domain_id = domain_id_;
entity_discovery_info.entity = std::const_pointer_cast<database::DataWriter>(
std::static_pointer_cast<const database::DataWriter>(database_->get_entity(datawriter_id)));
std::static_pointer_cast<const database::DataWriter>(database_->get_entity(
datawriter_id,
EntityKind::DATAWRITER)));

switch (info.status)
{
Expand Down
14 changes: 14 additions & 0 deletions test/mock/database/database/database/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,28 @@ class Database
MOCK_CONST_METHOD1(get_entity, const std::shared_ptr<const Entity>(
const EntityId& entity_id));

MOCK_CONST_METHOD2(get_entity, const std::shared_ptr<const Entity>(
const EntityId& entity_id,
const EntityKind entity_kind));

MOCK_CONST_METHOD2(get_entities, const std::vector<std::shared_ptr<const Entity>>(
EntityKind entity_kind,
const EntityId& entity_id));

MOCK_CONST_METHOD3(get_entities, const std::vector<std::shared_ptr<const Entity>>(
EntityKind entity_kind,
const EntityId& entity_id,
const EntityKind source_entity_kind));

MOCK_CONST_METHOD2(get_entity_ids, std::vector<EntityId>(
EntityKind entity_kind,
const EntityId& entity_id));

MOCK_CONST_METHOD3(get_entity_ids, std::vector<EntityId>(
EntityKind entity_kind,
const EntityId& entity_id,
const EntityKind source_entity_kind));

MOCK_CONST_METHOD2(get_entity_by_guid, std::pair<EntityId, EntityId>(
EntityKind entity_kind,
const std::string& guid));
Expand Down
20 changes: 16 additions & 4 deletions test/unittest/Database/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,19 @@ set(DATABASE_TEST_LIST
get_entity_datareader
get_entity_datawriter
get_entity_locator
get_entity_host_efficient_search
get_entity_process_efficient_search
get_entity_user_efficient_search
get_entity_domain_efficient_search
get_entity_topic_efficient_search
get_entity_participant_efficient_search
get_entity_datareader_efficient_search
get_entity_datawriter_efficient_search
get_entity_locator_efficient_search

get_entity_no_existing
get_entity_no_correct_kind

# get_entities_by_name
get_entities_by_name_host
get_entities_by_name_host_wrong_name
Expand Down Expand Up @@ -473,7 +485,7 @@ endforeach()
add_executable(database_load_tests DatabaseLoadTests.cpp ${LIBRARY_SOURCES})

if(MSVC)
target_compile_definitions(database_load_tests PRIVATE
target_compile_definitions(database_load_tests PRIVATE
_CRT_DECLARE_NONSTDC_NAMES=0 FASTDDS_STATISTICS_BACKEND_SOURCE)
endif(MSVC)

Expand Down Expand Up @@ -525,7 +537,7 @@ endforeach()
add_executable(database_load_insert_tests DatabaseLoadInsertTests.cpp ${LIBRARY_SOURCES})

if(MSVC)
target_compile_definitions(database_load_insert_tests PRIVATE
target_compile_definitions(database_load_insert_tests PRIVATE
_CRT_DECLARE_NONSTDC_NAMES=0 FASTDDS_STATISTICS_BACKEND_SOURCE)
endif(MSVC)

Expand Down Expand Up @@ -565,7 +577,7 @@ endforeach()
add_executable(database_status_tests DatabaseStatusTests.cpp ${LIBRARY_SOURCES})

if(MSVC)
target_compile_definitions(database_status_tests PRIVATE
target_compile_definitions(database_status_tests PRIVATE
_CRT_DECLARE_NONSTDC_NAMES=0 FASTDDS_STATISTICS_BACKEND_SOURCE)
endif(MSVC)

Expand Down Expand Up @@ -615,7 +627,7 @@ endforeach()
add_executable(database_erase_tests DatabaseEraseTests.cpp ${LIBRARY_SOURCES})

if(MSVC)
target_compile_definitions(database_erase_tests PRIVATE
target_compile_definitions(database_erase_tests PRIVATE
_CRT_DECLARE_NONSTDC_NAMES=0 FASTDDS_STATISTICS_BACKEND_SOURCE)
endif(MSVC)

Expand Down
Loading