Class AuroraListener
- java.lang.Object
-
- org.mariadb.jdbc.internal.failover.AbstractMastersListener
-
- org.mariadb.jdbc.internal.failover.AbstractMastersSlavesListener
-
- org.mariadb.jdbc.internal.failover.impl.MastersSlavesListener
-
- org.mariadb.jdbc.internal.failover.impl.AuroraListener
-
- All Implemented Interfaces:
Listener
public class AuroraListener extends MastersSlavesListener
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.regex.Pattern
auroraDnsPattern
private java.lang.String
clusterDnsSuffix
private HostAddress
clusterHostAddress
private static java.util.logging.Logger
logger
-
Fields inherited from class org.mariadb.jdbc.internal.failover.impl.MastersSlavesListener
hostAddresses, masterProtocol, secondaryProtocol
-
Fields inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersSlavesListener
waitNewMasterProtocol, waitNewSecondaryProtocol
-
Fields inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersListener
currentConnectionAttempts, currentProtocol, currentReadOnlyAsked, explicitClosed, globalInfo, lastQueryNanos, lastRetry, proxy, urlParser
-
-
Constructor Summary
Constructors Constructor Description AuroraListener(UrlParser urlParser, GlobalStateInfo globalInfo)
Constructor for Aurora.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkMasterStatus(SearchFilter searchFilter)
Check master status.private HostAddress
findClusterHostAddress()
Retrieves the cluster host address from the UrlParser instance.java.lang.String
getClusterDnsSuffix()
HostAddress
getClusterHostAddress()
private java.util.List<java.lang.String>
getCurrentEndpointIdentifiers(Protocol protocol)
Retrieves all endpoints of a cluster from the appropriate database table.void
reconnectFailedConnection(SearchFilter initialSearchFilter)
Search a valid connection for failed one.void
retrieveAllEndpointsAndSet(Protocol protocol)
Retrieves the information necessary to add a new endpoint.HostAddress
searchByStartName(Protocol secondaryProtocol, java.util.List<HostAddress> loopAddress)
Looks for the current master/writer instance via the secondary protocol if it is found within 3 attempts.private HostAddress
searchForMasterHostAddress(Protocol protocol, java.util.List<HostAddress> loopAddress)
Aurora replica doesn't have the master endpoint but the master instance name.private void
setUrlParserFromEndpoints(java.util.List<java.lang.String> endpoints, int port)
Sets urlParser accordingly to discovered hosts.-
Methods inherited from class org.mariadb.jdbc.internal.failover.impl.MastersSlavesListener
checkInitialConnection, checkWaitingConnection, connectedHosts, foundActiveMaster, foundActiveSecondary, getCatalog, getMajorServerVersion, getServerThreadId, getTimeout, handleFailLoop, initializeConnection, inTransaction, invoke, isClosed, isMasterConnected, isMasterConnection, isServerMariaDb, isValid, lockAndSwitchMaster, lockAndSwitchSecondary, noBackslashEscapes, preAbort, preClose, preExecute, primaryFail, prolog, reconnect, removeListenerFromSchedulers, rePrepareOnSlave, reset, secondaryFail, sessionStateAware, switchReadOnlyConnection, versionGreaterOrEqual
-
Methods inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersSlavesListener
getFilterForFailedHost, getSecondaryHostFailNanos, handleFailover, hasHostFail, isMasterHostFailReconnect, isSecondaryHostFail, isSecondaryHostFailReconnect, resetMasterFailoverData, resetSecondaryFailoverData, setSecondaryHostFail
-
Methods inherited from class org.mariadb.jdbc.internal.failover.AbstractMastersListener
abortConnection, addToBlacklist, canRetryFailLoop, clearBlacklist, closeConnection, getBlacklistKeys, getCurrentProtocol, getLastQueryNanos, getMasterHostFailNanos, getProxy, getRetriesAllDown, getUrlParser, invoke, isAutoReconnect, isExplicitClosed, isMasterHostFail, isQueryRelaunchable, isReadOnly, pingMasterProtocol, preAutoReconnect, relaunchOperation, removeFromBlacklist, resetOldsBlackListHosts, setMasterHostFail, setProxy, setSessionReadOnly, syncConnection, throwFailoverMessage
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
auroraDnsPattern
private final java.util.regex.Pattern auroraDnsPattern
-
clusterHostAddress
private final HostAddress clusterHostAddress
-
clusterDnsSuffix
private java.lang.String clusterDnsSuffix
-
-
Constructor Detail
-
AuroraListener
public AuroraListener(UrlParser urlParser, GlobalStateInfo globalInfo) throws java.sql.SQLException
Constructor for Aurora. This differ from standard failover because : - we don't know current master, we must check that after initial connection - master can change after he has a failover- Parameters:
urlParser
- connection informationglobalInfo
- server global variables information- Throws:
java.sql.SQLException
- when connection string contain host with different cluster
-
-
Method Detail
-
findClusterHostAddress
private HostAddress findClusterHostAddress() throws java.sql.SQLException
Retrieves the cluster host address from the UrlParser instance.- Returns:
- cluster host address
- Throws:
java.sql.SQLException
-
getClusterDnsSuffix
public java.lang.String getClusterDnsSuffix()
-
getClusterHostAddress
public HostAddress getClusterHostAddress()
-
reconnectFailedConnection
public void reconnectFailedConnection(SearchFilter initialSearchFilter) throws java.sql.SQLException
Search a valid connection for failed one. A Node can be a master or a replica depending on the cluster state. so search for each host until found all the failed connection. By default, search for the host not down, and recheck the down one after if not found valid connections.- Specified by:
reconnectFailedConnection
in interfaceListener
- Overrides:
reconnectFailedConnection
in classMastersSlavesListener
- Parameters:
initialSearchFilter
- initial search filter- Throws:
java.sql.SQLException
- if a connection asked is not found
-
retrieveAllEndpointsAndSet
public void retrieveAllEndpointsAndSet(Protocol protocol) throws java.sql.SQLException
Retrieves the information necessary to add a new endpoint. Calls the methods that retrieves the instance identifiers and sets urlParser accordingly.- Parameters:
protocol
- current protocol connected to- Throws:
java.sql.SQLException
- if connection error occur
-
getCurrentEndpointIdentifiers
private java.util.List<java.lang.String> getCurrentEndpointIdentifiers(Protocol protocol) throws java.sql.SQLException
Retrieves all endpoints of a cluster from the appropriate database table.- Parameters:
protocol
- current protocol connected to- Returns:
- instance endpoints of the cluster
- Throws:
java.sql.SQLException
- if connection error occur
-
setUrlParserFromEndpoints
private void setUrlParserFromEndpoints(java.util.List<java.lang.String> endpoints, int port)
Sets urlParser accordingly to discovered hosts.- Parameters:
endpoints
- instance identifiersport
- port that is common to all endpoints
-
searchByStartName
public HostAddress searchByStartName(Protocol secondaryProtocol, java.util.List<HostAddress> loopAddress)
Looks for the current master/writer instance via the secondary protocol if it is found within 3 attempts. Should it not be able to connect, the host is blacklisted and null is returned. Otherwise, it will open a new connection to the cluster endpoint and retrieve the data from there.- Parameters:
secondaryProtocol
- the current secondary protocolloopAddress
- list of possible hosts- Returns:
- the probable master address or null if not found
-
searchForMasterHostAddress
private HostAddress searchForMasterHostAddress(Protocol protocol, java.util.List<HostAddress> loopAddress) throws java.sql.SQLException
Aurora replica doesn't have the master endpoint but the master instance name. since the end point normally use the instance name like "instance-name.some_unique_string.region.rds.amazonaws.com", if an endpoint start with this instance name, it will be checked first. Otherwise, the endpoint ending string is extracted and used since the writer was newly created.- Parameters:
protocol
- current protocolloopAddress
- list of possible hosts- Returns:
- the probable host address or null if no valid endpoint found
- Throws:
java.sql.SQLException
- if any connection error occur
-
checkMasterStatus
public boolean checkMasterStatus(SearchFilter searchFilter)
Description copied from class:MastersSlavesListener
Check master status.- Specified by:
checkMasterStatus
in interfaceListener
- Overrides:
checkMasterStatus
in classMastersSlavesListener
- Parameters:
searchFilter
- search filter- Returns:
- has some status changed
-
-