From 29d38e1dbec0e1ef7abbb3fe48fca554dc879c4c Mon Sep 17 00:00:00 2001 From: rishtigupta <127137312+rishtigupta@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:48:19 -0800 Subject: [PATCH] feat: use retry interceptor for streaming calls (#400) --- .../momento/sdk/RetryClientInterceptor.java | 27 ++++++++--------- .../DefaultRetryEligibilityStrategy.java | 1 + ...lientCall.java => RetryingClientCall.java} | 30 ++++++++----------- 3 files changed, 27 insertions(+), 31 deletions(-) rename momento-sdk/src/main/java/momento/sdk/retry/{RetryingUnaryClientCall.java => RetryingClientCall.java} (67%) diff --git a/momento-sdk/src/main/java/momento/sdk/RetryClientInterceptor.java b/momento-sdk/src/main/java/momento/sdk/RetryClientInterceptor.java index 497c75ad..07a366fb 100644 --- a/momento-sdk/src/main/java/momento/sdk/RetryClientInterceptor.java +++ b/momento-sdk/src/main/java/momento/sdk/RetryClientInterceptor.java @@ -18,26 +18,27 @@ import javax.annotation.Nullable; import momento.sdk.retry.RetryEligibilityStrategy; import momento.sdk.retry.RetryStrategy; -import momento.sdk.retry.RetryingUnaryClientCall; +import momento.sdk.retry.RetryingClientCall; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Interceptor for retrying client calls with gRPC servers. This interceptor is responsible for - * handling retry logic when making unary (single request, single response) gRPC calls. + * handling retry logic when making unary (single request, single response) and streaming gRPC + * calls. * *
A {@link ClientCall} is essentially an instance of a gRPC invoker. Every gRPC interceptor * expects us to return such client call(s) that it will execute in order. Each call has a "start" * method, which is the entry point for the call. * - *
This retry client interceptor returns an instance of a {@link RetryingUnaryClientCall}, which - * is a client call designed to handle retrying unary (single request, single response) operations. - * The interceptor uses a provided {@link RetryStrategy} to determine when and how to retry failed - * calls. + *
This retry client interceptor returns an instance of a {@link RetryingClientCall}, which is a + * client call designed to handle retrying unary (single request, single response) and streaming + * call operations. The interceptor uses a provided {@link RetryStrategy} to determine when and how + * to retry failed calls. * *
When a gRPC call is intercepted, the interceptor checks whether the method is unary (client - * sends one message), and if so, it wraps the original {@link ClientCall} with the {@link - * RetryingUnaryClientCall}. This custom call is responsible for handling the retry logic. + * sends one message) or streaming, and if so, it wraps the original {@link ClientCall} with the + * {@link RetryingClientCall}. This custom call is responsible for handling the retry logic. * *
When the gRPC call is closed, the {@code onClose} method is called, which is the point where * we can safely check the status of the initial request that was made and determine if we want to @@ -48,8 +49,6 @@ * we should not retry anymore), the interceptor propagates the final result to the original * listener, effectively completing the call with the last status received. * - *
Note that the interceptor only supports unary operations for retrying.
- *
* @see RetryStrategy
* @see RetryEligibilityStrategy
* @param The {@code RetryingUnaryClientCall} wraps an original {@link ClientCall} and intercepts the
- * methods related to starting, sending messages, and handling the response. If the original call
- * encounters an error, the interceptor schedules a retry attempt based on the configured retry
- * strategy and eligibility rules.
+ * The {@code RetryingClientCall} wraps an original {@link ClientCall} and intercepts the methods
+ * related to starting, sending messages, and handling the response. If the original call encounters
+ * an error, the interceptor schedules a retry attempt based on the configured retry strategy and
+ * eligibility rules.
*
- * Each instance of {@code RetryingUnaryClientCall} maintains its own state, including the
- * request message, response listener, headers, and other properties specific to the call. When a
- * retry is needed, a new instance of this class is created with the original request details, and
- * the retry attempt is initiated.
- *
- * Note that this implementation assumes that the gRPC call is unary, meaning the client sends
- * one message and receives one response. For streaming calls or other call types, a different
- * approach or implementation would be required.
+ * Each instance of {@code RetryingClientCall} maintains its own state, including the request
+ * message, response listener, headers, and other properties specific to the call. When a retry is
+ * needed, a new instance of this class is created with the original request details, and the retry
+ * attempt is initiated.
*/
-public class RetryingUnaryClientCall