Skip to content

Commit 6433fd6

Browse files
committed
[#24061] Preserve reader partition filter on endpoint updates
Signed-off-by: danipiza <dpizarrogallego@gmail.com>
1 parent 584741a commit 6433fd6

4 files changed

Lines changed: 63 additions & 55 deletions

File tree

ddspipe_core/include/ddspipe_core/core/DdsPipe.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ class DdsPipe
463463
//! Allowed partitions list added in the filter.
464464
std::set<std::string> filter_partition_;
465465

466+
//! Current partitions configured in readers through \c update_partitions.
467+
std::set<std::string> reader_partitions_;
468+
466469
/**
467470
* @brief Internal mutex for concurrent calls
468471
*/

ddspipe_core/src/cpp/core/DdsPipe.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,11 @@ void DdsPipe::discovered_endpoint_nts_(
299299
}
300300
else
301301
{
302-
// there is a filter.
303-
// update the track of the topic to
304-
// add the partition in the reader if it is in the filter
302+
// Another endpoint from an already tracked topic/participant was discovered
303+
// Refresh bridge partition metadata and reader partition QoS
305304

306305
const auto bridge_it = bridges_.find(utils::Heritable<DdsTopic>::make_heritable(endpoint.topic));
307-
// add the specific partition of the endpoint in the bridge topic.
306+
// Add the specific partition of the endpoint in the bridge topic
308307
if (bridge_it != bridges_.end())
309308
{
310309
std::ostringstream guid_ss;
@@ -317,10 +316,15 @@ void DdsPipe::discovered_endpoint_nts_(
317316
}
318317
}
319318

320-
// update readers outside the lock
321-
if (!filter_partition_.empty())
319+
// Refresh this bridge so writers receive the updated guid->partition map
320+
// Also refresh reader partitions using
321+
// filter (if set), otherwise
322+
// the current reader partition configuration
323+
if (bridge_it != bridges_.end())
322324
{
323-
update_partitions_nts_(filter_partition_);
325+
const auto& partitions_to_apply =
326+
filter_partition_.empty() ? reader_partitions_ : filter_partition_;
327+
bridge_it->second->update_partitions(partitions_to_apply);
324328
}
325329
}
326330
}
@@ -624,6 +628,7 @@ void DdsPipe::update_partitions(
624628
{
625629
std::lock_guard<std::mutex> lock(mutex_);
626630

631+
reader_partitions_ = partitions_set;
627632
update_partitions_nts_(partitions_set);
628633
}
629634

ddspipe_participants/src/cpp/reader/dds/CommonReader.cpp

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ namespace dds {
3535

3636
using namespace eprosima::ddspipe::core::types;
3737

38+
static void apply_reader_partitions_(
39+
fastdds::dds::PartitionQosPolicy& partition_qos,
40+
const std::set<std::string>& partitions_filter)
41+
{
42+
partition_qos.clear();
43+
44+
// Empty filter means no filter: subscribe to all partitions
45+
if (partitions_filter.empty())
46+
{
47+
partition_qos.push_back("*");
48+
return;
49+
}
50+
51+
for (const std::string& partition : partitions_filter)
52+
{
53+
partition_qos.push_back(partition.c_str());
54+
}
55+
}
56+
3857
CommonReader::~CommonReader()
3958
{
4059
// This variables should be set, otherwise the creation should have fail
@@ -76,22 +95,11 @@ void CommonReader::init(
7695
<< participant_id_ << " in topic " << topic_ << ".");
7796
}
7897

79-
// If the reader has an active filter
80-
// change the qos partition before creating the datareader.
81-
if (partitions_set.size() > 0)
82-
{
83-
// Get the current subscriber qos
84-
fastdds::dds::SubscriberQos sub_qos = dds_subscriber_->get_qos();
85-
// Remove all partitions from the qos
86-
sub_qos.partition().clear();
87-
// Add the filter partitions
88-
for (const std::string& partition: partitions_set)
89-
{
90-
sub_qos.partition().push_back(partition.c_str());
91-
}
92-
// Update the subscriber qos
93-
dds_subscriber_->set_qos(sub_qos);
94-
}
98+
// Update subscriber partitions before creating the datareader
99+
// Empty filter means subscribe to all partitions ("*")
100+
fastdds::dds::SubscriberQos sub_qos = dds_subscriber_->get_qos();
101+
apply_reader_partitions_(sub_qos.partition(), partitions_set);
102+
dds_subscriber_->set_qos(sub_qos);
95103

96104
auto topic_tmp = dds_participant_->find_topic(topic_.topic_name(), 10);
97105

@@ -263,10 +271,6 @@ void CommonReader::enable_nts_() noexcept
263271
fastdds::dds::SubscriberQos CommonReader::reckon_subscriber_qos_() const
264272
{
265273
fastdds::dds::SubscriberQos qos = dds_participant_->get_default_subscriber_qos();
266-
if (topic_.topic_qos.has_partitions())
267-
{
268-
qos.partition().push_back("*");
269-
}
270274
qos.entity_factory().autoenable_created_entities = false;
271275
return qos;
272276
}
@@ -393,12 +397,7 @@ void CommonReader::update_partitions(
393397
const std::set<std::string>& partitions_set)
394398
{
395399
fastdds::dds::SubscriberQos sub_qos = dds_subscriber_->get_qos();
396-
sub_qos.partition().clear();
397-
for (const std::string& partition: partitions_set)
398-
{
399-
sub_qos.partition().push_back(partition.c_str());
400-
}
401-
400+
apply_reader_partitions_(sub_qos.partition(), partitions_set);
402401
dds_subscriber_->set_qos(sub_qos);
403402
}
404403

ddspipe_participants/src/cpp/reader/rtps/CommonReader.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ namespace rtps {
3737
using namespace eprosima::ddspipe::core::types;
3838
using eprosima::ddspipe::core::types::operator <<;
3939

40+
static void apply_reader_partitions_(
41+
fastdds::dds::PartitionQosPolicy& partition_qos,
42+
const std::set<std::string>& partitions_filter)
43+
{
44+
partition_qos.clear();
45+
46+
// Empty filter means no filter: subscribe to all partitions
47+
if (partitions_filter.empty())
48+
{
49+
partition_qos.push_back("*");
50+
return;
51+
}
52+
53+
for (const std::string& partition : partitions_filter)
54+
{
55+
partition_qos.push_back(partition.c_str());
56+
}
57+
}
58+
4059
CommonReader::CommonReader(
4160
const ParticipantId& participant_id,
4261
const DdsTopic& topic,
@@ -125,19 +144,9 @@ void CommonReader::internal_entities_creation_(
125144
<< participant_id_ << " in topic " << topic_ << ".");
126145
}
127146

128-
if (partitions_set.size() > 0)
129-
{
130-
auto& sub_part_qos = reader_qos_.m_partition;
131-
// Clear the partitions
132-
sub_part_qos.clear();
133-
// Add the partitions from the filter
134-
for (const auto& partition : partitions_set)
135-
{
136-
sub_part_qos.push_back(partition.c_str());
137-
}
138-
139-
// no content topic filter
140-
}
147+
// Update reader partitions before registration
148+
// Empty filter means subscribe to all partitions ("*")
149+
apply_reader_partitions_(reader_qos_.m_partition, partitions_set);
141150

142151
// Register reader with topic
143152
if (!rtps_participant_->register_reader(rtps_reader_, topic_description, reader_qos_))
@@ -177,15 +186,7 @@ core::types::DdsTopic CommonReader::topic() const noexcept
177186
void CommonReader::update_partitions(
178187
const std::set<std::string>& partitions_set)
179188
{
180-
// Get the partitions from the reader qos
181-
auto& sub_part_qos = reader_qos_.m_partition;
182-
// Clear the partitions
183-
sub_part_qos.clear();
184-
// Add the partitions from the filter
185-
for (const auto& partition : partitions_set)
186-
{
187-
sub_part_qos.push_back(partition.c_str());
188-
}
189+
apply_reader_partitions_(reader_qos_.m_partition, partitions_set);
189190
// Update the reader with the new partitions
190191
rtps_participant_->update_reader(rtps_reader_, reader_qos_);
191192
}

0 commit comments

Comments
 (0)