Package org.mariadb.jdbc.client
Class MultiPrimaryReplicaClient
- java.lang.Object
-
- org.mariadb.jdbc.client.MultiPrimaryClient
-
- org.mariadb.jdbc.client.MultiPrimaryReplicaClient
-
- All Implemented Interfaces:
java.lang.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 Summary
Fields Modifier and Type Field Description private static Loggerloggerprivate longnextTryPrimaryprivate longnextTryReplicaprivate ClientprimaryClientprivate ClientreplicaClientprivate booleanrequestReadOnlyprotected longwaitTimeout-
Fields inherited from class org.mariadb.jdbc.client.MultiPrimaryClient
closed, conf, currentClient, deniedListTimeout, denyList, lock
-
-
Constructor Summary
Constructors Constructor Description MultiPrimaryReplicaClient(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)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)ContextgetContext()ExceptionFactorygetExceptionFactory()HostAddressgetHostAddress()intgetSocketTimeout()booleanisPrimary()voidreadStreamingResults(java.util.List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion)protected voidreConnect()Reconnect connection, trying to continue transparently if possible.private voidreconnectIfNeeded()voidreset()voidsetReadOnly(boolean readOnly)voidsetSocketTimeout(int milliseconds)-
Methods inherited from class org.mariadb.jdbc.client.MultiPrimaryClient
connectHost, execute, execute, executeTransactionReplay, getWaitTimeout, isClosed, syncNewState
-
-
-
-
Field Detail
-
logger
private static final Logger logger
-
waitTimeout
protected long waitTimeout
-
replicaClient
private Client replicaClient
-
primaryClient
private Client primaryClient
-
requestReadOnly
private boolean requestReadOnly
-
nextTryReplica
private long nextTryReplica
-
nextTryPrimary
private long nextTryPrimary
-
-
Constructor Detail
-
MultiPrimaryReplicaClient
public MultiPrimaryReplicaClient(Configuration conf, java.util.concurrent.locks.ReentrantLock lock) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
-
Method Detail
-
reconnectIfNeeded
private void reconnectIfNeeded()
-
reConnect
protected void reConnect() throws java.sql.SQLExceptionReconnect connection, trying to continue transparently if possible. Different cases. * replica fails => reconnect to replica or to master if no replica availableif reconnect succeed on replica / use master, no problem, continuing without interruption // if reconnect primary, then replay transaction / throw exception if was in transaction.
- Overrides:
reConnectin classMultiPrimaryClient- Throws:
java.sql.SQLException- if exception
-
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:
executein interfaceClient- Overrides:
executein classMultiPrimaryClient- 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- Overrides:
executePipelinein classMultiPrimaryClient- 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- Overrides:
readStreamingResultsin classMultiPrimaryClient- Throws:
java.sql.SQLException
-
closePrepare
public void closePrepare(PrepareResultPacket prepare) throws java.sql.SQLException
- Specified by:
closePreparein interfaceClient- Overrides:
closePreparein classMultiPrimaryClient- Throws:
java.sql.SQLException
-
abort
public void abort(java.util.concurrent.Executor executor) throws java.sql.SQLException- Specified by:
abortin interfaceClient- Overrides:
abortin classMultiPrimaryClient- Throws:
java.sql.SQLException
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceClient- Overrides:
closein classMultiPrimaryClient
-
setReadOnly
public void setReadOnly(boolean readOnly) throws java.sql.SQLException- Specified by:
setReadOnlyin interfaceClient- Overrides:
setReadOnlyin classMultiPrimaryClient- Throws:
java.sql.SQLException
-
getSocketTimeout
public int getSocketTimeout()
- Specified by:
getSocketTimeoutin interfaceClient- Overrides:
getSocketTimeoutin classMultiPrimaryClient
-
setSocketTimeout
public void setSocketTimeout(int milliseconds) throws java.sql.SQLException- Specified by:
setSocketTimeoutin interfaceClient- Overrides:
setSocketTimeoutin classMultiPrimaryClient- Throws:
java.sql.SQLException
-
getContext
public Context getContext()
- Specified by:
getContextin interfaceClient- Overrides:
getContextin classMultiPrimaryClient
-
getExceptionFactory
public ExceptionFactory getExceptionFactory()
- Specified by:
getExceptionFactoryin interfaceClient- Overrides:
getExceptionFactoryin classMultiPrimaryClient
-
getHostAddress
public HostAddress getHostAddress()
- Specified by:
getHostAddressin interfaceClient- Overrides:
getHostAddressin classMultiPrimaryClient
-
isPrimary
public boolean isPrimary()
- Specified by:
isPrimaryin interfaceClient- Overrides:
isPrimaryin classMultiPrimaryClient
-
reset
public void reset()
- Specified by:
resetin interfaceClient- Overrides:
resetin classMultiPrimaryClient
-
-