Class MultiPrimaryClient
java.lang.Object
org.mariadb.jdbc.client.impl.MultiPrimaryClient
- All Implemented Interfaces:
AutoCloseable, Client
- Direct Known Subclasses:
MultiPrimaryReplicaClient
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanis connections explicitly closedprotected final Configurationconfigurationprotected Clientcurrent clientprotected final longdenied timeoutprotected static final ConcurrentMap<HostAddress, Long> temporary blacklisted hostsprotected final ClosableLockthread lockerprivate static final Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAbort current connectionvoidclose()Close clientvoidclosePrepare(Prepare prepare) Close prepare commandprotected ClientconnectHost(boolean readOnly, boolean failFast) Trying connecting server.execute(ClientMessage message, boolean canRedo) Send client message and read resultexecute(ClientMessage message, Statement stmt, boolean canRedo) Send client message and read resultexecute(ClientMessage message, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) Send client message and read resultexecutePipeline(ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) Send client messages pipelining and read resultprotected voidexecuteTransactionReplay(Client oldCli) Execute transaction replayGet connection contextGet connection exception factoryGet connection hostGet current socket IP or null (for Pipe / unix socket)intget socket timeoutbooleanisClosed()Is client closedbooleanis current client writer or read-onlyvoidreadStreamingResults(List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) Read resultsprotected ClientConnection loopprotected voidreplayIfPossible(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(Client oldCli) Synchronized previous and new client states.
-
Field Details
-
denyList
temporary blacklisted hosts -
logger
-
deniedListTimeout
protected final long deniedListTimeoutdenied timeout -
conf
configuration -
lock
thread locker -
closed
protected boolean closedis connections explicitly closed -
currentClient
current client
-
-
Constructor Details
-
MultiPrimaryClient
Constructor- Parameters:
conf- configurationlock- thread locker- Throws:
SQLException- if fail to connect
-
-
Method Details
-
connectHost
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 denied server- Returns:
- a valid connection client
- Throws:
SQLException- if not succeed to create a connection.
-
reConnect
Connection loop- Returns:
- client connection
- Throws:
SQLException- if fail to connect
-
replayIfPossible
Execute 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
Execute transaction replay- Parameters:
oldCli- previous client- Throws:
SQLException- if not able to replay
-
syncNewState
Synchronized previous and new client states.- Parameters:
oldCli- previous client- Throws:
SQLException- if error occurs
-
execute
Description copied from interface:ClientSend client message and read result- Specified by:
executein interfaceClient- Parameters:
message- client messagecanRedo- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException- if execution fails
-
execute
public List<Completion> execute(ClientMessage message, Statement stmt, boolean canRedo) throws SQLException Description copied from interface:ClientSend client message and read result- Specified by:
executein interfaceClient- Parameters:
message- client messagestmt- statementcanRedo- can client message be redone in case of failover- Returns:
- results
- Throws:
SQLException- if execution fails
-
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:ClientSend client message and read result- Specified by:
executein interfaceClient- 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<Completion> executePipeline(ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) throws SQLException Description copied from interface:ClientSend client messages pipelining and read result- Specified by:
executePipelinein interfaceClient- 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<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) throws SQLException Description copied from interface:ClientRead results- Specified by:
readStreamingResultsin interfaceClient- 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
Description copied from interface:ClientClose prepare command- Specified by:
closePreparein interfaceClient- Parameters:
prepare- prepare command- Throws:
SQLException- if any error occurs
-
abort
Description copied from interface:ClientAbort current connection- Specified by:
abortin interfaceClient- Parameters:
executor- executor- Throws:
SQLException- if any error occurs
-
close
Description copied from interface:ClientClose client- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceClient- Throws:
SQLException- if any error occurs
-
setReadOnly
Description copied from interface:ClientSwitch to a writer/read-only connection, no effet on mono-connection- Specified by:
setReadOnlyin interfaceClient- Parameters:
readOnly- must use read-only connection- Throws:
SQLException- if any error occurs
-
getSocketTimeout
public int getSocketTimeout()Description copied from interface:Clientget socket timeout- Specified by:
getSocketTimeoutin interfaceClient- Returns:
- socket timeout
-
setSocketTimeout
Description copied from interface:ClientSet socket timeout- Specified by:
setSocketTimeoutin interfaceClient- Parameters:
milliseconds- timeout- Throws:
SQLException- if any error occurs
-
isClosed
-
getContext
Description copied from interface:ClientGet connection context- Specified by:
getContextin interfaceClient- Returns:
- connection context
-
getExceptionFactory
Description copied from interface:ClientGet connection exception factory- Specified by:
getExceptionFactoryin interfaceClient- Returns:
- connection exception factory
-
getHostAddress
Description copied from interface:ClientGet connection host- Specified by:
getHostAddressin interfaceClient- Returns:
- connection host
-
getSocketIp
Description copied from interface:ClientGet current socket IP or null (for Pipe / unix socket)- Specified by:
getSocketIpin interfaceClient- Returns:
- Socket current IP
-
isPrimary
-
reset
-