Class MultiPrimaryClient

  • All Implemented Interfaces:
    java.lang.AutoCloseable, Client
    Direct Known Subclasses:
    MultiPrimaryReplicaClient

    public class MultiPrimaryClient
    extends java.lang.Object
    implements Client
    Handling connection failing automatic reconnection transparently when possible for multi-master Topology.

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

    • Field Detail

      • logger

        private static final Logger logger
      • denyList

        protected static final java.util.concurrent.ConcurrentMap<HostAddress,​java.lang.Long> denyList
      • deniedListTimeout

        protected final long deniedListTimeout
      • closed

        protected boolean closed
      • lock

        protected final java.util.concurrent.locks.ReentrantLock lock
      • currentClient

        protected Client currentClient
    • Constructor Detail

      • MultiPrimaryClient

        public MultiPrimaryClient​(Configuration conf,
                                  java.util.concurrent.locks.ReentrantLock lock)
                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException
    • Method Detail

      • connectHost

        protected Client connectHost​(boolean readOnly,
                                     boolean failFast)
                              throws java.sql.SQLException
        Trying connecting server.

        searching each connecting primary / replica connection not temporary denied until found one. searching in temporary denied host if not succeed, until reaching `retriesAllDown` attempts.

        Parameters:
        readOnly - must connect a replica / primary
        failFast - must try only not denyed server
        Returns:
        a valid connection client
        Throws:
        java.sql.SQLException - if not succeed to create a connection.
      • reConnect

        protected void reConnect()
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • executeTransactionReplay

        protected void executeTransactionReplay​(Client oldCli)
                                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • syncNewState

        public void syncNewState​(Client oldCli)
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • execute

        public java.util.List<Completion> execute​(ClientMessage message)
                                           throws java.sql.SQLException
        Specified by:
        execute in interface Client
        Throws:
        java.sql.SQLException
      • execute

        public java.util.List<Completion> execute​(ClientMessage message,
                                                  Statement stmt,
                                                  int fetchSize,
                                                  long maxRows,
                                                  int resultSetConcurrency,
                                                  int resultSetType,
                                                  boolean closeOnCompletion)
                                           throws java.sql.SQLException
        Specified by:
        execute in interface Client
        Throws:
        java.sql.SQLException
      • executePipeline

        public java.util.List<Completion> executePipeline​(ClientMessage[] messages,
                                                          Statement stmt,
                                                          int fetchSize,
                                                          long maxRows,
                                                          int resultSetConcurrency,
                                                          int resultSetType,
                                                          boolean closeOnCompletion)
                                                   throws java.sql.SQLException
        Specified by:
        executePipeline in interface Client
        Throws:
        java.sql.SQLException
      • readStreamingResults

        public void readStreamingResults​(java.util.List<Completion> completions,
                                         int fetchSize,
                                         long maxRows,
                                         int resultSetConcurrency,
                                         int resultSetType,
                                         boolean closeOnCompletion)
                                  throws java.sql.SQLException
        Specified by:
        readStreamingResults in interface Client
        Throws:
        java.sql.SQLException
      • abort

        public void abort​(java.util.concurrent.Executor executor)
                   throws java.sql.SQLException
        Specified by:
        abort in interface Client
        Throws:
        java.sql.SQLException
      • close

        public void close()
                   throws java.sql.SQLException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface Client
        Throws:
        java.sql.SQLException
      • setReadOnly

        public void setReadOnly​(boolean readOnly)
                         throws java.sql.SQLException
        Specified by:
        setReadOnly in interface Client
        Throws:
        java.sql.SQLException
      • setSocketTimeout

        public void setSocketTimeout​(int milliseconds)
                              throws java.sql.SQLException
        Specified by:
        setSocketTimeout in interface Client
        Throws:
        java.sql.SQLException
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in interface Client
      • isPrimary

        public boolean isPrimary()
        Specified by:
        isPrimary in interface Client
      • reset

        public void reset()
        Specified by:
        reset in interface Client