Class MultiPrimaryReplicaClient
java.lang.Object
org.mariadb.jdbc.client.impl.MultiPrimaryClient
org.mariadb.jdbc.client.impl.MultiPrimaryReplicaClient
- All Implemented Interfaces:
AutoCloseable, Client
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
FieldsModifier and TypeFieldDescriptionprivate static final Loggerprivate longprivate longprivate Clientprivate Clientprivate booleanprotected longtimeout before retrying to reconnect failing hostFields inherited from class MultiPrimaryClient
closed, conf, currentClient, deniedListTimeout, denyList, lock -
Constructor Summary
ConstructorsConstructorDescriptionMultiPrimaryReplicaClient(Configuration conf, ClosableLock lock) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidAbort current connectionvoidclose()Close clientvoidclosePrepare(Prepare prepare) Close prepare commandexecute(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 resultGet connection contextGet connection exception factoryGet connection hostintget socket timeoutbooleanis current client writer or read-onlyvoidreadStreamingResults(List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) Read resultsprotected ClientReconnect connection, trying to continue transparently if possible.private voidvoidreset()Reset connectionvoidsetReadOnly(boolean readOnly) Switch to a writer/read-only connection, no effet on mono-connectionvoidsetSocketTimeout(int milliseconds) Set socket timeoutMethods inherited from class MultiPrimaryClient
connectHost, execute, execute, executeTransactionReplay, getSocketIp, isClosed, replayIfPossible, syncNewState
-
Field Details
-
logger
-
waitTimeout
protected long waitTimeouttimeout before retrying to reconnect failing host -
replicaClient
-
-
requestReadOnly
private boolean requestReadOnly -
nextTryReplica
private long nextTryReplica -
nextTryPrimary
private long nextTryPrimary
-
-
Constructor Details
-
MultiPrimaryReplicaClient
Constructor- Parameters:
conf- configurationlock- thread locker- Throws:
SQLException- if any error occurs
-
-
Method Details
-
reconnectIfNeeded
private void reconnectIfNeeded() -
reConnect
Reconnect connection, trying to continue transparently if possible. Different possible cases : replica fails, then 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- Returns:
- client connection
- Throws:
SQLException- if exception
-
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- Overrides:
executein classMultiPrimaryClient- 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- Overrides:
executePipelinein classMultiPrimaryClient- 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- Overrides:
readStreamingResultsin classMultiPrimaryClient- 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- Overrides:
closePreparein classMultiPrimaryClient- Parameters:
prepare- prepare command- Throws:
SQLException- if any error occurs
-
abort
Description copied from interface:ClientAbort current connection- Specified by:
abortin interfaceClient- Overrides:
abortin classMultiPrimaryClient- Parameters:
executor- executor- Throws:
SQLException- if any error occurs
-
close
Description copied from interface:ClientClose client- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceClient- Overrides:
closein classMultiPrimaryClient- 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- Overrides:
setReadOnlyin classMultiPrimaryClient- 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- Overrides:
getSocketTimeoutin classMultiPrimaryClient- Returns:
- socket timeout
-
setSocketTimeout
Description copied from interface:ClientSet socket timeout- Specified by:
setSocketTimeoutin interfaceClient- Overrides:
setSocketTimeoutin classMultiPrimaryClient- Parameters:
milliseconds- timeout- Throws:
SQLException- if any error occurs
-
getContext
Description copied from interface:ClientGet connection context- Specified by:
getContextin interfaceClient- Overrides:
getContextin classMultiPrimaryClient- Returns:
- connection context
-
getExceptionFactory
Description copied from interface:ClientGet connection exception factory- Specified by:
getExceptionFactoryin interfaceClient- Overrides:
getExceptionFactoryin classMultiPrimaryClient- Returns:
- connection exception factory
-
getHostAddress
Description copied from interface:ClientGet connection host- Specified by:
getHostAddressin interfaceClient- Overrides:
getHostAddressin classMultiPrimaryClient- Returns:
- connection host
-
isPrimary
public boolean isPrimary()Description copied from interface:Clientis current client writer or read-only- Specified by:
isPrimaryin interfaceClient- Overrides:
isPrimaryin classMultiPrimaryClient- Returns:
- is primary
-
reset
public void reset()Description copied from interface:ClientReset connection- Specified by:
resetin interfaceClient- Overrides:
resetin classMultiPrimaryClient
-