-
Notifications
You must be signed in to change notification settings - Fork 37
Conversation
realm-java has a different semantics of read-only mode. In realm-java, there is no limitation that the read-only Realm won't be changed by sync or by the other process. realm-java only has a restriction that user cannot apply write transactions on the read-only Realm instance.
src/shared_realm.hpp
Outdated
// mode, sync Realm can be opened with ReadOnlyAlternative mode. Changes | ||
// can be made to the Realm file through another writable Realm instance. | ||
// Thus, notifications are also allowed in this mode. | ||
ReadOnlyAlternative, |
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.
This name feels slightly awkward, would it make sense to talk about ReadOnlyStrict
instead?
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.
I spent an hour to come with this name ... actually i feel the original ReadOnly
is more strict than this one since it doesn't even allow advance_read
. I am open for other better names :P
We've previously called this things like "soft read-only" since it opens the file in read-write mode and just doesn't allow making changes, but that name is awkward too. We probably should just rename the existing read-only mode to something like |
And ReadOnlyAlternative has been renamed to ReadOnly.
The problem with renaming |
@bdash Is |
|
to avoid bindings mis-choose a wrong schema mode without any compile errors.
src/shared_realm.hpp
Outdated
@@ -188,7 +192,7 @@ class Realm : public std::enable_shared_from_this<Realm> { | |||
ShouldCompactOnLaunchFunction should_compact_on_launch_function; | |||
|
|||
bool immutable() const { return schema_mode == SchemaMode::Immutable; } | |||
bool read_only() const { return schema_mode == SchemaMode::ReadOnly; } | |||
bool read_only() const { return schema_mode == SchemaMode::ReadOnlyAlternative; } |
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.
There's a similar issue with this being named read_only()
, since any existing calls to this really should be changed to immutable()
to preserve the existing semantics.
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.
Uh, right! forgot this one!
src/object_store.cpp
Outdated
struct Verifier : SchemaDifferenceExplainer { | ||
using SchemaDifferenceExplainer::operator(); | ||
|
||
void operator()(RemoveProperty) { } |
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.
Is it intentional that AddTable
/ AddInitialProperties
are not handled here like they are for immutable mode? If I understand correctly, that will result in an error if the local schema contains any classes that aren't present in the file being opened. That would appear to preclude opening a synced Realm that doesn't already exist locally using this new read-only mode, since we'll think the schema isn't compatible until after the Realm has been downloaded.
With the immutable schema mode, missing tables are simply treated as if they were empty. That seems like it should also work for this mode.
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.
Yes it is... That is the current realm-java's behavior. I have a discussion with @cmelchior before, we think it is better to keep this since it makes less sense to return an empty results when user query on a non-existing table than just throw earlier.
That would appear to preclude opening a synced Realm that doesn't already exist locally using this new read-only mode, since we'll think the schema isn't compatible until after the Realm has been downloaded.
This is handled in another way in java, open a dynamic realm, download changes, then open the typed realm. See https://github.com/realm/realm-java/blob/master/realm/realm-library/src/main/java/io/realm/RealmCache.java#L310
How does cocoa handle this? If we can unify this implementation in object store, it would be great.
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.
Yes it is... That is the current realm-java's behavior. I have a discussion with @cmelchior before, we think it is better to keep this since it makes less sense to return an empty results when user query on a non-existing table than just throw earlier.
What's the argument for this behaving differently than the immutable mode? It's not clear to me why this mode should throw if the app's schema contains classes not present in the Realm when immutable mode doesn't.
This is handled in another way in java, open a dynamic realm, download changes, then open the typed realm.
Sure, that's roughly how Cocoa implements its equivalent of "wait for initial remote data" as well. But what about using this schema mode without having to wait for all remote changes to be downloaded? Requiring that the set of classes in the schema match prevents using it for this. See realm/realm-swift#5186 for a scenario where this would be useful.
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.
What's the argument for this behaving differently than the immutable mode? It's not clear to me why this mode should throw if the app's schema contains classes not present in the Realm when immutable mode doesn't.
No argument for that actually. It is simply because of java wants to keep current behaviour to throw earlier.
Sure, that's roughly how Cocoa implements its equivalent of "wait for initial remote data" as well. But what about using this schema mode without having to wait for all remote changes to be downloaded? Requiring that the set of classes in the schema match prevents using it for this. See realm/realm-swift#5186 for a scenario where this would be useful.
Yeah, that is the valid case that the schema validation should not throw. @cmelchior Any comments?
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.
So what is the conclusion to solve this? Shall we have two modes ReadonlyAlternative
and ReadonlyStrict
where the ReadonlyStrict
will throw if the schema doesn't match?
The reason is two-fold:
|
Note that I'm taking from a Java context, so if we lifted the restriction on Except that you would then run into problems if the Realm downloaded from the server didn't match the schema. Then the Realm would already be open and you would have nowhere sensible to throw (except perhaps the Session ErrorHandler, which would also be a bit weird). |
I don’t agree. I don’t think it’s realistic to have an app where UI may never appear. I agree that currently showing an indeterminate spinner is less than ideal, but eventually we’ll provide a callback with downloaded/downloadable bytes to allow people to show proper loading bars. Note that asyncOpen is not necessarily called when downloading the realm for the first time - it’s perfectly reasonable for a user to have downloaded the majority (even all) of the content of the Realm on a previous run, so being unable to open it and show the existing content is a major architectural flaw. |
realm-java has a different semantics of read-only mode. In realm-java,
there is no limitation that the read-only Realm won't be changed by
sync or by the other process. realm-java only has a restriction that
user cannot apply write transactions on the read-only Realm instance.