Skip to content

refactor(NODE-4631): change_stream, gridfs to use maybeCallback #3406

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

Merged
merged 12 commits into from
Sep 21, 2022

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Sep 12, 2022

Description

What is changing?

  • Adds maybeCallback helper with tests
  • Changes PromiseProvider to communicate an unset state
  • Refactors:
    • ChangeStream
    • ClientSession
    • GridFS

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: <type>(NODE-xxxx)<!>: <description>
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@nbbeeken nbbeeken marked this pull request as draft September 12, 2022 20:19
@nbbeeken nbbeeken force-pushed the NODE-4631/refactor-change-stream-and-gridfs branch 5 times, most recently from 547b09a to e83ae11 Compare September 12, 2022 22:30
@nbbeeken nbbeeken marked this pull request as ready for review September 13, 2022 15:58
@nbbeeken nbbeeken assigned nbbeeken and unassigned nbbeeken Sep 13, 2022
@nbbeeken nbbeeken added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Sep 13, 2022
@nbbeeken nbbeeken force-pushed the NODE-4631/refactor-change-stream-and-gridfs branch from e83ae11 to 68eba0d Compare September 13, 2022 16:53
Copy link
Contributor

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

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

General comment - I think we should use maybeCallback in cases we don't use maybePromise now, but use the promise provider. We should encapsulate all knowledge of the promise provider into maybeCallback.

@@ -35,7 +35,6 @@ const options: MongoClientOptions = {
promoteBuffers: false,
authMechanism: 'SCRAM-SHA-1',
forceServerObjectId: false,
promiseLibrary: Promise,
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you remove promiseLibrary from these tests? it's deprecated but that shouldn't matter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was setting the promise lib to something other than null, so it had side effects, even though each MongoClient accepts a promiseLib it modifies it for the process globally

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't expect that to cause issues for our ts tests though, because they'll never actually run?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh sorry yea this one doesn't effect anything, the other one is the runtime usage. We have the explicit type test to check that promiseLibrary is deprecated, I think we can remove this from here now which is just a selection of MongoOptions. (one less search and replace)

Copy link
Contributor

Choose a reason for hiding this comment

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

leaving this thread open for context but I consider this resolved

@@ -4,11 +4,11 @@ import { MongoInvalidArgumentError } from './error';
const kPromise = Symbol('promise');

interface PromiseStore {
[kPromise]?: PromiseConstructor;
[kPromise]: PromiseConstructor | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

haven't reviewed this file yet - pending team discussion about breaking changes here

Copy link
Contributor

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

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

most comments addressed/resolved, some questions and suggestions remaining

@@ -35,7 +35,6 @@ const options: MongoClientOptions = {
promoteBuffers: false,
authMechanism: 'SCRAM-SHA-1',
forceServerObjectId: false,
promiseLibrary: Promise,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't expect that to cause issues for our ts tests though, because they'll never actually run?

@@ -35,7 +35,6 @@ const options: MongoClientOptions = {
promoteBuffers: false,
authMechanism: 'SCRAM-SHA-1',
forceServerObjectId: false,
promiseLibrary: Promise,
Copy link
Contributor

Choose a reason for hiding this comment

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

leaving this thread open for context but I consider this resolved

@nbbeeken nbbeeken force-pushed the NODE-4631/refactor-change-stream-and-gridfs branch from a54b2ef to f93126c Compare September 14, 2022 17:23
@nbbeeken nbbeeken changed the base branch from main to NODE-4639/promise-provider September 14, 2022 17:23
Base automatically changed from NODE-4639/promise-provider to main September 15, 2022 13:36
@nbbeeken nbbeeken force-pushed the NODE-4631/refactor-change-stream-and-gridfs branch from a5ad648 to 1643501 Compare September 15, 2022 14:08

if (this.s.executed) {
return handleEarlyError(new MongoBatchReExecutionError(), callback);
// eslint-disable-next-line @typescript-eslint/require-await
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we calling maybePromise twice to handle these errors because executeOperation takes a callback? Why not just promisify execute operation?

maybeCallback(async () => {
  ...
  return promisify(execute_operation)(....)
})

This approach might be preferable as well, because once you make execute_operation return a promise, you won't need to refactor this method much except just to remove the call to promisify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrapping the execOp in maybeCallback (naively, so that's likely why) messes with session allocation because it makes the maybePromise logic run. We can add a note to the refactor exec operation refactor ticket to comeback here, or I can revert the changes here and we can do it altogether.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll tackle this once execute_operation has been refactored

@nbbeeken nbbeeken added the Blocked Blocked on other work label Sep 15, 2022
@nbbeeken nbbeeken added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Sep 16, 2022
@nbbeeken nbbeeken requested a review from dariakp September 16, 2022 17:30
@nbbeeken nbbeeken force-pushed the NODE-4631/refactor-change-stream-and-gridfs branch from 511ddce to 70b8e76 Compare September 16, 2022 19:03
dariakp
dariakp previously approved these changes Sep 16, 2022
@nbbeeken nbbeeken removed the Blocked Blocked on other work label Sep 20, 2022
@nbbeeken nbbeeken force-pushed the NODE-4631/refactor-change-stream-and-gridfs branch from 70b8e76 to bf668c2 Compare September 20, 2022 17:39
@nbbeeken
Copy link
Contributor Author

@baileympearson this is unblocked with the recent release. I've rebased so we can double check we're up to date on changes while we held off on this. (just an FYI no rush at all!)

@baileympearson baileympearson merged commit 8c63447 into main Sep 21, 2022
@baileympearson baileympearson deleted the NODE-4631/refactor-change-stream-and-gridfs branch September 21, 2022 14:26
ZLY201 pushed a commit to ZLY201/node-mongodb-native that referenced this pull request Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants