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

Add support for compensating writes #5599

Merged
merged 22 commits into from
Mar 23, 2023
Merged

Add support for compensating writes #5599

merged 22 commits into from
Mar 23, 2023

Conversation

papafe
Copy link
Contributor

@papafe papafe commented Mar 21, 2023

This PR adds a new error class for compensating writes errors.

☑️ ToDos

  • 📝 Changelog entry
  • 🚦 Tests

@papafe papafe marked this pull request as ready for review March 21, 2023 11:59
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 have a few comments and suggestions.

packages/realm/src/errors.ts Outdated Show resolved Hide resolved
packages/realm/src/errors.ts Outdated Show resolved Hide resolved
packages/realm/src/errors.ts Outdated Show resolved Hide resolved
packages/realm/src/errors.ts Outdated Show resolved Hide resolved
integration-tests/tests/src/tests/sync/flexible.ts Outdated Show resolved Hide resolved
integration-tests/tests/src/tests/sync/flexible.ts Outdated Show resolved Hide resolved
integration-tests/tests/src/tests/sync/flexible.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@kneth kneth left a comment

Choose a reason for hiding this comment

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

I have added a couple of suggestions, and they shouldn't block you in any way. Great to see compensating writes coming to a SDK near me 😄

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
packages/realm/src/errors.ts Show resolved Hide resolved
packages/realm/src/Types.ts Outdated Show resolved Hide resolved
papafe and others added 5 commits March 22, 2023 08:50
* main:
  Add steps for prerequisites for running MDB aggregation tests. (#5475)
  Remove dependencies.list (#5598)
  Removed dependency on bare "mocha-remote" package.
  Making prebuild-install --verbose
  Bundle on CI (#5570)
  Fix example (#5534)
  Import device-info platform module to React Native bundle (#5594)
  Chang order of PATH segments, fixing the BaaS test server
  Download the assisted_agg binary (#5592)
Copy link
Contributor

@elle-j elle-j left a comment

Choose a reason for hiding this comment

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

Great and thanks 🙏 Added suggestions 👍

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
packages/realm/src/Types.ts Outdated Show resolved Hide resolved
packages/realm/src/errors.ts Outdated Show resolved Hide resolved
packages/realm/src/errors.ts Outdated Show resolved Hide resolved
packages/realm/src/errors.ts Outdated Show resolved Hide resolved
packages/realm/src/errors.ts Outdated Show resolved Hide resolved
packages/realm/src/errors.ts Outdated Show resolved Hide resolved
packages/realm/src/errors.ts Outdated Show resolved Hide resolved
integration-tests/tests/src/tests/sync/flexible.ts Outdated Show resolved Hide resolved
Copy link
Member

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

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

This is not a problem with this PR, but it looks like we don't expose the log url in the sync error. We should probably do it as the server logs are quite useful to understand what exactly is failing.

packages/realm/src/errors.ts Outdated Show resolved Hide resolved
integration-tests/tests/src/tests/sync/flexible.ts Outdated Show resolved Hide resolved
realm.create<IDog>(DogSchema.name, { _id: new BSON.ObjectId(), name: "Oldy", age: 6, owner: luigi });
});

await realm?.syncSession?.uploadAllLocalChanges();
Copy link
Member

Choose a reason for hiding this comment

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

Why?all?these?question?marks? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're fun to use 😁

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it should only be needed after syncSession.

Copy link
Contributor

@takameyer takameyer Mar 22, 2023

Choose a reason for hiding this comment

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

Optional chaining! It replaces this code:

if( realm && realm.syncSession && realm.syncSession.uploadAllLocalChanges){
  await realm.syncSession.uploadAllLocalChanges();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

But maybe we don't even need them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, just the second one, I think it's fine :)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need either one. If the syncSession is undefined/null, I'd rather that this throws than silently does nothing.

Copy link
Contributor

Choose a reason for hiding this comment

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

TypeScript will be defensive about this and have a type error if you do not have a check.

Copy link
Member

@nirinchev nirinchev Mar 22, 2023

Choose a reason for hiding this comment

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

Wait, why is Realm.syncSession nullable but Realm.subscriptions not? In any case, this should use ! then to express that we know this is not null.

Copy link
Contributor

Choose a reason for hiding this comment

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

My guess is that subscriptions can just return an empty array, even if sync isn't enabled. syncSession should return null if sync isn't configured

* main:
  Prepare for vNext
  Fixed extraction of version in publish workflow
  Prepare for 12.0.0-alpha.0 (#5600)
  Remove redundant MongoDBCollection watch tests.

# Conflicts:
#	CHANGELOG.md
@papafe
Copy link
Contributor Author

papafe commented Mar 22, 2023

@elle-j @kraenhansen @takameyer @kneth
I've just tried to follow all your recommendations so it'll be great if you could give a final (?) look:

  • The final name for the array property is writes, I hope we can all agree with that in some way 😁
  • I'm using promiseHandle for the test, instead of that horrible promise with async body
  • I've changed the type of the primary key from Mixed to PrimaryKey and added an assert method to verify it's of the correct type

@takameyer
Copy link
Contributor

:shipit: ShipIt

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.

There's just one thing missing 😬

@papafe papafe merged commit 9f8b6d8 into main Mar 23, 2023
@papafe papafe deleted the fp/compensating-writes branch March 23, 2023 09:14
@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.

6 participants