Skip to content

chore(retry): refactor RetryAlgorithmManager to simplify candidate public api#1108

Merged
BenWhitehead merged 3 commits intogoogleapis:mainfrom
BenWhitehead:ram-refactor
Oct 20, 2021
Merged

chore(retry): refactor RetryAlgorithmManager to simplify candidate public api#1108
BenWhitehead merged 3 commits intogoogleapis:mainfrom
BenWhitehead:ram-refactor

Conversation

@BenWhitehead
Copy link
Copy Markdown
Collaborator

@BenWhitehead BenWhitehead commented Oct 14, 2021

part 1

  • Remove separate idempotent handling for resumable uploads
  • Introduce new StorageExceptionHandlerFactory which provides a handle to get exception handlers for idempotent and nonidempotent handlers
  • Move existing ExceptionHandler implementations to DefaultStorageExceptionHandlerFactory
  • Refactor StorageOptions to use new StorageExceptionHandlerFactory
  • Make RetryAlgorithmManager a concrete class implemented in terms of the provided StorageExceptionHandlerFactory rather than an interface
  • Remove LegacyRetryAlgorithmManager
  • Remove NewRetryAlgorithmManager

part 2

  • following the precedent set by node use the term strategy for retry selection compared to the generic factory as before
  • Change retry types from ExceptionHandler to ResultRetryAlgorithm. ExceptionHandler is a subclass of ResultRetryAlgorithm, but this provides us binary compatability moving forward if we ever need to provide an implementation which isn't based on ExceptionHandler.
  • Remove LegacyStorageExceptionHandlerFactory and replace it with UniformStorageRetryStrategy. Allowing for a single algorithm to be specified and used for both idempotent and non-idempotent cases.
  • Rename StorageExceptionHandlerFactory to StorageRetryStrategy
  • Move access of strategy implementations to static method on StorageRetryStrategy.java
  • Add new getUniformStorageRetryStrategy() which provides a strategy which will use the idempotent algorithm for both cases.
  • Add javadocs with explanations about the strategies and their behaviors
  • Add serialVersionUID to each of the new classes which are Serializable

…blic api

* Remove separate idempotent handling for resumable uploads
* Introduce new StorageExceptionHandlerFactory which provides a handle to get exception handlers for idempotent and nonidempotent handlers
* Move existing ExceptionHandler implementations to DefaultStorageExceptionHandlerFactory
* Refactor StorageOptions to use new StorageExceptionHandlerFactory
* Make RetryAlgorithmManager a concrete class implemented in terms of the provided StorageExceptionHandlerFactory rather than an interface
* Remove LegacyRetryAlgorithmManager
* Remove NewRetryAlgorithmManager
@BenWhitehead BenWhitehead requested review from a team and frankyn October 14, 2021 21:57
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 14, 2021
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/java-storage API. label Oct 14, 2021

ExceptionHandler getIdempotentHandler();

ExceptionHandler getNonidempotentHandler();
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.

This is much easier to grok compared to having an overload for each operation. Is there potential gotchas to introduce only two calls instead of a call per method? Definitely would like to talk through this more.

Are you thinking of updating the design document with this change so we can discuss / get it approved by folks?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, if we think this new approach feels better than I can write it up and share around for feedback from folks.

Compared with the per-method is primarily that there is less granularity. This new approach seems to follow the pattern of the other languages and is probably better for an initial release. Afterward we can gauge whether there is demand to providing the per method approach.

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.

+1 to @frankyn , this seems easier to understand as a public surface and the loss of granularity/configurability seems minor (and can be worked around by using additional clients if it's really necessary).

…ctory

* following the precedent set by node use the term strategy for retry selection compared to the generic factory as before
* Change retry types from ExceptionHandler to ResultRetryAlgorithm<?>. ExceptionHandler is a subclass of ResultRetryAlgorithm<?>, but this provides us binary compatability moving forward if we ever need to provide an implementation which isn't based on ExceptionHandler.
* Remove LegacyStorageExceptionHandlerFactory and replace it with UniformStorageRetryStrategy. Allowing for a single algorithm to be specified and used for both idempotent and non-idempotent cases.
* Rename StorageExceptionHandlerFactory to StorageRetryStrategy
* Move access of strategy implementations to static method on StorageRetryStrategy.java
* Add new getUniformStorageRetryStrategy() which provides a strategy which will use the idempotent algorithm for both cases.
* Add javadocs with explanations about the strategies and their behaviors
* Add serialVersionUID to each of the new classes which are Serializable
@BenWhitehead
Copy link
Copy Markdown
Collaborator Author

ResultRetryAlgorithm is the name of the type from gax and is ultimately what is accepted by RetryHelper.runWithRetries. I used the work algorithm for the variables to not type the whole name.

I chose the name StorageRetryStrategy for the factory class as it's functioning as an accessor for specific strategies of evaluation (i.e. 'selecting either the idempotent strategy of retrying or the non-idempotent') and because node is using the name IdempotentcyStrategy. If we want to change StorageRetryStrategy to StorageRetryPolicy I can make that change.

@BenWhitehead BenWhitehead merged commit 0f5b3cb into googleapis:main Oct 20, 2021
@BenWhitehead BenWhitehead deleted the ram-refactor branch October 20, 2021 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/java-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.

3 participants