Skip to content

Commit d435910

Browse files
author
jparisu
committed
Refs #12001: apply changes
Signed-off-by: jparisu <[email protected]>
1 parent 2e946de commit d435910

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

src/cpp/database/database.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,37 +1478,53 @@ std::vector<const StatisticsSample*> Database::select(
14781478
std::shared_ptr<const eprosima::statistics_backend::database::Entity> source_entity;
14791479
std::shared_ptr<const eprosima::statistics_backend::database::Entity> target_entity;
14801480

1481-
EntityKind last_iteration_kind_source = EntityKind::INVALID;
1482-
EntityKind last_iteration_kind_target = EntityKind::INVALID;
1483-
14841481
for (auto kinds : StatisticsBackend::get_data_supported_entity_kinds(data_type))
14851482
{
14861483
try
14871484
{
1488-
// In case the kind is the same as the last iteration and the entity was already found
1489-
// do not look for it again
1490-
if (!source_entity || last_iteration_kind_source != kinds.first)
1485+
// In case the entity already exists, it does not need to seach for it but to compare its kind.
1486+
// If the kind is the same as the one is needed, continue looking for the target.
1487+
// If it is not, this pair of kinds is not correct and continue to the other.
1488+
if (!source_entity)
14911489
{
14921490
source_entity = get_entity(entity_id_source, kinds.first);
14931491
}
1494-
if (!target_entity || last_iteration_kind_target != kinds.second)
1492+
else
1493+
{
1494+
if (source_entity->kind != kinds.first)
1495+
{
1496+
continue;
1497+
}
1498+
}
1499+
1500+
if (!target_entity)
14951501
{
14961502
target_entity = get_entity(entity_id_target, kinds.second);
14971503
}
1504+
else
1505+
{
1506+
if (target_entity->kind != kinds.second)
1507+
{
1508+
continue;
1509+
}
1510+
}
14981511
}
14991512
catch (const std::exception& e)
15001513
{
1501-
// It has not found the entity, check next kinds possibility
1514+
// It has not found the entity, check next possible kinds
15021515
continue;
15031516
}
15041517

1505-
// In case it has found it, follow with that entity
1518+
// In case both entities have been found, follow with them
15061519
break;
15071520
}
15081521

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

15141530
std::shared_lock<std::shared_timed_mutex> lock(mutex_);
@@ -1702,17 +1718,17 @@ std::vector<const StatisticsSample*> Database::select(
17021718
}
17031719
catch (const std::exception& e)
17041720
{
1705-
// It has not found the entity, check next kinds possibility
1721+
// It has not found the entity, check next possible kind
17061722
continue;
17071723
}
17081724

1709-
// In case it has found it, follow with that entity
1725+
// In case it has found the entity, follow with it
17101726
break;
17111727
}
17121728

17131729
if (!entity)
17141730
{
1715-
throw BadParameter("Entity not found in required EntityKind for this DataKind");
1731+
throw BadParameter("Entity not found in required EntityKind for the given DataKind");
17161732
}
17171733

17181734
std::shared_lock<std::shared_timed_mutex> lock(mutex_);

src/cpp/database/database.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class Database
215215
* Get an entity given its EntityId
216216
*
217217
* @param entity_id constant reference to the EntityId of the retrieved entity.
218-
* @param entity_kind Kind of the entity to look up it faster. Default/Unknown INVALID.
218+
* @param entity_kind Kind of the entity to speed up the search. Default/Unknown INVALID.
219219
* @throws eprosima::statistics_backend::BadParameter if there is no entity with the given ID.
220220
* @return A constant shared pointer to the Entity.
221221
*/
@@ -231,7 +231,7 @@ class Database
231231
* @param entity_id constant reference to the EntityId of the entity to which the returned
232232
* entities are related.
233233
* @param entity_kind The EntityKind of the fetched entities.
234-
* @param source_entity_kind Kind of the source of the entity to look up it faster. Default/Unknown INVALID.
234+
* @param source_entity_kind Kind of the source of the entity to speed up the search. Default/Unknown INVALID.
235235
* @throws eprosima::statistics_backend::BadParameter in the following case:
236236
* * if the \c entity_kind is \c INVALID.
237237
* * if the \c entity_id does not reference a entity contained in the database or is not EntityId::all().
@@ -251,7 +251,7 @@ class Database
251251
* @param entity_id constant reference to the EntityId of the entity to which the returned
252252
* entities are related.
253253
* @param entity_kind The EntityKind of the fetched entities.
254-
* @param source_entity_kind Kind of the source of the entity to look up it faster. Default/Unknown INVALID.
254+
* @param source_entity_kind Kind of the source of the entity to speed up the search. Default/Unknown INVALID.
255255
* @throws eprosima::statistics_backend::BadParameter in the following case:
256256
* * if the \c entity_kind is \c INVALID.
257257
* * if the \c entity_id does not reference a entity contained in the database or is not EntityId::all().

test/unittest/Database/DatabaseTests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3439,7 +3439,6 @@ TEST_F(database_tests, select_rtps_packets_lost)
34393439
TEST_F(database_tests, select_rtps_bytes_lost)
34403440
{
34413441
data_output.clear();
3442-
db.select(DataKind::RTPS_BYTES_LOST, participant_id, writer_locator->id, src_ts, end_ts);
34433442
ASSERT_NO_THROW(data_output = db.select(DataKind::RTPS_BYTES_LOST, participant_id, writer_locator->id, src_ts,
34443443
end_ts));
34453444
EXPECT_EQ(data_output.size(), 0u);

0 commit comments

Comments
 (0)