Skip to content

Transport level retry#954

Open
l-trotta wants to merge 7 commits into
mainfrom
transport-level-retry
Open

Transport level retry#954
l-trotta wants to merge 7 commits into
mainfrom
transport-level-retry

Conversation

@l-trotta

@l-trotta l-trotta commented Mar 3, 2025

Copy link
Copy Markdown
Contributor

Adds new retry functionality to the client, configurable like so:

try (ElasticsearchClient client = ElasticsearchClient.of(e -> e
    .host(serverUrl)
    .apiKey(apikey)
    .retryConfig(r -> r
        .retryableExceptions(Set.of(SocketException.class)) // defaults to IOException.class
        .retryableStatuses(429,503) // defaults to 429, 500, 502, 503, 504
        .backoffPolicy(BackoffPolicy.constantBackoff(5000L,5)) // defaults to BackoffPolicy.noBackoff()
    )
)) 

The delegate client (Rest5Client, RestClient or any custom client) is wrapped in an instance of RetryingHttpClient, which takes care of the retrying logic according to the configuration.
This only concerns the same node the request was originally sent to, it's still the underlying client's responsibility to handle dead node logic and node selection.

@l-trotta l-trotta requested a review from swallez March 3, 2025 17:00

@swallez swallez left a comment

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.

Left some comments on implementation independence and async tasks.

Adding this to TransportOptions is an interesting choice, as it allows using different retry policies with a single transport.

import java.util.Iterator;
import java.util.concurrent.CompletableFuture;

public class RetryRestClientHttpClient implements TransportHttpClient {

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 class should be co.elastic.transport.http.RetryingHttpClient and be independent from org.elasticsearch.client so that it can be independent of the http client implementation (see also below on exception handling)

@l-trotta l-trotta force-pushed the transport-level-retry branch from 8012980 to 2fd0bbc Compare June 19, 2026 16:35
@l-trotta l-trotta marked this pull request as ready for review June 19, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants