-
Notifications
You must be signed in to change notification settings - Fork 793
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
[12552] delete_contained_entities implementation #2223
Conversation
…Participant, Publisher, Subscriber and DataReader Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
…s implementation Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
…ent function Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
std::vector<DataReader*> reader_vector; | ||
get_datareaders(reader_vector); | ||
|
||
std::lock_guard<std::mutex> lock(mtx_readers_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the lock up, to ensure there is no other reader created in between
std::vector<DataReader*> reader_vector; | |
get_datareaders(reader_vector); | |
std::lock_guard<std::mutex> lock(mtx_readers_); | |
std::lock_guard<std::mutex> lock(mtx_readers_); | |
std::vector<DataReader*> reader_vector; | |
get_datareaders(reader_vector); |
Also, we can traverse the readers_
map directly, and we'll avoid allocating the reader_vector
elements on the heap.
for (DataReader* reader: reader_vector) | ||
{ | ||
can_be_deleted = can_be_deleted && reader->impl_->can_be_deleted(); | ||
if (!can_be_deleted) | ||
{ | ||
return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid the result
variable altogether
for (DataReader* reader: reader_vector) | |
{ | |
can_be_deleted = can_be_deleted && reader->impl_->can_be_deleted(); | |
if (!can_be_deleted) | |
{ | |
return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; | |
} | |
} | |
for (DataReader* reader: reader_vector) | |
{ | |
if (!reader->impl_->can_be_deleted()) | |
{ | |
return ReturnCode_t::RETCODE_PRECONDITION_NOT_MET; | |
} | |
} |
return_status = return_status && dr->can_be_deleted(); | ||
if (!return_status) | ||
{ | ||
return return_status; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify and avoid the bitwise AND.
Same applies to the publisher
return_status = return_status && dr->can_be_deleted(); | |
if (!return_status) | |
{ | |
return return_status; | |
} | |
return_status = dr->can_be_deleted(); | |
if (!return_status) | |
{ | |
return true; | |
} |
//std::vector<DataWriter*> writer_vector; | ||
//get_datawriters(writer_vector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code
/* std::lock_guard<std::mutex> lock(mtx_writers_); | ||
for (DataWriter* writer: writer_vector) | ||
{ | ||
can_be_deleted = can_be_deleted && (writer->impl_->check_delete_preconditions() == ReturnCode_t::RETCODE_OK); | ||
if (!can_be_deleted) | ||
{ | ||
return can_be_deleted; | ||
} | ||
}*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code
|
||
for (auto& subscriber : subscribers_) | ||
{ | ||
subscriber.first->delete_contained_entities(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the return code and exit with error if it is not OK
|
||
for (auto& publisher : publishers_) | ||
{ | ||
publisher.first->delete_contained_entities(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the return code and exit with error if it is not OK
); | ||
ASSERT_EQ(query_condition, nullptr); | ||
|
||
ASSERT_EQ(data_reader->delete_contained_entities(), ReturnCode_t::RETCODE_OK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment stating that this must be updated once the query conditions are in place
ASSERT_TRUE(data_reader_list.size() == 2); | ||
|
||
data_reader_list.clear(); | ||
ASSERT_EQ(subscriber->delete_contained_entities(), ReturnCode_t::RETCODE_OK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment stating that this must be updated once the query conditions are in place
@@ -535,6 +535,83 @@ class DomainParticipantImpl | |||
return false; | |||
} | |||
|
|||
ReturnCode_t delete_contained_entities() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update this implementation to manage the locks as in the real implementation. It is not so important in the mock, but releasing the locks may result in publishers or subscribers being create in between.
Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
//std::vector<DataWriter*> writer_vector; | ||
//get_datawriters(writer_vector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code
Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI errors seem to be unrelated to the changes.
LGTM
@Mergifyio backport 2.3.x |
* Refs #12532: Added delete_contained_entities implementation to DomainParticipant, Publisher, Subscriber and DataReader Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Added tests to validate the new delete_contained_entities implementation Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Formatting and comment cleanup Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Modified test to check for entity presence with a different function Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Added delete_contained_entities to Statistics mock classes Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Modified locking logic and unit test Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: General improvements from PR suggestions Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Comment cleanup Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> (cherry picked from commit af0ff68) # Conflicts: # test/unittest/dds/subscriber/DataReaderTests.cpp # test/unittest/dds/subscriber/SubscriberTests.cpp
✅ Backports have been created
|
* Refs #12532: Added delete_contained_entities implementation to DomainParticipant, Publisher, Subscriber and DataReader Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Added tests to validate the new delete_contained_entities implementation Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Formatting and comment cleanup Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Modified test to check for entity presence with a different function Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Added delete_contained_entities to Statistics mock classes Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Modified locking logic and unit test Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: General improvements from PR suggestions Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Comment cleanup Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> (cherry picked from commit af0ff68)
* delete_contained_entities implementation (#2223) * Refs #12532: Added delete_contained_entities implementation to DomainParticipant, Publisher, Subscriber and DataReader Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Added tests to validate the new delete_contained_entities implementation Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Formatting and comment cleanup Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Modified test to check for entity presence with a different function Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Added delete_contained_entities to Statistics mock classes Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Modified locking logic and unit test Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: General improvements from PR suggestions Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> * Refs #12532: Comment cleanup Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> (cherry picked from commit af0ff68) * Refs #12990: delete_contained_entities 2.3.x backport Signed-off-by: Javier Santiago <javiersantiago@eprosima.com> Co-authored-by: jsantiago-eProsima <90755661+jsantiago-eProsima@users.noreply.github.com> Co-authored-by: Javier Santiago <javiersantiago@eprosima.com>
Added delete_contained_entities functionality to DomainParticipant, Publisher, Subscriber and DataReader.