-
Notifications
You must be signed in to change notification settings - Fork 149
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
feat: retry BatchGetDocuments RPCs that fail with errors #1544
Conversation
8baf0a9
to
207d054
Compare
207d054
to
a04a119
Compare
dev/src/document-reader.ts
Outdated
* as part of a transaction. | ||
* | ||
* @param firestore The Firestore instance to use. | ||
* @param allDocuments The documents to receive. |
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.
documents to *get?
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.
Done
dev/src/document-reader.ts
Outdated
/** An optional transaction ID to use for this read. */ | ||
transactionId?: Uint8Array; | ||
|
||
private remainingDocuments = new Set<string>(); |
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.
nit: something more specific like unfetchedDocuments or requestedDocuments?
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.
Renamed to outstandingDocuments. Pretty outstanding, me thinks.
* | ||
* @param requestTag A unique client-assigned identifier for this request. | ||
*/ | ||
async get(requestTag: string): Promise<Array<DocumentSnapshot<T>>> { |
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.
If get() is only meant to be run once, the method should throw an error if it is run again
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.
It is only meant to be run once, but it should work if run multiple times. It will return the same result without doing any work.
dev/src/document-reader.ts
Outdated
} | ||
|
||
const path = document.ref.formattedName; | ||
this.remainingDocuments.delete(path); |
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.
optional: add assert() to check that path is in the set.
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.
Skipped for now.
dev/src/document-reader.ts
Outdated
); | ||
throw err; | ||
} else { | ||
logger( |
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.
Is the maximum number of retries allowed capped?
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.
No, I thought it would be better not to. But then I changed my mind. I rewrote this logic to only fetch more results if we made some progress, which should ensure that we never end up in a loop with just errors. This also removes the need to add backoff, which I otherwise should have done.
FYI - This rewrite was pretty complicated, so I ended up changing the implementation to use async iterators. I did this in steps in case you want to see more reasonable diffs.
7ee61e8
to
3634fd6
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.
lgtm
dev/src/document-reader.ts
Outdated
private retrievedDocuments = new Map<string, DocumentSnapshot>(); | ||
|
||
/** | ||
* Internal method to retrieve multiple documents from Firestore, optionally |
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.
nit: it seems weird to call the constructor an "internal method". Move this comment elsewhere?
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.
Oh, that's an old comment. Updated.
🤖 I have created a release \*beep\* \*boop\* --- ## [4.13.0](https://www.github.com/googleapis/nodejs-firestore/compare/v4.12.3...v4.13.0) (2021-06-29) ### Features * add read-only transactions ([#1541](https://www.github.com/googleapis/nodejs-firestore/issues/1541)) ([ca4241e](https://www.github.com/googleapis/nodejs-firestore/commit/ca4241eb3ee4abb8453b6da0911397187dc18dde)) * retry BatchGetDocuments RPCs that fail with errors ([#1544](https://www.github.com/googleapis/nodejs-firestore/issues/1544)) ([b39dd3c](https://www.github.com/googleapis/nodejs-firestore/commit/b39dd3c65549fb1a651c1722d8ea2c038e152417)) ### Bug Fixes * **deps:** google-gax v2.17.0 with mTLS ([#1546](https://www.github.com/googleapis/nodejs-firestore/issues/1546)) ([a322345](https://www.github.com/googleapis/nodejs-firestore/commit/a32234510d487982b950c88575b9425c531c2d94)) * make request optional in all cases ([#1536](https://www.github.com/googleapis/nodejs-firestore/issues/1536)) ([f6edfc1](https://www.github.com/googleapis/nodejs-firestore/commit/f6edfc181ca39cd307eab6d141db08f377d5cfdf)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
This PR moves the existing logic for Firestore.getAll() to a new class and adds a new retry mechanism that is similar to the current Query RPC retry.
Fixes #1387