Class FailoverProxy
java.lang.Object
org.mariadb.jdbc.internal.failover.FailoverProxy
- All Implemented Interfaces:
InvocationHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Listener
final ReentrantLock
private static final Logger
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
final LruTraceCache
-
Constructor Summary
ConstructorsConstructorDescriptionFailoverProxy
(Listener listener, ReentrantLock lock, LruTraceCache traceCache) Proxy constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate static SQLException
addHostInformationToException
(SQLException exception, Protocol protocol) Add Host information ("on HostAddress...") to exception.private Object
executeInvocation
(Method method, Object[] args, boolean isSecondExecution) private Object
handleFailOver
(SQLException qe, Method method, Object[] args, Protocol protocol, boolean isClosed) After a connection exception, launch failover.boolean
hasToHandleFailover
(SQLException exception) Check if this Sqlerror is a connection exception.Proxy that catch Protocol call, to permit to catch errors and handle failover when multiple hosts.void
Launch reconnect implementation.
-
Field Details
-
METHOD_IS_EXPLICIT_CLOSED
- See Also:
-
METHOD_GET_OPTIONS
- See Also:
-
METHOD_GET_URLPARSER
- See Also:
-
METHOD_GET_PROXY
- See Also:
-
METHOD_EXECUTE_QUERY
- See Also:
-
METHOD_SET_READ_ONLY
- See Also:
-
METHOD_GET_READ_ONLY
- See Also:
-
METHOD_IS_MASTER_CONNECTION
- See Also:
-
METHOD_VERSION_GREATER_OR_EQUAL
- See Also:
-
METHOD_SESSION_STATE_AWARE
- See Also:
-
METHOD_CLOSED_EXPLICIT
- See Also:
-
METHOD_ABORT
- See Also:
-
METHOD_IS_CLOSED
- See Also:
-
METHOD_EXECUTE_PREPARED_QUERY
- See Also:
-
METHOD_COM_MULTI_PREPARE_EXECUTES
- See Also:
-
METHOD_PROLOG_PROXY
- See Also:
-
METHOD_RESET
- See Also:
-
METHOD_IS_VALID
- See Also:
-
METHOD_GET_LOCK
- See Also:
-
METHOD_GET_NO_BACKSLASH
- See Also:
-
METHOD_GET_SERVER_THREAD_ID
- See Also:
-
METHOD_PROLOG
- See Also:
-
METHOD_GET_CATALOG
- See Also:
-
METHOD_GET_TIMEOUT
- See Also:
-
METHOD_GET_MAJOR_VERSION
- See Also:
-
METHOD_IN_TRANSACTION
- See Also:
-
METHOD_IS_MARIADB
- See Also:
-
logger
-
lock
-
traceCache
-
listener
-
-
Constructor Details
-
FailoverProxy
public FailoverProxy(Listener listener, ReentrantLock lock, LruTraceCache traceCache) throws SQLException Proxy constructor.- Parameters:
listener
- failover implementation.lock
- synchronisation locktraceCache
- trace cache- Throws:
SQLException
- if connection error occur
-
-
Method Details
-
addHostInformationToException
private static SQLException addHostInformationToException(SQLException exception, Protocol protocol) Add Host information ("on HostAddress...") to exception.example : java.sql.SQLException: (conn=603) Cannot execute statement in a READ ONLY transaction.
Query is: INSERT INTO TableX VALUES (21)
on HostAddress{host='mydb.example.com', port=3306},master=true- Parameters:
exception
- current exceptionprotocol
- protocol to have hostname
-
invoke
Proxy that catch Protocol call, to permit to catch errors and handle failover when multiple hosts.- Specified by:
invoke
in interfaceInvocationHandler
- Parameters:
proxy
- the current protocolmethod
- the called method on the protocolargs
- methods parameters- Returns:
- protocol method result
- Throws:
Throwable
- the method throwed error if not catch by failover
-
executeInvocation
private Object executeInvocation(Method method, Object[] args, boolean isSecondExecution) throws Throwable - Throws:
Throwable
-
handleFailOver
private Object handleFailOver(SQLException qe, Method method, Object[] args, Protocol protocol, boolean isClosed) throws Throwable After a connection exception, launch failover.- Parameters:
qe
- the exception thrownmethod
- the method to call if failover works wellargs
- the arguments of the method- Returns:
- the object return from the method
- Throws:
Throwable
- throwable
-
hasToHandleFailover
Check if this Sqlerror is a connection exception. if that's the case, must be handle by failovererror codes : 08000 : connection exception 08001 : SQL client unable to establish SQL connection 08002 : connection name in use 08003 : connection does not exist 08004 : SQL server rejected SQL connection 08006 : connection failure 08007 : transaction resolution unknown 70100 : connection was killed if error code is "1927"
- Parameters:
exception
- the Exception- Returns:
- true if there has been a connection error that must be handled by failover
-
reconnect
Launch reconnect implementation.- Throws:
SQLException
- exception
-
getListener
-