public class AutoReadWriteSplittingPlugin extends ReadWriteSplittingPlugin
Routing can be overridden using SQL comment hints:
/*@reader* / — force query to reader/*@writer* / — force query to writer/*@keep* / — run on the current connection without re-routingRequires the sqlParser plugin to be loaded before this plugin.
Connection routing is not changed while a transaction is in progress: a transaction
keeps running against the connection it started on (so a read-only transaction started
on a reader stays on the reader, and a write transaction stays on the writer).
| Modifier and Type | Field and Description |
|---|---|
static AwsWrapperProperty |
LOAD_BALANCING_INCLUDE_WRITER |
static AwsWrapperProperty |
QUERY_LEVEL_LOAD_BALANCING |
hosts, READER_HOST_SELECTOR_STRATEGY, readerSelectorStrategy, VERIFY_INITIAL_CONNECTION_ROLE, verifyInitialConnectionRoleCACHED_READER_KEEP_ALIVE_TIMEOUT, hostListProviderService, inReadWriteSplit, isReaderConnFromInternalPool, isWriterConnFromInternalPool, pluginService, properties, readerCacheItem, readerHostSpec, writerConnection, writerHostSpec| Constructor and Description |
|---|
AutoReadWriteSplittingPlugin(PluginService pluginService,
@NonNull java.util.Properties properties) |
| Modifier and Type | Method and Description |
|---|---|
<T,E extends java.lang.Exception> |
execute(java.lang.Class<T> resultClass,
java.lang.Class<E> exceptionClass,
java.lang.Object methodInvokeOn,
java.lang.String methodName,
JdbcCallable<T,E> jdbcMethodFunc,
java.lang.Object[] args) |
java.util.Set<java.lang.String> |
getSubscribedMethods() |
void |
releaseResources()
An object that implements this interface should release all acquired resources assuming it may
be disposed at any time.
|
protected void |
switchToBalancedReader()
Selects a balancing target for a read query and switches the current connection to it.
|
closeReaderIfNecessary, connect, getReaderHostCandidates, getSnapshotState, initializeReaderConnection, initializeWriterConnection, isReader, isWriter, openNewReaderConnection, refreshAndStoreTopology, shouldUpdateReaderConnection, shouldUpdateWriterConnectioncloseReaderConnectionIfIdle, closeWriterConnectionIfIdle, getKeepAliveTimeout, getReaderConnection, getReaderHostSpec, getWriterConnection, getWriterHostSpec, initHostProvider, isConnectionUsable, logAndThrowException, logAndThrowException, notifyConnectionChanged, setReaderConnection, setWriterConnection, switchConnectionIfRequired, switchCurrentConnectionToacceptsStrategy, forceConnect, getHostSpecByStrategy, getHostSpecByStrategy, notifyNodeListChangedpublic static final AwsWrapperProperty QUERY_LEVEL_LOAD_BALANCING
public static final AwsWrapperProperty LOAD_BALANCING_INCLUDE_WRITER
public AutoReadWriteSplittingPlugin(PluginService pluginService, @NonNull java.util.Properties properties)
public java.util.Set<java.lang.String> getSubscribedMethods()
getSubscribedMethods in interface ConnectionPlugingetSubscribedMethods in class AbstractReadWriteSplittingPluginpublic <T,E extends java.lang.Exception> T execute(java.lang.Class<T> resultClass,
java.lang.Class<E> exceptionClass,
java.lang.Object methodInvokeOn,
java.lang.String methodName,
JdbcCallable<T,E> jdbcMethodFunc,
java.lang.Object[] args)
throws E extends java.lang.Exception
execute in interface ConnectionPluginexecute in class AbstractReadWriteSplittingPluginE extends java.lang.Exceptionprotected void switchToBalancedReader()
throws java.sql.SQLException
The target is chosen with the configured readerHostSelectorStrategy. When
loadBalancingIncludeWriter is enabled, the writer instance is also eligible.
If no eligible target is available, or the selected target is already the current host,
the current connection is left in place. On connection failure the current connection is
kept as a fallback when it is still usable.
This method is confined to the Automatic Read/Write Splitting Plugin and does not change the behavior of the other read/write splitting plugins.
java.sql.SQLExceptionpublic void releaseResources()
CanReleaseResourcesCalling this method does NOT mean that an object is disposing and there won't be any further calls. An object should keep its functional state after calling this method.
releaseResources in interface CanReleaseResourcesreleaseResources in class AbstractReadWriteSplittingPlugin