-
Notifications
You must be signed in to change notification settings - Fork 164
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
Conversation
@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. |
src/realm/sync/subscriptions.cpp
Outdated
, 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))) |
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.
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.
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.
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.
src/realm/sync/subscriptions.cpp
Outdated
@@ -429,7 +445,7 @@ SubscriptionSet MutableSubscriptionSet::commit() && | |||
|
|||
std::string SubscriptionSet::to_ext_json() const | |||
{ | |||
if (!m_obj.is_valid()) { | |||
if (!m_subs.empty()) { |
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.
if (!m_subs.empty()) { | |
if (m_subs.empty()) { |
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.
Good catch!
33794bd
to
7ce288a
Compare
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. |
What, How & Why?
This reworks the implementation of
SubscriptionSet
/MutableSubscriptionSet
so thatSubscriptionSet
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 aSubscriptionSet
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 calledrefresh()
on aSuperceded
SubscriptonSet
it would throw aKeyNotFound
error, and now it will properly update the state info.☑️ ToDos