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

SubscriptionSet should not hold any database resources #5150

Merged
merged 6 commits into from
Jan 10, 2022

Conversation

jbreams
Copy link
Contributor

@jbreams jbreams commented Jan 10, 2022

What, How & Why?

This reworks the implementation of SubscriptionSet/MutableSubscriptionSet so that SubscriptionSet does not actually hold on to any database resources and we can avoid pinning old versions of the database if a user holds on to a SubscriptionSet for a long time.

This simplified a bunch of things - like we don't need to maintain our own iterator implementation anymore, we can just re-use std::vector's iterators. But it also made the commit method do actual serialization work in addition to just committing.

This also lets us handle the Superceded state a little more gracefully. Before, if you called refresh() on a Superceded SubscriptonSet it would throw a KeyNotFound error, and now it will properly update the state info.

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)

@cla-bot cla-bot bot added the cla: yes label Jan 10, 2022
@jbreams
Copy link
Contributor Author

jbreams commented Jan 10, 2022

@nirinchev, this draft PR is something I had stashed away for making SubscriptionSets not hold any database resources. MutableSubscriptionSets still need to hold on to a write transaction and an Obj, but the immutable SubscriptionSet can just be plain old data.

@jbreams jbreams requested a review from ironage January 10, 2022 16:31
@jbreams jbreams marked this pull request as ready for review January 10, 2022 16:31
@jbreams jbreams linked an issue Jan 10, 2022 that may be closed by this pull request
Comment on lines 58 to 60
, m_name(static_cast<std::string_view>(obj.get<StringData>(parent->m_sub_keys->name)))
, m_object_class_name(static_cast<std::string_view>(obj.get<StringData>(parent->m_sub_keys->object_class_name)))
, m_query_string(static_cast<std::string_view>(obj.get<StringData>(parent->m_sub_keys->query_str)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the static cast to string_view here? Reading this before the hpp file changes, I thought these members were string_views, which would be wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, you're right. I wasn't sure what the obj.get would actually do. It looks like it will call the std::string conversion operator to convert to a std::string which is the new type of these members.

@@ -429,7 +445,7 @@ SubscriptionSet MutableSubscriptionSet::commit() &&

std::string SubscriptionSet::to_ext_json() const
{
if (!m_obj.is_valid()) {
if (!m_subs.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!m_subs.empty()) {
if (m_subs.empty()) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

@jbreams
Copy link
Contributor Author

jbreams commented Jan 10, 2022

For posterity's sake: I ran the FLX evergreen tests with the known-to-fail client reset tests disabled here https://spruce.mongodb.com/version/61dc97640ae6060efde64d1e/tasks and they passed just fine.

@jbreams jbreams merged commit 592d305 into master Jan 10, 2022
@jbreams jbreams deleted the jbr/inmemory_sub_sets branch January 10, 2022 22:36
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SubscriptionSets should not hold any database resources
2 participants