Package org.mariadb.jdbc.client.impl
Class MultiPrimaryReplicaClient
- java.lang.Object
-
- org.mariadb.jdbc.client.impl.MultiPrimaryClient
-
- org.mariadb.jdbc.client.impl.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 Logger
logger
private long
nextTryPrimary
private long
nextTryReplica
private Client
primaryClient
private Client
replicaClient
private boolean
requestReadOnly
protected long
waitTimeout
timeout before retrying to reconnect failing host-
Fields inherited from class org.mariadb.jdbc.client.impl.MultiPrimaryClient
closed, conf, currentClient, deniedListTimeout, denyList, lock
-
-
Constructor Summary
Constructors Constructor Description MultiPrimaryReplicaClient(Configuration conf, ClosableLock lock)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort(java.util.concurrent.Executor executor)
Abort current connectionvoid
close()
Close clientvoid
closePrepare(Prepare prepare)
Close prepare commandjava.util.List<Completion>
execute(ClientMessage message, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo)
Send client message and read resultjava.util.List<Completion>
executePipeline(ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo)
Send client messages pipelining and read resultContext
getContext()
Get connection contextExceptionFactory
getExceptionFactory()
Get connection exception factoryHostAddress
getHostAddress()
Get connection hostint
getSocketTimeout()
get socket timeoutboolean
isPrimary()
is current client writer or read-onlyvoid
readStreamingResults(java.util.List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion)
Read resultsprotected Client
reConnect()
Reconnect connection, trying to continue transparently if possible.private void
reconnectIfNeeded()
void
reset()
Reset connectionvoid
setReadOnly(boolean readOnly)
Switch to a writer/read-only connection, no effet on mono-connectionvoid
setSocketTimeout(int milliseconds)
Set socket timeout-
Methods inherited from class org.mariadb.jdbc.client.impl.MultiPrimaryClient
connectHost, execute, execute, executeTransactionReplay, getSocketIp, isClosed, replayIfPossible, syncNewState
-
-
-
-
Field Detail
-
logger
private static final Logger logger
-
waitTimeout
protected long waitTimeout
timeout before retrying to reconnect failing host
-
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, ClosableLock lock) throws java.sql.SQLException
Constructor- Parameters:
conf
- configurationlock
- thread locker- Throws:
java.sql.SQLException
- if any error occurs
-
-
Method Detail
-
reconnectIfNeeded
private void reconnectIfNeeded()
-
reConnect
protected Client reConnect() throws java.sql.SQLException
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:
reConnect
in classMultiPrimaryClient
- Returns:
- client connection
- 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, boolean canRedo) throws java.sql.SQLException
Description copied from interface:Client
Send client message and read result- Specified by:
execute
in interfaceClient
- Overrides:
execute
in 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:
java.sql.SQLException
- if any error occurs
-
executePipeline
public java.util.List<Completion> executePipeline(ClientMessage[] messages, Statement stmt, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion, boolean canRedo) throws java.sql.SQLException
Description copied from interface:Client
Send client messages pipelining and read result- Specified by:
executePipeline
in interfaceClient
- Overrides:
executePipeline
in 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:
java.sql.SQLException
- if any error occurs
-
readStreamingResults
public void readStreamingResults(java.util.List<Completion> completions, int fetchSize, long maxRows, int resultSetConcurrency, int resultSetType, boolean closeOnCompletion) throws java.sql.SQLException
Description copied from interface:Client
Read results- Specified by:
readStreamingResults
in interfaceClient
- Overrides:
readStreamingResults
in 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:
java.sql.SQLException
- if any error occurs
-
closePrepare
public void closePrepare(Prepare prepare) throws java.sql.SQLException
Description copied from interface:Client
Close prepare command- Specified by:
closePrepare
in interfaceClient
- Overrides:
closePrepare
in classMultiPrimaryClient
- Parameters:
prepare
- prepare command- Throws:
java.sql.SQLException
- if any error occurs
-
abort
public void abort(java.util.concurrent.Executor executor) throws java.sql.SQLException
Description copied from interface:Client
Abort current connection- Specified by:
abort
in interfaceClient
- Overrides:
abort
in classMultiPrimaryClient
- Parameters:
executor
- executor- Throws:
java.sql.SQLException
- if any error occurs
-
close
public void close() throws java.sql.SQLException
Description copied from interface:Client
Close client- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceClient
- Overrides:
close
in classMultiPrimaryClient
- Throws:
java.sql.SQLException
- if any error occurs
-
setReadOnly
public void setReadOnly(boolean readOnly) throws java.sql.SQLException
Description copied from interface:Client
Switch to a writer/read-only connection, no effet on mono-connection- Specified by:
setReadOnly
in interfaceClient
- Overrides:
setReadOnly
in classMultiPrimaryClient
- Parameters:
readOnly
- must use read-only connection- Throws:
java.sql.SQLException
- if any error occurs
-
getSocketTimeout
public int getSocketTimeout()
Description copied from interface:Client
get socket timeout- Specified by:
getSocketTimeout
in interfaceClient
- Overrides:
getSocketTimeout
in classMultiPrimaryClient
- Returns:
- socket timeout
-
setSocketTimeout
public void setSocketTimeout(int milliseconds) throws java.sql.SQLException
Description copied from interface:Client
Set socket timeout- Specified by:
setSocketTimeout
in interfaceClient
- Overrides:
setSocketTimeout
in classMultiPrimaryClient
- Parameters:
milliseconds
- timeout- Throws:
java.sql.SQLException
- if any error occurs
-
getContext
public Context getContext()
Description copied from interface:Client
Get connection context- Specified by:
getContext
in interfaceClient
- Overrides:
getContext
in classMultiPrimaryClient
- Returns:
- connection context
-
getExceptionFactory
public ExceptionFactory getExceptionFactory()
Description copied from interface:Client
Get connection exception factory- Specified by:
getExceptionFactory
in interfaceClient
- Overrides:
getExceptionFactory
in classMultiPrimaryClient
- Returns:
- connection exception factory
-
getHostAddress
public HostAddress getHostAddress()
Description copied from interface:Client
Get connection host- Specified by:
getHostAddress
in interfaceClient
- Overrides:
getHostAddress
in classMultiPrimaryClient
- Returns:
- connection host
-
isPrimary
public boolean isPrimary()
Description copied from interface:Client
is current client writer or read-only- Specified by:
isPrimary
in interfaceClient
- Overrides:
isPrimary
in classMultiPrimaryClient
- Returns:
- is primary
-
reset
public void reset()
Description copied from interface:Client
Reset connection- Specified by:
reset
in interfaceClient
- Overrides:
reset
in classMultiPrimaryClient
-
-