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

[12552] delete_contained_entities implementation #2223

Merged
merged 8 commits into from
Oct 6, 2021

Conversation

jsan-rt
Copy link
Contributor

@jsan-rt jsan-rt commented Sep 23, 2021

Added delete_contained_entities functionality to DomainParticipant, Publisher, Subscriber and DataReader.

…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>
@jsan-rt jsan-rt marked this pull request as ready for review September 30, 2021 08:36
…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>
Comment on lines 638 to 641
std::vector<DataReader*> reader_vector;
get_datareaders(reader_vector);

std::lock_guard<std::mutex> lock(mtx_readers_);
Copy link
Contributor

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

Suggested change
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.

Comment on lines 642 to 649
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;
}
}
Copy link
Contributor

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

Suggested change
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;
}
}

Comment on lines 685 to 689
return_status = return_status && dr->can_be_deleted();
if (!return_status)
{
return return_status;
}
Copy link
Contributor

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

Suggested change
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;
}

Comment on lines 584 to 585
//std::vector<DataWriter*> writer_vector;
//get_datawriters(writer_vector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code

Comment on lines 601 to 609
/* 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;
}
}*/
Copy link
Contributor

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();
Copy link
Contributor

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();
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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()
Copy link
Contributor

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>
Comment on lines 542 to 543
//std::vector<DataWriter*> writer_vector;
//get_datawriters(writer_vector);
Copy link
Contributor

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>
Copy link
Contributor

@IkerLuengo IkerLuengo left a 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

@MiguelCompany MiguelCompany merged commit af0ff68 into master Oct 6, 2021
@MiguelCompany MiguelCompany deleted the feature/delete_contained_entities branch October 6, 2021 13:51
@MiguelCompany
Copy link
Member

@Mergifyio backport 2.3.x

mergify bot pushed a commit that referenced this pull request Nov 22, 2021
* 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
@mergify
Copy link
Contributor

mergify bot commented Nov 22, 2021

backport 2.3.x

✅ Backports have been created

jsan-rt added a commit that referenced this pull request Apr 22, 2022
* 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)
MiguelCompany pushed a commit that referenced this pull request Jul 15, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants