Package org.mariadb.jdbc.client.impl
Class MultiPrimaryClient
- java.lang.Object
-
- org.mariadb.jdbc.client.impl.MultiPrimaryClient
-
- All Implemented Interfaces:
AutoCloseable,org.mariadb.jdbc.client.Client
- Direct Known Subclasses:
MultiPrimaryReplicaClient
public class MultiPrimaryClient extends Object implements org.mariadb.jdbc.client.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 booleanclosedis connections explicitly closedprotected Configurationconfconfigurationprotected org.mariadb.jdbc.client.ClientcurrentClientcurrent clientprotected longdeniedListTimeoutdenied timeoutprotected static ConcurrentMap<HostAddress,Long>denyListtemporary blacklisted hostsprotected ReentrantLocklockthread locker
-
Constructor Summary
Constructors Constructor Description MultiPrimaryClient(Configuration conf, ReentrantLock lock)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort(Executor executor)Abort current connectionvoidclose()Close clientvoidclosePrepare(Prepare prepare)Close prepare commandprotected org.mariadb.jdbc.client.ClientconnectHost(boolean readOnly, boolean failFast)Trying connecting server.List<org.mariadb.jdbc.client.Completion>execute(org.mariadb.jdbc.message.ClientMessage message, boolean canRedo)Send client message and read resultList<org.mariadb.jdbc.client.Completion>execute(org.mariadb.jdbc.message.ClientMessage message, Statement stmt, boolean canRedo)Send client message and read resultList<org.mariadb.jdbc.client.Completion>execute(org.mariadb.jdbc.message.ClientMessage message, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo)Send client message and read resultList<org.mariadb.jdbc.client.Completion>executePipeline(org.mariadb.jdbc.message.ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo)Send client messages pipelining and read resultprotected voidexecuteTransactionReplay(org.mariadb.jdbc.client.Client oldCli)Execute transaction replayorg.mariadb.jdbc.client.ContextgetContext()Get connection contextExceptionFactorygetExceptionFactory()Get connection exception factoryHostAddressgetHostAddress()Get connection hostintgetSocketTimeout()get socket timeoutbooleanisClosed()Is client closedbooleanisPrimary()is current client writer or read-onlyvoidreadStreamingResults(List<org.mariadb.jdbc.client.Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion)Read resultsprotected org.mariadb.jdbc.client.ClientreConnect()Connection loopprotected voidreplayIfPossible(org.mariadb.jdbc.client.Client oldClient, boolean canRedo)Execute transaction replay if in transaction and configured for it, throw an exception if notvoidreset()Reset connectionvoidsetReadOnly(boolean readOnly)Switch to a writer/read-only connection, no effet on mono-connectionvoidsetSocketTimeout(int milliseconds)Set socket timeoutvoidsyncNewState(org.mariadb.jdbc.client.Client oldCli)Synchronized previous and new client states.
-
-
-
Field Detail
-
denyList
protected static final ConcurrentMap<HostAddress,Long> denyList
temporary blacklisted hosts
-
deniedListTimeout
protected final long deniedListTimeout
denied timeout
-
conf
protected final Configuration conf
configuration
-
closed
protected boolean closed
is connections explicitly closed
-
lock
protected final ReentrantLock lock
thread locker
-
currentClient
protected org.mariadb.jdbc.client.Client currentClient
current client
-
-
Constructor Detail
-
MultiPrimaryClient
public MultiPrimaryClient(Configuration conf, ReentrantLock lock) throws SQLException
Constructor- Parameters:
conf- configurationlock- thread locker- Throws:
SQLException- if fail to connect
-
-
Method Detail
-
connectHost
protected org.mariadb.jdbc.client.Client connectHost(boolean readOnly, boolean failFast) throws SQLExceptionTrying 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 denied server- Returns:
- a valid connection client
- Throws:
SQLException- if not succeed to create a connection.
-
reConnect
protected org.mariadb.jdbc.client.Client reConnect() throws SQLExceptionConnection loop- Returns:
- client connection
- Throws:
SQLException- if fail to connect
-
replayIfPossible
protected void replayIfPossible(org.mariadb.jdbc.client.Client oldClient, boolean canRedo) throws SQLExceptionExecute transaction replay if in transaction and configured for it, throw an exception if not- Parameters:
oldClient- previous clientcanRedo- if command can be redo even if not in transaction- Throws:
SQLException- if not able to replay
-
executeTransactionReplay
protected void executeTransactionReplay(org.mariadb.jdbc.client.Client oldCli) throws SQLExceptionExecute transaction replay- Parameters:
oldCli- previous client- Throws:
SQLException- if not able to replay
-
syncNewState
public void syncNewState(org.mariadb.jdbc.client.Client oldCli) throws SQLExceptionSynchronized previous and new client states.- Parameters:
oldCli- previous client- Throws:
SQLException- if error occurs
-
execute
public List<org.mariadb.jdbc.client.Completion> execute(org.mariadb.jdbc.message.ClientMessage message, boolean canRedo) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.ClientSend client message and read result- Specified by:
executein interfaceorg.mariadb.jdbc.client.Client- Parameters:
message- client messagecanRedo- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException- if execution fails
-
execute
public List<org.mariadb.jdbc.client.Completion> execute(org.mariadb.jdbc.message.ClientMessage message, Statement stmt, boolean canRedo) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.ClientSend client message and read result- Specified by:
executein interfaceorg.mariadb.jdbc.client.Client- Parameters:
message- client messagestmt- statementcanRedo- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException- if execution fails
-
execute
public List<org.mariadb.jdbc.client.Completion> execute(org.mariadb.jdbc.message.ClientMessage message, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.ClientSend client message and read result- Specified by:
executein interfaceorg.mariadb.jdbc.client.Client- Parameters:
message- client messagestmt- statementfetchSize- fetch sizemaxRows- maximum number of rows. 0 = allresultSetConcurrency- concurrencyresultSetType- result-set typecloseOnCompletion- close statement on completioncanRedo- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException- if any error occurs
-
executePipeline
public List<org.mariadb.jdbc.client.Completion> executePipeline(org.mariadb.jdbc.message.ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.ClientSend client messages pipelining and read result- Specified by:
executePipelinein interfaceorg.mariadb.jdbc.client.Client- Parameters:
messages- client messagestmt- statementfetchSize- fetch sizemaxRows- maximum number of rows. 0 = allresultSetConcurrency- concurrencyresultSetType- result-set typecloseOnCompletion- close statement on completioncanRedo- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException- if any error occurs
-
readStreamingResults
public void readStreamingResults(List<org.mariadb.jdbc.client.Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.ClientRead results- Specified by:
readStreamingResultsin interfaceorg.mariadb.jdbc.client.Client- Parameters:
completions- List that will have the new resultsfetchSize- fetch sizemaxRows- maximum number of rows. 0 = allresultSetConcurrency- concurrencyresultSetType- result-set typecloseOnCompletion- close statement on completion- Throws:
SQLException- if any error occurs
-
closePrepare
public void closePrepare(Prepare prepare) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.ClientClose prepare command- Specified by:
closePreparein interfaceorg.mariadb.jdbc.client.Client- Parameters:
prepare- prepare command- Throws:
SQLException- if any error occurs
-
abort
public void abort(Executor executor) throws SQLException
Description copied from interface:org.mariadb.jdbc.client.ClientAbort current connection- Specified by:
abortin interfaceorg.mariadb.jdbc.client.Client- Parameters:
executor- executor- Throws:
SQLException- if any error occurs
-
close
public void close() throws SQLExceptionDescription copied from interface:org.mariadb.jdbc.client.ClientClose client- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceorg.mariadb.jdbc.client.Client- Throws:
SQLException- if any error occurs
-
setReadOnly
public void setReadOnly(boolean readOnly) throws SQLExceptionDescription copied from interface:org.mariadb.jdbc.client.ClientSwitch to a writer/read-only connection, no effet on mono-connection- Specified by:
setReadOnlyin interfaceorg.mariadb.jdbc.client.Client- Parameters:
readOnly- must use read-only connection- Throws:
SQLException- if any error occurs
-
getSocketTimeout
public int getSocketTimeout()
Description copied from interface:org.mariadb.jdbc.client.Clientget socket timeout- Specified by:
getSocketTimeoutin interfaceorg.mariadb.jdbc.client.Client- Returns:
- socket timeout
-
setSocketTimeout
public void setSocketTimeout(int milliseconds) throws SQLExceptionDescription copied from interface:org.mariadb.jdbc.client.ClientSet socket timeout- Specified by:
setSocketTimeoutin interfaceorg.mariadb.jdbc.client.Client- Parameters:
milliseconds- timeout- Throws:
SQLException- if any error occurs
-
isClosed
public boolean isClosed()
Description copied from interface:org.mariadb.jdbc.client.ClientIs client closed- Specified by:
isClosedin interfaceorg.mariadb.jdbc.client.Client- Returns:
- close flag
-
getContext
public org.mariadb.jdbc.client.Context getContext()
Description copied from interface:org.mariadb.jdbc.client.ClientGet connection context- Specified by:
getContextin interfaceorg.mariadb.jdbc.client.Client- Returns:
- connection context
-
getExceptionFactory
public ExceptionFactory getExceptionFactory()
Description copied from interface:org.mariadb.jdbc.client.ClientGet connection exception factory- Specified by:
getExceptionFactoryin interfaceorg.mariadb.jdbc.client.Client- Returns:
- connection exception factory
-
getHostAddress
public HostAddress getHostAddress()
Description copied from interface:org.mariadb.jdbc.client.ClientGet connection host- Specified by:
getHostAddressin interfaceorg.mariadb.jdbc.client.Client- Returns:
- connection host
-
isPrimary
public boolean isPrimary()
Description copied from interface:org.mariadb.jdbc.client.Clientis current client writer or read-only- Specified by:
isPrimaryin interfaceorg.mariadb.jdbc.client.Client- Returns:
- is primary
-
reset
public void reset()
Description copied from interface:org.mariadb.jdbc.client.ClientReset connection- Specified by:
resetin interfaceorg.mariadb.jdbc.client.Client
-
-