-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(NODE-4125): change stream resumability #3289
Conversation
19ebf83
to
63f77b6
Compare
- adds resumability tests for the iterator based API (tryNext, hasNext and next) - adds resumability tests for the event emitter-based API - adds tests demonstrating that change streams do not resume on unresumable errors for iterator and event emitter based apis - adds tests for resumability iterator mode on 3.6 servers - adds resume options tests to resumability tests
This commit removes a custom function we had to wait until the topology was reconnected in favor of performing server selection. This is described here: https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst#resume-process
63f77b6
to
d57f78a
Compare
tryNext is not blocking and on sharded clusters we don't have control of when the actual change event will be ready on the change stream pipeline. This introduces a race condition, where sometimes we receive the change event and sometimes we don't when we call tryNext, depending on the timing of the sharded cluster. Since we really only care about the resumability, it's enough for this test to throw if tryNext ever throws and assert on the number of aggregate events.
d57f78a
to
28e1b77
Compare
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 removed all the if this.cursor
checks on this PR and made this.cursor?
lines just this.cursor
and all change stream integration tests passed. Just want to make sure that's expected and that extra code could be removed (since we always have a cursor it seems). Would you like me to just push my changes to the branch or am I missing something where the cursor would not be there?
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.
The refactor away from the resume queue is so much easier to understand. Nice work. Just the one nit left after the changes.
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.
LGTM - Thanks!
- removes MongoClient.connect() call from new change stream tests - awaits a promise in iterateUntilDocumentOrError in the unified runner - removes an unused method in the change stream class
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.
the changes addressing my comments look good to me, I just have a suggestion on one of the tests
- use to.be.a('number') in assertion - remove bracket style type assertion in favor of as
…ing" This reverts commit 50980b8.
This PR address resumability issues in the iterator-based API for change streams.
As much as I tried to separate the refactor from the code changes, I ended up making a few refactors as a part of this PR.
maybePromise
wrapper and the IIFE, and we should have the async functionality we need already written for us.Relevant Commits
8820ea1 is the most important commit in this PR, as it actually fixes the resumability for iterator mode.
94a4853 makes a drive-by fix to remove an internal function in favor of server selection in the resume process.
Note
As it turns out, the stream based change stream API has never been resumable. I can file a follow up ticket to make our stream resumable, if we want to, but it seemed out of scope for this bug fix work.
Double check the following
npm run check:lint
script<type>(NODE-xxxx)<!>: <description>