Class FailoverProxy
- java.lang.Object
-
- org.mariadb.jdbc.internal.failover.FailoverProxy
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
public class FailoverProxy extends java.lang.Object implements java.lang.reflect.InvocationHandler
-
-
Field Summary
Fields Modifier and Type Field Description private Listener
listener
java.util.concurrent.locks.ReentrantLock
lock
private static Logger
logger
private static java.lang.String
METHOD_ABORT
private static java.lang.String
METHOD_CLOSED_EXPLICIT
private static java.lang.String
METHOD_COM_MULTI_PREPARE_EXECUTES
private static java.lang.String
METHOD_EXECUTE_PREPARED_QUERY
private static java.lang.String
METHOD_EXECUTE_QUERY
private static java.lang.String
METHOD_GET_CATALOG
private static java.lang.String
METHOD_GET_LOCK
private static java.lang.String
METHOD_GET_MAJOR_VERSION
private static java.lang.String
METHOD_GET_NO_BACKSLASH
private static java.lang.String
METHOD_GET_OPTIONS
private static java.lang.String
METHOD_GET_PROXY
private static java.lang.String
METHOD_GET_READ_ONLY
private static java.lang.String
METHOD_GET_SERVER_THREAD_ID
private static java.lang.String
METHOD_GET_TIMEOUT
private static java.lang.String
METHOD_GET_URLPARSER
private static java.lang.String
METHOD_IN_TRANSACTION
private static java.lang.String
METHOD_IS_CLOSED
private static java.lang.String
METHOD_IS_EXPLICIT_CLOSED
private static java.lang.String
METHOD_IS_MARIADB
private static java.lang.String
METHOD_IS_MASTER_CONNECTION
private static java.lang.String
METHOD_IS_VALID
private static java.lang.String
METHOD_PROLOG
private static java.lang.String
METHOD_PROLOG_PROXY
private static java.lang.String
METHOD_RESET
private static java.lang.String
METHOD_SESSION_STATE_AWARE
private static java.lang.String
METHOD_SET_READ_ONLY
private static java.lang.String
METHOD_VERSION_GREATER_OR_EQUAL
LruTraceCache
traceCache
-
Constructor Summary
Constructors Constructor Description FailoverProxy(Listener listener, java.util.concurrent.locks.ReentrantLock lock, LruTraceCache traceCache)
Proxy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.sql.SQLException
addHostInformationToException(java.sql.SQLException exception, Protocol protocol)
Add Host information ("on HostAddress...") to exception.private java.lang.Object
executeInvocation(java.lang.reflect.Method method, java.lang.Object[] args, boolean isSecondExecution)
Listener
getListener()
private java.lang.Object
handleFailOver(java.sql.SQLException qe, java.lang.reflect.Method method, java.lang.Object[] args, Protocol protocol, boolean isClosed)
After a connection exception, launch failover.boolean
hasToHandleFailover(java.sql.SQLException exception)
Check if this Sqlerror is a connection exception.java.lang.Object
invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
Proxy that catch Protocol call, to permit to catch errors and handle failover when multiple hosts.void
reconnect()
Launch reconnect implementation.
-
-
-
Field Detail
-
METHOD_IS_EXPLICIT_CLOSED
private static final java.lang.String METHOD_IS_EXPLICIT_CLOSED
- See Also:
- Constant Field Values
-
METHOD_GET_OPTIONS
private static final java.lang.String METHOD_GET_OPTIONS
- See Also:
- Constant Field Values
-
METHOD_GET_URLPARSER
private static final java.lang.String METHOD_GET_URLPARSER
- See Also:
- Constant Field Values
-
METHOD_GET_PROXY
private static final java.lang.String METHOD_GET_PROXY
- See Also:
- Constant Field Values
-
METHOD_EXECUTE_QUERY
private static final java.lang.String METHOD_EXECUTE_QUERY
- See Also:
- Constant Field Values
-
METHOD_SET_READ_ONLY
private static final java.lang.String METHOD_SET_READ_ONLY
- See Also:
- Constant Field Values
-
METHOD_GET_READ_ONLY
private static final java.lang.String METHOD_GET_READ_ONLY
- See Also:
- Constant Field Values
-
METHOD_IS_MASTER_CONNECTION
private static final java.lang.String METHOD_IS_MASTER_CONNECTION
- See Also:
- Constant Field Values
-
METHOD_VERSION_GREATER_OR_EQUAL
private static final java.lang.String METHOD_VERSION_GREATER_OR_EQUAL
- See Also:
- Constant Field Values
-
METHOD_SESSION_STATE_AWARE
private static final java.lang.String METHOD_SESSION_STATE_AWARE
- See Also:
- Constant Field Values
-
METHOD_CLOSED_EXPLICIT
private static final java.lang.String METHOD_CLOSED_EXPLICIT
- See Also:
- Constant Field Values
-
METHOD_ABORT
private static final java.lang.String METHOD_ABORT
- See Also:
- Constant Field Values
-
METHOD_IS_CLOSED
private static final java.lang.String METHOD_IS_CLOSED
- See Also:
- Constant Field Values
-
METHOD_EXECUTE_PREPARED_QUERY
private static final java.lang.String METHOD_EXECUTE_PREPARED_QUERY
- See Also:
- Constant Field Values
-
METHOD_COM_MULTI_PREPARE_EXECUTES
private static final java.lang.String METHOD_COM_MULTI_PREPARE_EXECUTES
- See Also:
- Constant Field Values
-
METHOD_PROLOG_PROXY
private static final java.lang.String METHOD_PROLOG_PROXY
- See Also:
- Constant Field Values
-
METHOD_RESET
private static final java.lang.String METHOD_RESET
- See Also:
- Constant Field Values
-
METHOD_IS_VALID
private static final java.lang.String METHOD_IS_VALID
- See Also:
- Constant Field Values
-
METHOD_GET_LOCK
private static final java.lang.String METHOD_GET_LOCK
- See Also:
- Constant Field Values
-
METHOD_GET_NO_BACKSLASH
private static final java.lang.String METHOD_GET_NO_BACKSLASH
- See Also:
- Constant Field Values
-
METHOD_GET_SERVER_THREAD_ID
private static final java.lang.String METHOD_GET_SERVER_THREAD_ID
- See Also:
- Constant Field Values
-
METHOD_PROLOG
private static final java.lang.String METHOD_PROLOG
- See Also:
- Constant Field Values
-
METHOD_GET_CATALOG
private static final java.lang.String METHOD_GET_CATALOG
- See Also:
- Constant Field Values
-
METHOD_GET_TIMEOUT
private static final java.lang.String METHOD_GET_TIMEOUT
- See Also:
- Constant Field Values
-
METHOD_GET_MAJOR_VERSION
private static final java.lang.String METHOD_GET_MAJOR_VERSION
- See Also:
- Constant Field Values
-
METHOD_IN_TRANSACTION
private static final java.lang.String METHOD_IN_TRANSACTION
- See Also:
- Constant Field Values
-
METHOD_IS_MARIADB
private static final java.lang.String METHOD_IS_MARIADB
- See Also:
- Constant Field Values
-
logger
private static final Logger logger
-
lock
public final java.util.concurrent.locks.ReentrantLock lock
-
traceCache
public final LruTraceCache traceCache
-
listener
private final Listener listener
-
-
Constructor Detail
-
FailoverProxy
public FailoverProxy(Listener listener, java.util.concurrent.locks.ReentrantLock lock, LruTraceCache traceCache) throws java.sql.SQLException
Proxy constructor.- Parameters:
listener
- failover implementation.lock
- synchronisation locktraceCache
- trace cache- Throws:
java.sql.SQLException
- if connection error occur
-
-
Method Detail
-
addHostInformationToException
private static java.sql.SQLException addHostInformationToException(java.sql.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
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
Proxy that catch Protocol call, to permit to catch errors and handle failover when multiple hosts.- Specified by:
invoke
in interfacejava.lang.reflect.InvocationHandler
- Parameters:
proxy
- the current protocolmethod
- the called method on the protocolargs
- methods parameters- Returns:
- protocol method result
- Throws:
java.lang.Throwable
- the method throwed error if not catch by failover
-
executeInvocation
private java.lang.Object executeInvocation(java.lang.reflect.Method method, java.lang.Object[] args, boolean isSecondExecution) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
handleFailOver
private java.lang.Object handleFailOver(java.sql.SQLException qe, java.lang.reflect.Method method, java.lang.Object[] args, Protocol protocol, boolean isClosed) throws java.lang.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:
java.lang.Throwable
- throwable
-
hasToHandleFailover
public boolean hasToHandleFailover(java.sql.SQLException exception)
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
public void reconnect() throws java.sql.SQLException
Launch reconnect implementation.- Throws:
java.sql.SQLException
- exception
-
getListener
public Listener getListener()
-
-