public class ClusterTopologyMonitorImpl extends AbstractMonitor implements ClusterTopologyMonitor, StateSnapshotProvider
| Modifier and Type | Field and Description |
|---|---|
protected static int |
closeConnectionNetworkTimeoutMs |
protected java.lang.String |
clusterId |
protected java.util.Map<java.lang.String,java.lang.Boolean> |
completedOneCycle |
protected MonitoringConnectionHandler |
connectionHandler |
protected static int |
defaultConnectionTimeoutMs |
protected static int |
defaultSocketTimeoutMs |
protected static long |
highRefreshPeriodAfterPanicNano |
protected long |
highRefreshRateEndTimeNano |
protected long |
highRefreshRateNano |
protected java.util.function.Function<HostSpec,java.util.List<java.lang.Object>> |
hostSpecExtractor |
protected HostSpec |
initialHostSpec |
protected HostSpec |
instanceTemplate |
protected @Nullable HostSpec |
lastKnownWriterHostSpec
The last writer we believed to be the cluster's writer, retained even after
writerHostSpec is
cleared on errors. |
protected boolean |
logUnclosedConnections |
protected static java.lang.String |
MONITORING_PROPERTY_PREFIX |
protected AtomicConnection |
monitoringConnection |
protected java.util.Properties |
monitoringProperties |
protected static long |
monitorTerminationTimeoutSec |
protected static java.util.concurrent.Executor |
networkTimeoutExecutor |
protected ResourceLock |
nodeExecutorLock |
protected java.util.concurrent.ExecutorService |
nodeExecutorService |
protected java.util.concurrent.ConcurrentHashMap<HostSpec,AtomicConnection> |
nodeThreadsConnections |
protected java.util.concurrent.atomic.AtomicReference<java.util.List<HostSpec>> |
nodeThreadsLatestTopology |
protected java.util.concurrent.atomic.AtomicBoolean |
nodeThreadsStop |
protected java.util.concurrent.atomic.AtomicReference<HostSpec> |
nodeThreadsWriterHostSpec |
protected java.util.Properties |
properties |
protected static RdsUtils |
rdsHelper |
protected java.util.Map<java.lang.String,java.util.List<HostSpec>> |
readerTopologiesById |
protected long |
refreshRateNano |
protected java.util.concurrent.atomic.AtomicBoolean |
requestToUpdateTopology |
protected FullServicesContainer |
servicesContainer |
protected long |
stableTopologiesStartNano |
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Boolean> |
submittedNodes |
protected java.lang.Object |
topologyUpdated |
protected TopologyUtils |
topologyUtils |
protected java.util.concurrent.atomic.AtomicReference<HostSpec> |
writerHostSpec |
lastActivityTimestampNanos, monitorExecutor, state, stop, terminationTimeoutSec| Constructor and Description |
|---|
ClusterTopologyMonitorImpl(FullServicesContainer servicesContainer,
TopologyUtils topologyUtils,
java.lang.String clusterId,
HostSpec initialHostSpec,
java.util.Properties properties,
HostSpec instanceTemplate,
long refreshRateNano,
long highRefreshRateNano) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canDispose()
Defines whether this monitor can be disposed.
|
protected void |
checkForStableReaderTopologies() |
protected void |
clearTopologyCache() |
void |
close()
Closes all resources used by this monitor.
|
protected void |
closeConnection(@Nullable java.sql.Connection connection) |
protected void |
closeNodeMonitors() |
protected MonitoringConnectionHandler |
createConnectionHandler() |
protected void |
createNodeExecutorService() |
protected void |
delay(boolean useHighRefreshRate) |
protected @Nullable java.util.List<HostSpec> |
fetchTopologyAndUpdateCache(java.sql.Connection connection) |
protected java.util.List<HostSpec> |
filterHostsForNodeMonitoring(java.util.List<HostSpec> hosts)
Filters the list of hosts that should be used for node monitoring during panic mode.
|
java.util.List<HostSpec> |
forceRefresh(boolean verifyTopology,
long timeoutMs) |
protected MonitoringConnectionHandler |
getConnectionHandler()
Returns the connection handler, creating it lazily on first access.
|
protected HostSpec |
getInstanceTemplate(java.lang.String nodeId,
java.sql.Connection connection) |
protected java.lang.Runnable |
getNodeMonitoringWorker(HostSpec hostSpec,
@Nullable HostSpec writerHostSpec,
boolean someRegionsInaccessible) |
java.util.List<Pair<java.lang.String,java.lang.Object>> |
getSnapshotState() |
protected long |
getStableTopologiesDurationNano() |
protected java.util.List<HostSpec> |
getStoredHosts() |
protected boolean |
isInPanicMode() |
void |
monitor()
Executes the monitoring loop for this monitor.
|
protected void |
nodeThreadConnectionCleanUp() |
protected java.util.List<HostSpec> |
openAnyConnectionAndUpdateTopology() |
void |
processEvent(Event event)
Processes an event.
|
protected java.util.List<HostSpec> |
queryForTopology(java.sql.Connection connection) |
protected void |
reset() |
void |
stop()
Stops the monitoring tasks for this monitor and closes all resources.
|
protected void |
updateHostsAvailability(@NonNull java.util.List<HostSpec> hosts) |
protected void |
updateTopologyCache(@NonNull java.util.List<HostSpec> hosts) |
protected java.util.List<HostSpec> |
waitForTopologyUpdate(long timeoutMs) |
protected void |
wakeUpMonitoringLoop()
Wakes up the monitoring loop so it can process events (e.g., a completed connection upgrade)
immediately instead of waiting for the next refresh cycle.
|
getLastActivityTimestampNanos, getState, run, startclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetLastActivityTimestampNanos, getState, startprotected static final java.lang.String MONITORING_PROPERTY_PREFIX
protected static final java.util.concurrent.Executor networkTimeoutExecutor
protected static final RdsUtils rdsHelper
protected static final long monitorTerminationTimeoutSec
protected static final int closeConnectionNetworkTimeoutMs
protected static final int defaultConnectionTimeoutMs
protected static final int defaultSocketTimeoutMs
protected static final long highRefreshPeriodAfterPanicNano
protected final java.util.concurrent.atomic.AtomicReference<HostSpec> writerHostSpec
protected volatile @Nullable HostSpec lastKnownWriterHostSpec
writerHostSpec is
cleared on errors. Used by panic-mode node threads as a baseline for writer-change detection.protected AtomicConnection monitoringConnection
protected final java.lang.Object topologyUpdated
protected final java.util.concurrent.atomic.AtomicBoolean requestToUpdateTopology
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Boolean> submittedNodes
protected final ResourceLock nodeExecutorLock
protected final java.util.concurrent.atomic.AtomicBoolean nodeThreadsStop
protected final java.util.concurrent.atomic.AtomicReference<HostSpec> nodeThreadsWriterHostSpec
protected final java.util.concurrent.atomic.AtomicReference<java.util.List<HostSpec>> nodeThreadsLatestTopology
protected final java.util.concurrent.ConcurrentHashMap<HostSpec,AtomicConnection> nodeThreadsConnections
protected final java.util.Map<java.lang.String,java.util.List<HostSpec>> readerTopologiesById
protected final java.util.Map<java.lang.String,java.lang.Boolean> completedOneCycle
protected long stableTopologiesStartNano
protected java.util.function.Function<HostSpec,java.util.List<java.lang.Object>> hostSpecExtractor
protected final long refreshRateNano
protected final long highRefreshRateNano
protected final TopologyUtils topologyUtils
protected final FullServicesContainer servicesContainer
protected final java.util.Properties properties
protected final java.util.Properties monitoringProperties
protected final HostSpec initialHostSpec
protected final HostSpec instanceTemplate
protected java.util.concurrent.ExecutorService nodeExecutorService
protected long highRefreshRateEndTimeNano
protected java.lang.String clusterId
protected boolean logUnclosedConnections
protected MonitoringConnectionHandler connectionHandler
public ClusterTopologyMonitorImpl(FullServicesContainer servicesContainer, TopologyUtils topologyUtils, java.lang.String clusterId, HostSpec initialHostSpec, java.util.Properties properties, HostSpec instanceTemplate, long refreshRateNano, long highRefreshRateNano)
protected MonitoringConnectionHandler getConnectionHandler()
createConnectionHandler() is invoked.public boolean canDispose()
MonitorcanDispose in interface ClusterTopologyMonitorcanDispose in interface MonitorcanDispose in class AbstractMonitorpublic java.util.List<HostSpec> forceRefresh(boolean verifyTopology, long timeoutMs) throws java.sql.SQLException, java.util.concurrent.TimeoutException
forceRefresh in interface ClusterTopologyMonitorjava.sql.SQLExceptionjava.util.concurrent.TimeoutExceptionprotected java.util.List<HostSpec> waitForTopologyUpdate(long timeoutMs) throws java.util.concurrent.TimeoutException
java.util.concurrent.TimeoutExceptionprotected java.util.List<HostSpec> getStoredHosts()
public void stop()
Monitorstop in interface Monitorstop in class AbstractMonitorpublic void close()
MonitorMonitor.stop().close in interface Monitorclose in class AbstractMonitorpublic void monitor()
throws java.lang.Exception
MonitorMonitor.start(). Additionally, the monitoring loop should regularly update the last
activity timestamp so that the MonitorService can detect whether the monitor is stuck or not.protected void checkForStableReaderTopologies()
protected void reset()
public void processEvent(Event event)
EventSubscriberEventPublisher.subscribe(software.amazon.jdbc.util.events.EventSubscriber, java.util.Set<java.lang.Class<? extends software.amazon.jdbc.util.events.Event>>).processEvent in interface EventSubscriberevent - the event to process.protected void nodeThreadConnectionCleanUp()
protected void closeNodeMonitors()
protected void createNodeExecutorService()
protected MonitoringConnectionHandler createConnectionHandler()
protected void wakeUpMonitoringLoop()
protected boolean isInPanicMode()
protected java.util.List<HostSpec> filterHostsForNodeMonitoring(java.util.List<HostSpec> hosts)
hosts - the full list of hosts from the topologyprotected java.lang.Runnable getNodeMonitoringWorker(HostSpec hostSpec, @Nullable HostSpec writerHostSpec, boolean someRegionsInaccessible) throws java.sql.SQLException
java.sql.SQLExceptionprotected java.util.List<HostSpec> openAnyConnectionAndUpdateTopology()
protected HostSpec getInstanceTemplate(java.lang.String nodeId, java.sql.Connection connection) throws java.sql.SQLException
java.sql.SQLExceptionprotected void closeConnection(@Nullable java.sql.Connection connection)
protected void delay(boolean useHighRefreshRate)
throws java.lang.InterruptedException
java.lang.InterruptedExceptionprotected @Nullable java.util.List<HostSpec> fetchTopologyAndUpdateCache(java.sql.Connection connection)
protected java.util.List<HostSpec> queryForTopology(java.sql.Connection connection) throws java.sql.SQLException
java.sql.SQLExceptionprotected void updateHostsAvailability(@NonNull java.util.List<HostSpec> hosts)
protected void updateTopologyCache(@NonNull java.util.List<HostSpec> hosts)
protected void clearTopologyCache()
protected long getStableTopologiesDurationNano()
public java.util.List<Pair<java.lang.String,java.lang.Object>> getSnapshotState()
getSnapshotState in interface StateSnapshotProvider