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

Client reset w/recovery #4711

Merged
merged 31 commits into from Oct 31, 2022
Merged

Client reset w/recovery #4711

merged 31 commits into from Oct 31, 2022

Conversation

kneth
Copy link
Member

@kneth kneth commented Jul 8, 2022

What, How & Why?

This closes #4135

☑️ ToDos

  • 📝 Changelog entry
  • 📝 Compatibility label is updated or copied from previous entry
  • 🚦 Tests
  • 🔀 Executed flexible sync tests locally if modifying flexible sync
  • 📦 Updated internal package version in consuming package.jsons (if updating internal packages)
  • 📱 Check the React Native/other sample apps work if necessary
  • 📝 Public documentation PR created or is not necessary
  • 💥 Breaking label has been applied or is not necessary

If this PR adds or changes public API's:

  • typescript definitions file is updated
  • jsdoc files updated
  • [ ] Chrome debug API is updated if API is available on React Native

@cla-bot cla-bot bot added the cla: yes label Jul 8, 2022
@kneth kneth self-assigned this Jul 8, 2022
@kneth kneth force-pushed the feature/client-reset-recovery branch from 2a4c222 to a5371ce Compare August 4, 2022 15:32
@kneth kneth force-pushed the feature/client-reset-recovery branch from 4a73a46 to dff7204 Compare September 22, 2022 11:48
@kneth kneth force-pushed the feature/client-reset-recovery branch from 1b0b9f1 to 2b93d65 Compare October 1, 2022 08:01
@kneth kneth force-pushed the feature/client-reset-recovery branch from 7219b78 to e753044 Compare October 12, 2022 07:11
@kneth kneth marked this pull request as ready for review October 13, 2022 13:36
types/index.d.ts Outdated
Comment on lines 152 to 155
enum ClientResetDidRecover {
Yes = 'yes',
No = 'no'
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this not just a simple boolean?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would allow for latter adding "perhaps - not entirely sure" 🤷

Copy link
Member

Choose a reason for hiding this comment

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

undefined would be a great way to express that in that theoretical future.

I suggest making this a boolean for now if we're not certain that new values will be added soon.

Alternatively I'd suggest using values that are closer to semantics:

Suggested change
enum ClientResetDidRecover {
Yes = 'yes',
No = 'no'
}
enum ClientResetOutcome {
Recovered = 'recovered',
Discarded = 'discarded'
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Another alternative (implemented in other SDKs) is to provide a third callback (similar to the callback for manual mode) which is called when recovery is not possible - or when an error occurs.

src/js_sync.hpp Outdated
arguments[0] = create_object<T, RealmClass<T>>(m_ctx, new SharedRealm(before_realm));
arguments[1] = create_object<T, RealmClass<T>>(m_ctx, new SharedRealm(after_realm));
if (!m_ignore_recover) {
arguments[2] = Value<T>::from_string(m_ctx, did_recover ? "yes" : "no");
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest this should simply be a boolean in the user-facing API.

Copy link
Member Author

Choose a reason for hiding this comment

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

An enum is specified in the technical design and will align better with other SDKs

types/index.d.ts Outdated
Comment on lines 159 to 160
type ClientResetAfterCallback = (localRealm: Realm, remoteRealm: Realm) => void;
interface ClientResetConfiguration<ClientResetModeT = ClientResetMode> {
mode: ClientResetModeT;
clientResetBefore?: ClientResetBeforeCallback;
clientResetAfter?: ClientResetAfterCallback;
type ClientResetAfterRecoveryCallback = (localRealm: Realm, remoteRealm: Realm, didRecover: ClientResetDidRecover) => void;
Copy link
Member

Choose a reason for hiding this comment

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

Could we merge the ClientResetAfterCallback and ClientResetAfterRecoveryCallback if we provided false as default value for didRecover?

Copy link
Member Author

Choose a reason for hiding this comment

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

didRecover is something the sync client sets. Moreover, I want to express that didRecover do not make sense in all cases.

Copy link
Member

Choose a reason for hiding this comment

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

I think it should simply call this with false if it couldn't happen. Users providing this callback can simply choose not to read that third argument. I believe the complexity added doesn't outweigh the benefits here.

@kneth kneth changed the base branch from master to v10 October 18, 2022 12:03
@@ -1330,7 +1213,7 @@ module.exports = {

13) synced, unencrypted Realm -> synced, unencrypted Realm
14) synced, unencrypted Realm -> synced, encrypted Realm
15) synced, encrypted Realm -> synced, unencrypted Realm
15) synced, encrypted Realm -> synced, unencrypted Relam
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
15) synced, encrypted Realm -> synced, unencrypted Relam
15) synced, encrypted Realm -> synced, unencrypted Realm

@@ -361,7 +361,7 @@ module.exports = {
const credentials = Realm.Credentials.anonymous();
return app.logIn(credentials).then((user) => {
return new Promise((resolve, _reject) => {
const config = getSyncConfiguration(user, partition);
let config = getSyncConfiguration(user, partition);
Copy link
Member

Choose a reason for hiding this comment

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

Seem like an unneeded change to me.

Copy link
Member

@kraenhansen kraenhansen left a comment

Choose a reason for hiding this comment

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

I think this API makes more sense 👍

Comment on lines 469 to +472
Manual: "manual",
DiscardLocal: "discardLocal",
DiscardUnsyncedChanges: "discardUnsyncedChanges",
RecoverUnsyncedChanges: "recoverUnsyncedChanges",
RecoverOrDiscardUnsyncedChanges: "recoverOrDiscardUnsyncedChanges",
Copy link
Member

Choose a reason for hiding this comment

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

This is missing: DiscardLocal = 'discardLocal'

@kneth kneth force-pushed the feature/client-reset-recovery branch from e845294 to ee75117 Compare October 25, 2022 13:39
@kneth kneth force-pushed the feature/client-reset-recovery branch from 6c6603e to e28658a Compare October 26, 2022 06:42
@kneth kneth merged commit a54c953 into v10 Oct 31, 2022
@kneth kneth deleted the feature/client-reset-recovery branch October 31, 2022 10:02
kneth added a commit that referenced this pull request Nov 1, 2022
* Add new client reset modes
* Expand manual mode
Co-authored-by: Kræn Hansen <kraen.hansen@mongodb.com>
kneth added a commit that referenced this pull request Nov 1, 2022
* Add new client reset modes
* Expand manual mode
Co-authored-by: Kræn Hansen <kraen.hansen@mongodb.com>
@@ -438,13 +612,6 @@ void SessionClass<T>::get_config(ContextType ctx, ObjectType object, ReturnValue
Value::from_string(ctx, String::from_bson(partition_value_bson)));
}

auto conf = session->config();
Copy link
Contributor

Choose a reason for hiding this comment

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

@kneth What was the reasoning of removing error from the returned sync configuration?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 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.

Implement Client Reset w/ Recovery
4 participants