Class AuroraListener

All Implemented Interfaces:
Listener

public class AuroraListener extends MastersReplicasListener
  • Field Details

    • logger

      private static final Logger logger
    • auroraDnsPattern

      private final Pattern auroraDnsPattern
    • clusterHostAddress

      private final HostAddress clusterHostAddress
    • clusterDnsSuffix

      private String clusterDnsSuffix
  • Constructor Details

    • AuroraListener

      public AuroraListener(UrlParser urlParser, GlobalStateInfo globalInfo) throws 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 information
      globalInfo - server global variables information
      Throws:
      SQLException - when connection string contain host with different cluster
  • Method Details

    • findClusterHostAddress

      private HostAddress findClusterHostAddress() throws SQLException
      Retrieves the cluster host address from the UrlParser instance.
      Returns:
      cluster host address
      Throws:
      SQLException
    • getClusterDnsSuffix

      public String getClusterDnsSuffix()
    • getClusterHostAddress

      public HostAddress getClusterHostAddress()
    • reconnectFailedConnection

      public void reconnectFailedConnection(SearchFilter initialSearchFilter) throws 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 interface Listener
      Overrides:
      reconnectFailedConnection in class MastersReplicasListener
      Parameters:
      initialSearchFilter - initial search filter
      Throws:
      SQLException - if a connection asked is not found
    • retrieveAllEndpointsAndSet

      public void retrieveAllEndpointsAndSet(Protocol protocol) throws 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:
      SQLException - if connection error occur
    • getCurrentEndpointIdentifiers

      private List<String> getCurrentEndpointIdentifiers(Protocol protocol) throws 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:
      SQLException - if connection error occur
    • setUrlParserFromEndpoints

      private void setUrlParserFromEndpoints(List<String> endpoints, int port)
      Sets urlParser accordingly to discovered hosts.
      Parameters:
      endpoints - instance identifiers
      port - port that is common to all endpoints
    • searchByStartName

      public HostAddress searchByStartName(Protocol secondaryProtocol, 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 protocol
      loopAddress - list of possible hosts
      Returns:
      the probable master address or null if not found
    • searchForMasterHostAddress

      private HostAddress searchForMasterHostAddress(Protocol protocol, List<HostAddress> loopAddress) throws 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 protocol
      loopAddress - list of possible hosts
      Returns:
      the probable host address or null if no valid endpoint found
      Throws:
      SQLException - if any connection error occur
    • checkMasterStatus

      public boolean checkMasterStatus(SearchFilter searchFilter)
      Description copied from class: MastersReplicasListener
      Check master status.
      Specified by:
      checkMasterStatus in interface Listener
      Overrides:
      checkMasterStatus in class MastersReplicasListener
      Parameters:
      searchFilter - search filter
      Returns:
      has some status changed