Package io.debezium.storage.jdbc
Class RetriableConnection
java.lang.Object
io.debezium.storage.jdbc.RetriableConnection
- All Implemented Interfaces:
AutoCloseable
Class encapsulates a java.sql.Connection. It provides
executeWithRetry method to execute code snippet
that interacts with the connection. If that fails with SQLRecoverableException, it will try to
re-create new connection and perform the complete code snippet again (first, it performs rollback
if specified in params).
It attempts to reconnect number of times as specified in
io.debezium.storage.jdbc.JdbcCommonConfig.PROP_MAX_RETRIES and there is a delay in between per
io.debezium.storage.jdbc.JdbcCommonConfig.PROP_WAIT_RETRY_DELAY
The code snippet provided should handle commit of its own if required. The connection is marked as autocommit = false- Author:
- Jiri Kulhanek
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Connectionprivate static final org.slf4j.Loggerprivate final intprivate final Stringprivate final Stringprivate final Stringprivate final Duration -
Constructor Summary
ConstructorsConstructorDescriptionRetriableConnection(String url, String user, String pwd, Duration waitRetryDelay, int maxRetryCount) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()private voidvoidexecuteWithRetry(RetriableConnection.ConnectionConsumer consumer, String name, boolean rollback) execute code snippet where no value is returned.private <T> TexecuteWithRetry(RetriableConnection.ConnectionFunction<T> func, RetriableConnection.ConnectionConsumer consumer, String name, boolean rollback) <T> TexecuteWithRetry(RetriableConnection.ConnectionFunction<T> func, String name, boolean rollback) execute code snippet which returns some value.booleanisOpen()
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
url
-
user
-
pwd
-
waitRetryDelay
-
maxRetryCount
private final int maxRetryCount -
conn
-
-
Constructor Details
-
RetriableConnection
public RetriableConnection(String url, String user, String pwd, Duration waitRetryDelay, int maxRetryCount) throws SQLException - Throws:
SQLException
-
-
Method Details
-
createConnection
- Throws:
SQLException
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException
-
isOpen
public boolean isOpen() -
executeWithRetry
public void executeWithRetry(RetriableConnection.ConnectionConsumer consumer, String name, boolean rollback) throws SQLException execute code snippet where no value is returned.- Parameters:
consumer- code snippet to executename- name of the operation being executed (for logging purposes)rollback- if set to true, the rollback will be called in case of SQLException- Throws:
SQLException- sql connection related exception
-
executeWithRetry
public <T> T executeWithRetry(RetriableConnection.ConnectionFunction<T> func, String name, boolean rollback) throws SQLException execute code snippet which returns some value.- Parameters:
func- code snippet to executename- name of the operation being executed (for logging purposes)rollback- if set to true, the rollback will be called in case of SQLException- Throws:
SQLException- sql connection related exception
-
executeWithRetry
private <T> T executeWithRetry(RetriableConnection.ConnectionFunction<T> func, RetriableConnection.ConnectionConsumer consumer, String name, boolean rollback) throws SQLException - Throws:
SQLException
-