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 java.util.concurrent.atomic.AtomicReference<java.sql.SQLException> |
fatalError |
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 @Nullable 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(@Nullable 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.
|
@Nullable 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(@Nullable 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 @Nullable java.util.List<HostSpec> |
getStoredHosts() |
protected boolean |
isInPanicMode() |
protected boolean |
isUnresolvableDueToMisconfiguration(java.lang.Throwable t)
Determines whether a connection failure is a permanent DNS-resolution failure caused by a
configuration problem: the instance template is the bare "?" placeholder (built only when the
connection host is not a recognized RDS endpoint and no clusterInstanceHostPattern was supplied),
and the underlying cause is an
UnknownHostException. |
void |
monitor()
Executes the monitoring loop for this monitor.
|
protected void |
nodeThreadConnectionCleanUp() |
protected @Nullable java.util.List<HostSpec> |
openAnyConnectionAndUpdateTopology() |
void |
processEvent(Event event)
Processes an event.
|
protected @Nullable java.util.List<HostSpec> |
queryForTopology(java.sql.Connection connection) |
protected void |
recordFatalError(java.sql.SQLException ex)
Records a non-recoverable configuration error detected by a node monitor and wakes any threads
waiting for a topology update so they can fail fast instead of blocking until the failover timeout.
|
protected void |
reset() |
void |
stop()
Stops the monitoring tasks for this monitor and closes all resources.
|
protected void |
submitNodeMonitorIfAbsent(HostSpec hostSpec,
@Nullable HostSpec baselineWriter,
boolean someRegionsInaccessible,
java.util.List<java.lang.Exception> exceptionList)
Submits a node-monitoring worker for
hostSpec unless one has already been submitted for that host. |
protected void |
throwIfFatalError()
Throws the recorded fatal error, if any, so that a thread waiting for a topology update fails fast
instead of blocking until the failover timeout.
|
protected void |
updateHostsAvailability(@NonNull java.util.List<HostSpec> hosts) |
protected void |
updateTopologyCache(@NonNull java.util.List<HostSpec> hosts) |
protected @Nullable 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 java.util.concurrent.atomic.AtomicReference<java.sql.SQLException> fatalError
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 @Nullable 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 @Nullable 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 @Nullable java.util.List<HostSpec> waitForTopologyUpdate(long timeoutMs) throws java.util.concurrent.TimeoutException, java.sql.SQLException
java.util.concurrent.TimeoutExceptionjava.sql.SQLExceptionprotected void throwIfFatalError()
throws java.sql.SQLException
java.sql.SQLExceptionprotected void recordFatalError(java.sql.SQLException ex)
protected boolean isUnresolvableDueToMisconfiguration(java.lang.Throwable t)
UnknownHostException. In that case the derived instance
endpoints can never resolve, so retrying until the failover timeout is pointless.protected @Nullable 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 void submitNodeMonitorIfAbsent(HostSpec hostSpec, @Nullable HostSpec baselineWriter, boolean someRegionsInaccessible, java.util.List<java.lang.Exception> exceptionList)
hostSpec unless one has already been submitted for that host.
Any SQLException raised while creating the worker is collected into exceptionList and the host
is left unsubmitted so it can be retried on a later cycle.protected java.lang.Runnable getNodeMonitoringWorker(HostSpec hostSpec, @Nullable HostSpec writerHostSpec, boolean someRegionsInaccessible) throws java.sql.SQLException
java.sql.SQLExceptionprotected @Nullable java.util.List<HostSpec> openAnyConnectionAndUpdateTopology()
protected HostSpec getInstanceTemplate(@Nullable 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(@Nullable java.sql.Connection connection)
protected @Nullable 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