Retrying
The article is being updated.
YDB is a distributed database management system with automatic load scaling.
Routine maintenance can be carried out on the server side, with server racks or entire data centers temporarily shut down.
This may result in errors arising from YDB operation.
There are different response scenarios depending on the error type.
YDB To ensure high database availability, SDKs provide built-in tools for retries, accounting for error types and responses to them.
Below are code examples showing the YDB SDK built-in tools for retries:
Go
Java
In the YDB Go SDK, correct error handling is implemented by several programming interfaces:
-
- Via the context (where you can set the deadline and cancel).
- Via the operation’s idempotency flag
retry.WithIdempotent()
. By default, the operation is considered non-idempotent.
The user passes a custom function to
retry.Retry
that returns an error by its signature.
If the custom function returnsnil
, then repeat queries stop.
If the custom function returns an error, the YDB Go SDK tries to identify this error and executes retries depending on it.Example of code, using `retry.Retry` function:
Queries to other YDB services (
db.Scripting()
,db.Scheme()
,db.Coordination()
,db.Ratelimiter()
, anddb.Discovery()
) also use theretry.Retry
function internally to make repeat queries.
In the YDB Java SDK, the request retry mechanism is implemented as the com.yandex.ydb.table.SessionRetryContext
helper class. This class is built using the SessionRetryContext.create
method, where you should pass the implementation of the SessionSupplier
interface (usually, this is an instance of the class).
Additionally, the user can set some other options.
maxRetries(int maxRetries)
: The maximum number of operation retries, excluding the first execution. Defaults to10
.retryNotFound(boolean retryNotFound)
: The option to retry operations that return theNOT_FOUND
status. Enabled by default.
CompletableFuture<Status> supplyStatus
: Run an operation that returns a status. Takes theFunction<Session, CompletableFuture<Status>> fn
lambda as an argument.CompletableFuture<Result<T>> supplyResult
: Run an operation that returns data. Takes theFunction<Session, CompletableFutureResult<T>> fn
lambda as an argument.
When using the class, keep in mind that operation retries will be made in the following cases:
The lamda function returns the retryable error code.