Package org.mariadb.jdbc.client
Class MultiPrimaryClient
- java.lang.Object
-
- org.mariadb.jdbc.client.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 Summary
Fields Modifier and Type Field Description protected booleanclosedprotected Configurationconfprotected ClientcurrentClientprotected longdeniedListTimeoutprotected static java.util.concurrent.ConcurrentMap<HostAddress,java.lang.Long>denyListprotected java.util.concurrent.locks.ReentrantLocklockprivate static Loggerlogger
-
Constructor Summary
Constructors Constructor Description MultiPrimaryClient(Configuration conf, java.util.concurrent.locks.ReentrantLock lock)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort(java.util.concurrent.Executor executor)voidclose()voidclosePrepare(PrepareResultPacket prepare)protected ClientconnectHost(boolean readOnly, boolean failFast)Trying connecting server.java.util.List<Completion>execute(ClientMessage message)java.util.List<Completion>execute(ClientMessage message, Statement stmt)java.util.List<Completion>execute(ClientMessage message, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion)java.util.List<Completion>executePipeline(ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion)protected voidexecuteTransactionReplay(Client oldCli)ContextgetContext()ExceptionFactorygetExceptionFactory()HostAddressgetHostAddress()intgetSocketTimeout()intgetWaitTimeout()booleanisClosed()booleanisPrimary()voidreadStreamingResults(java.util.List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion)protected voidreConnect()voidreset()voidsetReadOnly(boolean readOnly)voidsetSocketTimeout(int milliseconds)voidsyncNewState(Client oldCli)
-
-
-
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
-
conf
protected final Configuration conf
-
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 / primaryfailFast- 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
-
execute
public java.util.List<Completion> execute(ClientMessage message, Statement stmt) 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
-
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:
executePipelinein interfaceClient- 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:
readStreamingResultsin interfaceClient- Throws:
java.sql.SQLException
-
closePrepare
public void closePrepare(PrepareResultPacket prepare) throws java.sql.SQLException
- Specified by:
closePreparein interfaceClient- Throws:
java.sql.SQLException
-
abort
public void abort(java.util.concurrent.Executor executor) throws java.sql.SQLException
-
close
public void close() throws java.sql.SQLException
-
setReadOnly
public void setReadOnly(boolean readOnly) throws java.sql.SQLException- Specified by:
setReadOnlyin interfaceClient- Throws:
java.sql.SQLException
-
getSocketTimeout
public int getSocketTimeout()
- Specified by:
getSocketTimeoutin interfaceClient
-
setSocketTimeout
public void setSocketTimeout(int milliseconds) throws java.sql.SQLException- Specified by:
setSocketTimeoutin interfaceClient- Throws:
java.sql.SQLException
-
getWaitTimeout
public int getWaitTimeout()
- Specified by:
getWaitTimeoutin interfaceClient
-
getContext
public Context getContext()
- Specified by:
getContextin interfaceClient
-
getExceptionFactory
public ExceptionFactory getExceptionFactory()
- Specified by:
getExceptionFactoryin interfaceClient
-
getHostAddress
public HostAddress getHostAddress()
- Specified by:
getHostAddressin interfaceClient
-
-