Class AbstractMastersListener
- java.lang.Object
-
- org.mariadb.jdbc.internal.failover.AbstractMastersListener
-
- All Implemented Interfaces:
Listener
- Direct Known Subclasses:
AbstractMastersSlavesListener,MastersFailoverListener
public abstract class AbstractMastersListener extends Object implements Listener
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicIntegercurrentConnectionAttemptsprotected ProtocolcurrentProtocolprotected booleancurrentReadOnlyAskedprotected AtomicBooleanexplicitClosedprotected GlobalStateInfoglobalInfoprotected longlastQueryNanosprotected longlastRetryprotected FailoverProxyproxyUrlParserurlParser
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMastersListener(UrlParser urlParser, GlobalStateInfo globalInfo)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidabortConnection(Protocol protocol)Utility to force close existing connection.voidaddToBlacklist(HostAddress hostAddress)After a failover, put the hostAddress in a static list so the other connection will not take this host in account for a time.booleancanRetryFailLoop()abstract booleancheckMasterStatus(SearchFilter searchFilter)static voidclearBlacklist()Clear blacklist data.voidcloseConnection(Protocol protocol)Utility to close existing connection.Set<HostAddress>getBlacklistKeys()StringgetCatalog()ProtocolgetCurrentProtocol()SearchFiltergetFilterForFailedHost()longgetLastQueryNanos()intgetMajorServerVersion()longgetMasterHostFailNanos()FailoverProxygetProxy()intgetRetriesAllDown()intgetTimeout()UrlParsergetUrlParser()abstract voidhandleFailLoop()HandleErrorResulthandleFailover(SQLException qe, Method method, Object[] args, Protocol protocol, boolean isClosed)Call when a failover is detected on master connection.booleanhasHostFail()voidinitializeConnection()Initialize Listener.booleaninTransaction()Objectinvoke(Method method, Object[] args)Objectinvoke(Method method, Object[] args, Protocol specificProtocol)booleanisAutoReconnect()booleanisClosed()booleanisExplicitClosed()booleanisMasterConnection()booleanisMasterHostFail()booleanisQueryRelaunchable(Method method, Object[] args)Check if query can be re-executed.booleanisReadOnly()booleanisServerMariaDb()booleanisValid(int timeout)booleannoBackslashEscapes()protected booleanpingMasterProtocol(Protocol protocol)protected voidpreAutoReconnect()abstract voidpreClose()abstract voidpreExecute()abstract HandleErrorResultprimaryFail(Method method, Object[] args, boolean killCmd, boolean isClosed)voidprolog(long maxRows, MariaDbConnection connection, MariaDbStatement statement)abstract voidreconnect()abstract voidreconnectFailedConnection(SearchFilter filter)HandleErrorResultrelaunchOperation(Method method, Object[] args)After a failover that has bean done, relaunch the operation that was in progress.voidremoveFromBlacklist(HostAddress hostAddress)After a successfull connection, permit to remove a hostAddress from blacklist.protected voidremoveListenerFromSchedulers()protected voidresetMasterFailoverData()voidresetOldsBlackListHosts()Permit to remove Host to blacklist after loadBalanceBlacklistTimeout seconds.booleansessionStateAware()booleansetMasterHostFail()Set master fail variables.voidsetProxy(FailoverProxy proxy)protected voidsetSessionReadOnly(boolean readOnly, Protocol protocol)abstract voidswitchReadOnlyConnection(Boolean readonly)voidsyncConnection(Protocol from, Protocol to)When switching between 2 connections, report existing connection parameter to the new used connection.voidthrowFailoverMessage(HostAddress failHostAddress, boolean wasMaster, SQLException queryException, boolean reconnected)Throw a human readable message after a failoverException.booleanversionGreaterOrEqual(int major, int minor, int patch)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.mariadb.jdbc.internal.failover.Listener
foundActiveMaster, getServerThreadId, isMasterConnected, preAbort, rePrepareOnSlave, reset
-
-
-
-
Field Detail
-
urlParser
public final UrlParser urlParser
-
currentConnectionAttempts
protected final AtomicInteger currentConnectionAttempts
-
explicitClosed
protected final AtomicBoolean explicitClosed
-
globalInfo
protected final GlobalStateInfo globalInfo
-
currentReadOnlyAsked
protected volatile boolean currentReadOnlyAsked
-
currentProtocol
protected Protocol currentProtocol
-
proxy
protected FailoverProxy proxy
-
lastRetry
protected long lastRetry
-
lastQueryNanos
protected long lastQueryNanos
-
-
Constructor Detail
-
AbstractMastersListener
protected AbstractMastersListener(UrlParser urlParser, GlobalStateInfo globalInfo)
-
-
Method Detail
-
clearBlacklist
public static void clearBlacklist()
Clear blacklist data.
-
initializeConnection
public void initializeConnection() throws SQLExceptionInitialize Listener. This listener will be added to the connection validation loop according to option value so the connection will be verified periodically. (Important for aurora, for other, connection pool often have this functionality)- Specified by:
initializeConnectionin interfaceListener- Throws:
SQLException- if any exception occur.
-
removeListenerFromSchedulers
protected void removeListenerFromSchedulers()
-
preAutoReconnect
protected void preAutoReconnect() throws SQLException- Throws:
SQLException
-
getProxy
public FailoverProxy getProxy()
-
setProxy
public void setProxy(FailoverProxy proxy)
-
getBlacklistKeys
public Set<HostAddress> getBlacklistKeys()
- Specified by:
getBlacklistKeysin interfaceListener
-
handleFailover
public HandleErrorResult handleFailover(SQLException qe, Method method, Object[] args, Protocol protocol, boolean isClosed) throws SQLException
Call when a failover is detected on master connection. Will :- set fail variable
- try to reconnect
- relaunch query if possible
- Specified by:
handleFailoverin interfaceListener- Parameters:
method- called methodargs- methods parametersprotocol- current protocol- Returns:
- a HandleErrorResult object to indicate if query has been relaunched, and the exception if not
- Throws:
SQLException- when method and parameters does not exist.
-
addToBlacklist
public void addToBlacklist(HostAddress hostAddress)
After a failover, put the hostAddress in a static list so the other connection will not take this host in account for a time.- Specified by:
addToBlacklistin interfaceListener- Parameters:
hostAddress- the HostAddress to add to blacklist
-
removeFromBlacklist
public void removeFromBlacklist(HostAddress hostAddress)
After a successfull connection, permit to remove a hostAddress from blacklist.- Specified by:
removeFromBlacklistin interfaceListener- Parameters:
hostAddress- the host address tho be remove of blacklist
-
resetOldsBlackListHosts
public void resetOldsBlackListHosts()
Permit to remove Host to blacklist after loadBalanceBlacklistTimeout seconds.
-
resetMasterFailoverData
protected void resetMasterFailoverData()
-
setSessionReadOnly
protected void setSessionReadOnly(boolean readOnly, Protocol protocol) throws SQLException- Throws:
SQLException
-
handleFailLoop
public abstract void handleFailLoop()
-
getCurrentProtocol
public Protocol getCurrentProtocol()
- Specified by:
getCurrentProtocolin interfaceListener
-
getMasterHostFailNanos
public long getMasterHostFailNanos()
-
setMasterHostFail
public boolean setMasterHostFail()
Set master fail variables.- Specified by:
setMasterHostFailin interfaceListener- Returns:
- true if was already failed
-
isMasterHostFail
public boolean isMasterHostFail()
- Specified by:
isMasterHostFailin interfaceListener
-
hasHostFail
public boolean hasHostFail()
- Specified by:
hasHostFailin interfaceListener
-
getFilterForFailedHost
public SearchFilter getFilterForFailedHost()
- Specified by:
getFilterForFailedHostin interfaceListener
-
relaunchOperation
public HandleErrorResult relaunchOperation(Method method, Object[] args) throws SQLException
After a failover that has bean done, relaunch the operation that was in progress. In case of special operation that crash server, doesn't relaunched it;- Parameters:
method- the method accessedargs- the parameters- Returns:
- An object that indicate the result or that the exception as to be thrown
- Throws:
SQLException- if there is any error relaunching initial method
-
isQueryRelaunchable
public boolean isQueryRelaunchable(Method method, Object[] args)
Check if query can be re-executed.- Parameters:
method- invoke methodargs- invoke arguments- Returns:
- true if can be re-executed
-
invoke
public Object invoke(Method method, Object[] args, Protocol specificProtocol) throws Throwable
-
syncConnection
public void syncConnection(Protocol from, Protocol to) throws SQLException
When switching between 2 connections, report existing connection parameter to the new used connection.- Specified by:
syncConnectionin interfaceListener- Parameters:
from- used connectionto- will-be-current connection- Throws:
SQLException- if catalog cannot be set
-
versionGreaterOrEqual
public boolean versionGreaterOrEqual(int major, int minor, int patch)- Specified by:
versionGreaterOrEqualin interfaceListener
-
isServerMariaDb
public boolean isServerMariaDb()
- Specified by:
isServerMariaDbin interfaceListener
-
sessionStateAware
public boolean sessionStateAware()
- Specified by:
sessionStateAwarein interfaceListener
-
noBackslashEscapes
public boolean noBackslashEscapes()
- Specified by:
noBackslashEscapesin interfaceListener
-
getMajorServerVersion
public int getMajorServerVersion()
- Specified by:
getMajorServerVersionin interfaceListener
-
isValid
public boolean isValid(int timeout) throws SQLException- Specified by:
isValidin interfaceListener- Throws:
SQLException
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnlyin interfaceListener
-
inTransaction
public boolean inTransaction()
- Specified by:
inTransactionin interfaceListener
-
isMasterConnection
public boolean isMasterConnection()
- Specified by:
isMasterConnectionin interfaceListener
-
isExplicitClosed
public boolean isExplicitClosed()
- Specified by:
isExplicitClosedin interfaceListener
-
getRetriesAllDown
public int getRetriesAllDown()
- Specified by:
getRetriesAllDownin interfaceListener
-
isAutoReconnect
public boolean isAutoReconnect()
- Specified by:
isAutoReconnectin interfaceListener
-
getUrlParser
public UrlParser getUrlParser()
- Specified by:
getUrlParserin interfaceListener
-
preExecute
public abstract void preExecute() throws SQLException- Specified by:
preExecutein interfaceListener- Throws:
SQLException
-
reconnectFailedConnection
public abstract void reconnectFailedConnection(SearchFilter filter) throws SQLException
- Specified by:
reconnectFailedConnectionin interfaceListener- Throws:
SQLException
-
switchReadOnlyConnection
public abstract void switchReadOnlyConnection(Boolean readonly) throws SQLException
- Specified by:
switchReadOnlyConnectionin interfaceListener- Throws:
SQLException
-
primaryFail
public abstract HandleErrorResult primaryFail(Method method, Object[] args, boolean killCmd, boolean isClosed) throws SQLException
- Specified by:
primaryFailin interfaceListener- Throws:
SQLException
-
throwFailoverMessage
public void throwFailoverMessage(HostAddress failHostAddress, boolean wasMaster, SQLException queryException, boolean reconnected) throws SQLException
Throw a human readable message after a failoverException.- Specified by:
throwFailoverMessagein interfaceListener- Parameters:
failHostAddress- failedHostAddresswasMaster- was failed connection masterqueryException- internal errorreconnected- connection status- Throws:
SQLException- error with failover information
-
canRetryFailLoop
public boolean canRetryFailLoop()
- Specified by:
canRetryFailLoopin interfaceListener
-
prolog
public void prolog(long maxRows, MariaDbConnection connection, MariaDbStatement statement) throws SQLException- Specified by:
prologin interfaceListener- Throws:
SQLException
-
getCatalog
public String getCatalog() throws SQLException
- Specified by:
getCatalogin interfaceListener- Throws:
SQLException
-
getTimeout
public int getTimeout() throws SocketException- Specified by:
getTimeoutin interfaceListener- Throws:
SocketException
-
reconnect
public abstract void reconnect() throws SQLException- Specified by:
reconnectin interfaceListener- Throws:
SQLException
-
checkMasterStatus
public abstract boolean checkMasterStatus(SearchFilter searchFilter)
- Specified by:
checkMasterStatusin interfaceListener
-
getLastQueryNanos
public long getLastQueryNanos()
- Specified by:
getLastQueryNanosin interfaceListener
-
pingMasterProtocol
protected boolean pingMasterProtocol(Protocol protocol)
-
closeConnection
public void closeConnection(Protocol protocol)
Utility to close existing connection.- Parameters:
protocol- connection to close.
-
abortConnection
public void abortConnection(Protocol protocol)
Utility to force close existing connection.- Parameters:
protocol- connection to close.
-
-