Skip to content

Commit

Permalink
Refs #12001: apply changes
Browse files Browse the repository at this point in the history
Signed-off-by: jparisu <javierparis@eprosima.com>
  • Loading branch information
jparisu committed Jul 13, 2021
1 parent 6bbf013 commit 6843bf5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
42 changes: 29 additions & 13 deletions src/cpp/database/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,37 +1487,53 @@ std::vector<const StatisticsSample*> Database::select(
std::shared_ptr<const eprosima::statistics_backend::database::Entity> source_entity;
std::shared_ptr<const eprosima::statistics_backend::database::Entity> target_entity;

EntityKind last_iteration_kind_source = EntityKind::INVALID;
EntityKind last_iteration_kind_target = EntityKind::INVALID;

for (auto kinds : StatisticsBackend::get_data_supported_entity_kinds(data_type))
{
try
{
// In case the kind is the same as the last iteration and the entity was already found
// do not look for it again
if (!source_entity || last_iteration_kind_source != kinds.first)
// In case the entity already exists, it does not need to seach for it but to compare its kind.
// If the kind is the same as the one is needed, continue looking for the target.
// If it is not, this pair of kinds is not correct and continue to the other.
if (!source_entity)
{
source_entity = get_entity(entity_id_source, kinds.first);
}
if (!target_entity || last_iteration_kind_target != kinds.second)
else
{
if (source_entity->kind != kinds.first)
{
continue;
}
}

if (!target_entity)
{
target_entity = get_entity(entity_id_target, kinds.second);
}
else
{
if (target_entity->kind != kinds.second)
{
continue;
}
}
}
catch (const std::exception& e)
{
// It has not found the entity, check next kinds possibility
// It has not found the entity, check next possible kinds
continue;
}

// In case it has found it, follow with that entity
// In case both entities have been found, follow with them
break;
}

// There is no way to set both to not null unless it is a pair with both types.
// Every time source entity is found in correct kind look for target, if found correct, if not target is null.
// Target does not look for an entity unless source has been found AND in the correct entity.
if (!source_entity || !target_entity)
{
throw BadParameter("Entity not found in required EntityKind for this DataKind");
throw BadParameter("Entity not found in required EntityKind for the given DataKind");
}

std::shared_lock<std::shared_timed_mutex> lock(mutex_);
Expand Down Expand Up @@ -1711,17 +1727,17 @@ std::vector<const StatisticsSample*> Database::select(
}
catch (const std::exception& e)
{
// It has not found the entity, check next kinds possibility
// It has not found the entity, check next possible kind
continue;
}

// In case it has found it, follow with that entity
// In case it has found the entity, follow with it
break;
}

if (!entity)
{
throw BadParameter("Entity not found in required EntityKind for this DataKind");
throw BadParameter("Entity not found in required EntityKind for the given DataKind");
}

std::shared_lock<std::shared_timed_mutex> lock(mutex_);
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/database/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ 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 look up it faster. Default/Unknown INVALID.
* @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.
*/
Expand All @@ -231,7 +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 look up it faster. Default/Unknown INVALID.
* @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 @@ -251,7 +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 look up it faster. Default/Unknown INVALID.
* @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 Down
1 change: 0 additions & 1 deletion test/unittest/Database/DatabaseTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3439,7 +3439,6 @@ TEST_F(database_tests, select_rtps_packets_lost)
TEST_F(database_tests, select_rtps_bytes_lost)
{
data_output.clear();
db.select(DataKind::RTPS_BYTES_LOST, participant_id, writer_locator->id, src_ts, end_ts);
ASSERT_NO_THROW(data_output = db.select(DataKind::RTPS_BYTES_LOST, participant_id, writer_locator->id, src_ts,
end_ts));
EXPECT_EQ(data_output.size(), 0u);
Expand Down

0 comments on commit 6843bf5

Please sign in to comment.