-
Notifications
You must be signed in to change notification settings - Fork 171
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
Fix support for ReadOnly ThreadSafeReferences #4517
Conversation
…nsaction_version().
…nsaction version.
The title of this PR should be in the imperative: |
It is difficult to find the actual change here in the giant mess of unrelated pointless renamings, but I think it's incorrect. The entire concept of a readlock or version does not apply to a read-only Realm, and it doesn't make any sense to add them to Group. |
b2d7deb
to
c246636
Compare
c246636
to
e0bb952
Compare
e0bb952
to
37b2345
Compare
Issue was continued and fixed by @finnschiermer in #4688. |
Fix for realm/realm-swift#5475.
What, How & Why?
Problem
This issue is caused by two checks interfering with each other:
realm-core/src/realm/object-store/thread_safe_reference.cpp
Lines 38 to 46 in b64aa00
realm-core/src/realm/object-store/shared_realm.cpp
Lines 490 to 495 in b64aa00
Within a
ThreadSafeReference
weduplicate()
therealm
if itis_in_read_transaction()
which it is since the check looks like this:realm-core/src/realm/object-store/shared_realm.hpp
Lines 313 to 316 in b64aa00
The then executed path of
duplicate()
which needs toget_version_of_current_transaction()
tries toverify_can_create_any_transaction
which subsequently crashes because we"Can't perform transactions on read-only Realms."
.Solution
ReadLockInfo
andget_current_version()
toGroup
so that we can read a version for a (read-only)Group
as wellread_transaction_version()
was split intoget_current_version()
in general andget_version_of_current_or_frozen_transaction()
specifically to account for that changeis_in_any_transaction()
was adjusted to match the test in the more specificis_in_write_transaction()
With these preparations we can then make the two resolving changes:
realm-core/src/realm/object-store/shared_realm.cpp
Lines 103 to 115 in fbc94bf
SharedRealm
correctly inrealm-core/src/realm/object-store/thread_safe_reference.cpp
Lines 45 to 46 in fbc94bf
☑️ ToDos
Notes
I was encouraged to change names when unclear and add comments, etc.
The changes I've made happened while creating this PR and helped me understanding those parts of the core better and eventually led to the solution but are not necessarily part of it. I'm happy to divide them into two PRs if preferred.
Open questions
realm-core/src/realm/object-store/collection.cpp
Lines 59 to 67 in fbc94bf
Why can a
List
,Set
orDictionary
not be valid on a read-only realm?is_valid()
function?