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

refactor: Move retries finish making createreadstream smaller #1403

Open
wants to merge 19 commits into
base: move-retries-to-google-gax
Choose a base branch
from

Conversation

danieljbruce
Copy link
Contributor

This PR is written to reduce the amount of code in createreadstream so it is easier to work with when moving the retries. Before merging to main we can always revert these changes if we prefer the code to be inline.

Code from createreadstream is pulled out into 3 functions:

  • getRowKeys
  • spliceRanges
  • #readRowsReqOpts

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigtable Issues related to the googleapis/nodejs-bigtable API. labels Apr 22, 2024
Copy link
Contributor Author

@danieljbruce danieljbruce left a comment

Choose a reason for hiding this comment

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

Adding some comments to clearly explain where all the code was moved to.

@@ -37,7 +37,6 @@ export class MockServer {
`localhost:${this.port}`,
grpc.ServerCredentials.createInsecure(),
() => {
server.start();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As stated before. start is deprecated for grpc servers.

src/table.ts Show resolved Hide resolved
src/table.ts Show resolved Hide resolved
src/table.ts Show resolved Hide resolved
src/table.ts Show resolved Hide resolved
src/table.ts Show resolved Hide resolved
@@ -2049,7 +2016,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
* that a callback is omitted.
*/
promisifyAll(Table, {
exclude: ['family', 'row'],
exclude: ['family', 'row', '#readRowsReqOpts'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes it so our new helper function #readRowsReqOpts works as a normal function and doesn't return a promise.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine for now, but depending on what we decide on for this eventually, I want to leave this comment open in case we need to change it later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we pull #readRowsReqOpts out of this class like populateAttemptHeader then we don't need this anymore and since modifying this exclude variable is not preferred, I think this is a good argument for the change you suggested above which is pulling #readRowsReqOpts out of this class like populateAttemptHeader.

@danieljbruce danieljbruce changed the title Move retries finish making createreadstream smaller refactor: Move retries finish making createreadstream smaller Apr 22, 2024
@danieljbruce danieljbruce marked this pull request as ready for review April 22, 2024 15:02
@danieljbruce danieljbruce requested review from a team as code owners April 22, 2024 15:02
Copy link
Contributor

@leahecole leahecole left a comment

Choose a reason for hiding this comment

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

just a couple of nits!

src/table.ts Show resolved Hide resolved
src/table.ts Outdated
if (filter) {
reqOpts.filter = filter;
}
const reqOpts: any = this.#readRowsReqOpts(ranges, rowKeys, options);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please address this any!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this change.

@@ -1640,6 +1576,40 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
makeNextBatchRequest();
}

#readRowsReqOpts(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit that I'm surprised our linter didn't catch - I think you shouldn't use #private notation per our ts style guide. Does this helper function for sure need to be private? (It might - I just want to know more about your thought process! 😁 )

Copy link
Contributor

Choose a reason for hiding this comment

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

Additional question - does this need to stay within the table class, or could it be a helper function similar to populateAttemptHeader down below? Tell me more! 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think doing what populateAttemptHeader does is a good option. The con is that the function also needs to be able to accept table so needs a fourth argument. The pro is that we don't have to have private ECMA script function syntax that is hard to debug. It's a good suggestion overall that I was wondering about.

We definitely should hide this function from the user either way.

@@ -2049,7 +2016,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
* that a callback is omitted.
*/
promisifyAll(Table, {
exclude: ['family', 'row'],
exclude: ['family', 'row', '#readRowsReqOpts'],
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine for now, but depending on what we decide on for this eventually, I want to leave this comment open in case we need to change it later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the googleapis/nodejs-bigtable API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants