Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

refactor: Unify precondition retry logic#1660

Merged
danielbankhead merged 5 commits into
mainfrom
unify-retry-logic
Oct 18, 2021
Merged

refactor: Unify precondition retry logic#1660
danielbankhead merged 5 commits into
mainfrom
unify-retry-logic

Conversation

@danielbankhead

Copy link
Copy Markdown
Contributor

No description provided.

@product-auto-label product-auto-label Bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Oct 13, 2021
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 13, 2021
Comment thread src/file.ts Outdated
* - if precondition option `ifGenerationMatch` is not set OR
* - if `idempotencyStrategy` is set to `RetryNever`
*/
private shouldRetry(options: RetryOptions): boolean {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe work into the title that this is in regards to precondition stuff? we already have another function similarly named for error code retry logic

Comment thread src/file.ts Outdated
preconditionOpts?: PreconditionOptions;
}

export interface RetryOptions {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think this is also misnamed. is this interface needed? can the shouldRetry function take in PreconditionOptions directly?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can see the value in splitting out this interface if we were going to be doing the etag work soon but for the moment I would agree with Sameena that shouldRetry can probably just take PreconditionOptions directly.

@danielbankhead danielbankhead changed the title refactor: Unify retry logic refactor: Unify precondition retry logic Oct 13, 2021
Comment thread src/file.ts Outdated
this.storage.retryOptions.idempotencyStrategy ===
IdempotencyStrategy.RetryNever
) {
if (!this.shouldRetryRequest(options.preconditionOpts)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

will this throw if options is undefined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

options is defined on line 1035

Comment thread src/file.ts Outdated
* - if precondition option `ifGenerationMatch` is not set OR
* - if `idempotencyStrategy` is set to `RetryNever`
*/
private shouldRetryRequest(options?: PreconditionOptions): boolean {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you please rename to shouldRetryBasedOnPreconditionAndIdempotencyStrat or maybe something less long but still descriptive? we already have too many functions that effectively decide shouldRetryRequest

  1. in common: https://github.com/googleapis/nodejs-common/blob/6d239d3b8c58c1e00571135e1e715e4c5cd8c2a3/src/util.ts#L545
  2. in storage:
    const RETRYABLE_ERR_FN_DEFAULT = function (err?: ApiError) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure

Comment thread src/file.ts
* A helper method for determining if a request should be retried based on preconditions
*
* A request should not be retried under the following conditions:
* - if precondition option `ifGenerationMatch` is not set OR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, this should only be used for methods where the idempotency is determined by ifGenerationMatch, not for ones where metageneration is used-- is that correct? If so we should make that clear.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point - I'll make a note. Perhaps we can extend the function when we require IfMetagenerationMatch checking in this class.

Refs:

We can extend the function when we require `IfMetagenerationMatch` checking in this class
@shaffeeullah shaffeeullah self-requested a review October 18, 2021 16:18
@danielbankhead danielbankhead merged commit 746420e into main Oct 18, 2021
@danielbankhead danielbankhead deleted the unify-retry-logic branch October 18, 2021 16:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: storage Issues related to the googleapis/nodejs-storage API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants