Class MultiPrimaryReplicaClient

java.lang.Object
org.mariadb.jdbc.client.impl.MultiPrimaryClient
org.mariadb.jdbc.client.impl.MultiPrimaryReplicaClient
All Implemented Interfaces:
AutoCloseable, Client

public class MultiPrimaryReplicaClient extends MultiPrimaryClient
Handling connection failing automatic reconnection transparently when possible for replication Topology.

remark: would have been better using proxy, but for AOT compilation, avoiding to using not supported proxy class.

  • Field Details

    • logger

      private static final Logger logger
    • waitTimeout

      protected long waitTimeout
      timeout before retrying to reconnect failing host
    • replicaClient

      private Client replicaClient
    • primaryClient

      private Client primaryClient
    • requestReadOnly

      private boolean requestReadOnly
    • nextTryReplica

      private long nextTryReplica
    • nextTryPrimary

      private long nextTryPrimary
  • Constructor Details

  • Method Details

    • reconnectIfNeeded

      private void reconnectIfNeeded()
    • reConnect

      protected Client reConnect() throws SQLException
      Reconnect connection, trying to continue transparently if possible. Different possible cases : replica fails, then reconnect to replica or to master if no replica available

      if reconnect succeed on replica / use master, no problem, continuing without interruption // if reconnect primary, then replay transaction / throw exception if was in transaction.

      Overrides:
      reConnect in class MultiPrimaryClient
      Returns:
      client connection
      Throws:
      SQLException - if exception
    • execute

      public List<Completion> execute(ClientMessage message, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) throws SQLException
      Description copied from interface: Client
      Send client message and read result
      Specified by:
      execute in interface Client
      Overrides:
      execute in class MultiPrimaryClient
      Parameters:
      message - client message
      stmt - statement
      fetchSize - fetch size
      maxRows - maximum number of rows. 0 = all
      resultSetConcurrency - concurrency
      resultSetType - result-set type
      closeOnCompletion - close statement on completion
      canRedo - can client message be redone in case of failover
      Returns:
      results
      Throws:
      SQLException - if any error occurs
    • executePipeline

      public List<Completion> executePipeline(ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) throws SQLException
      Description copied from interface: Client
      Send client messages pipelining and read result
      Specified by:
      executePipeline in interface Client
      Overrides:
      executePipeline in class MultiPrimaryClient
      Parameters:
      messages - client message
      stmt - statement
      fetchSize - fetch size
      maxRows - maximum number of rows. 0 = all
      resultSetConcurrency - concurrency
      resultSetType - result-set type
      closeOnCompletion - close statement on completion
      canRedo - can client message be redone in case of failover
      Returns:
      results
      Throws:
      SQLException - if any error occurs
    • readStreamingResults

      public void readStreamingResults(List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) throws SQLException
      Description copied from interface: Client
      Read results
      Specified by:
      readStreamingResults in interface Client
      Overrides:
      readStreamingResults in class MultiPrimaryClient
      Parameters:
      completions - List that will have the new results
      fetchSize - fetch size
      maxRows - maximum number of rows. 0 = all
      resultSetConcurrency - concurrency
      resultSetType - result-set type
      closeOnCompletion - close statement on completion
      Throws:
      SQLException - if any error occurs
    • closePrepare

      public void closePrepare(Prepare prepare) throws SQLException
      Description copied from interface: Client
      Close prepare command
      Specified by:
      closePrepare in interface Client
      Overrides:
      closePrepare in class MultiPrimaryClient
      Parameters:
      prepare - prepare command
      Throws:
      SQLException - if any error occurs
    • abort

      public void abort(Executor executor) throws SQLException
      Description copied from interface: Client
      Abort current connection
      Specified by:
      abort in interface Client
      Overrides:
      abort in class MultiPrimaryClient
      Parameters:
      executor - executor
      Throws:
      SQLException - if any error occurs
    • close

      public void close() throws SQLException
      Description copied from interface: Client
      Close client
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Client
      Overrides:
      close in class MultiPrimaryClient
      Throws:
      SQLException - if any error occurs
    • setReadOnly

      public void setReadOnly(boolean readOnly) throws SQLException
      Description copied from interface: Client
      Switch to a writer/read-only connection, no effet on mono-connection
      Specified by:
      setReadOnly in interface Client
      Overrides:
      setReadOnly in class MultiPrimaryClient
      Parameters:
      readOnly - must use read-only connection
      Throws:
      SQLException - if any error occurs
    • getSocketTimeout

      public int getSocketTimeout()
      Description copied from interface: Client
      get socket timeout
      Specified by:
      getSocketTimeout in interface Client
      Overrides:
      getSocketTimeout in class MultiPrimaryClient
      Returns:
      socket timeout
    • setSocketTimeout

      public void setSocketTimeout(int milliseconds) throws SQLException
      Description copied from interface: Client
      Set socket timeout
      Specified by:
      setSocketTimeout in interface Client
      Overrides:
      setSocketTimeout in class MultiPrimaryClient
      Parameters:
      milliseconds - timeout
      Throws:
      SQLException - if any error occurs
    • getContext

      public Context getContext()
      Description copied from interface: Client
      Get connection context
      Specified by:
      getContext in interface Client
      Overrides:
      getContext in class MultiPrimaryClient
      Returns:
      connection context
    • getExceptionFactory

      public ExceptionFactory getExceptionFactory()
      Description copied from interface: Client
      Get connection exception factory
      Specified by:
      getExceptionFactory in interface Client
      Overrides:
      getExceptionFactory in class MultiPrimaryClient
      Returns:
      connection exception factory
    • getHostAddress

      public HostAddress getHostAddress()
      Description copied from interface: Client
      Get connection host
      Specified by:
      getHostAddress in interface Client
      Overrides:
      getHostAddress in class MultiPrimaryClient
      Returns:
      connection host
    • isPrimary

      public boolean isPrimary()
      Description copied from interface: Client
      is current client writer or read-only
      Specified by:
      isPrimary in interface Client
      Overrides:
      isPrimary in class MultiPrimaryClient
      Returns:
      is primary
    • reset

      public void reset()
      Description copied from interface: Client
      Reset connection
      Specified by:
      reset in interface Client
      Overrides:
      reset in class MultiPrimaryClient