public class ClusterTopologyMonitorImpl extends AbstractMonitor implements ClusterTopologyMonitor
| Modifier and Type | Field and Description |
|---|---|
protected static int |
closeConnectionNetworkTimeoutMs |
protected java.lang.String |
clusterId |
protected HostSpec |
clusterInstanceTemplate |
protected ConnectionService |
connectionService |
protected static int |
defaultConnectionTimeoutMs |
protected static int |
defaultSocketTimeoutMs |
protected static int |
defaultTopologyQueryTimeoutMs |
protected static long |
highRefreshPeriodAfterPanicNano |
protected long |
highRefreshRateEndTimeNano |
protected long |
highRefreshRateNano |
protected HostListProviderService |
hostListProviderService |
protected java.util.concurrent.atomic.AtomicLong |
ignoreNewTopologyRequestsEndTimeNano |
protected static long |
ignoreTopologyRequestNano |
protected HostSpec |
initialHostSpec |
protected boolean |
isVerifiedWriterConnection |
protected static java.lang.String |
MONITORING_PROPERTY_PREFIX |
protected java.util.concurrent.atomic.AtomicReference<java.sql.Connection> |
monitoringConnection |
protected java.util.Properties |
monitoringProperties |
protected static long |
monitorTerminationTimeoutSec |
protected static java.util.concurrent.Executor |
networkTimeoutExecutor |
protected java.util.concurrent.locks.ReentrantLock |
nodeExecutorLock |
protected java.util.concurrent.ExecutorService |
nodeExecutorService |
protected java.lang.String |
nodeIdQuery |
protected java.util.concurrent.atomic.AtomicReference<java.util.List<HostSpec>> |
nodeThreadsLatestTopology |
protected java.util.concurrent.atomic.AtomicReference<java.sql.Connection> |
nodeThreadsReaderConnection |
protected java.util.concurrent.atomic.AtomicBoolean |
nodeThreadsStop |
protected java.util.concurrent.atomic.AtomicReference<java.sql.Connection> |
nodeThreadsWriterConnection |
protected java.util.concurrent.atomic.AtomicReference<HostSpec> |
nodeThreadsWriterHostSpec |
protected java.util.Properties |
properties |
protected static RdsUtils |
rdsHelper |
protected long |
refreshRateNano |
protected java.util.concurrent.atomic.AtomicBoolean |
requestToUpdateTopology |
protected StorageService |
storageService |
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Boolean> |
submittedNodes |
protected java.lang.String |
topologyQuery |
protected java.lang.Object |
topologyUpdated |
protected java.util.concurrent.atomic.AtomicReference<HostSpec> |
writerHostSpec |
protected java.lang.String |
writerTopologyQuery |
lastActivityTimestampNanos, monitorExecutor, state, stop, terminationTimeoutSec| Constructor and Description |
|---|
ClusterTopologyMonitorImpl(java.lang.String clusterId,
StorageService storageService,
ConnectionService connectionService,
HostSpec initialHostSpec,
java.util.Properties properties,
HostListProviderService hostListProviderService,
HostSpec clusterInstanceTemplate,
long refreshRateNano,
long highRefreshRateNano,
java.lang.String topologyQuery,
java.lang.String writerTopologyQuery,
java.lang.String nodeIdQuery) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canDispose()
Defines whether this monitor can be disposed.
|
void |
close()
Closes all resources used by this monitor.
|
protected void |
closeConnection(@Nullable java.sql.Connection connection) |
protected HostSpec |
createHost(java.sql.ResultSet resultSet,
java.lang.String suggestedWriterNodeId) |
protected HostSpec |
createHost(java.lang.String nodeName,
boolean isWriter,
long weight,
java.sql.Timestamp lastUpdateTime) |
protected void |
createNodeExecutorService() |
protected void |
delay(boolean useHighRefreshRate) |
protected @Nullable java.util.List<HostSpec> |
fetchTopologyAndUpdateCache(java.sql.Connection connection) |
java.util.List<HostSpec> |
forceRefresh(boolean shouldVerifyWriter,
long timeoutMs) |
java.util.List<HostSpec> |
forceRefresh(@Nullable java.sql.Connection connection,
long timeoutMs) |
protected java.lang.String |
getHostEndpoint(java.lang.String nodeName) |
protected java.lang.String |
getNodeId(java.sql.Connection connection) |
protected java.lang.Runnable |
getNodeMonitoringWorker(HostSpec hostSpec,
@Nullable HostSpec writerHostSpec) |
protected java.lang.String |
getSuggestedWriterNodeId(java.sql.Connection connection) |
protected java.lang.String |
getWriterNodeId(java.sql.Connection connection) |
protected boolean |
isInPanicMode() |
void |
monitor()
Executes the monitoring loop for this monitor.
|
protected java.util.List<HostSpec> |
openAnyConnectionAndUpdateTopology() |
protected @Nullable java.util.List<HostSpec> |
processQueryResults(java.sql.ResultSet resultSet,
java.lang.String suggestedWriterNodeId) |
protected @Nullable java.util.List<HostSpec> |
queryForTopology(java.sql.Connection conn) |
void |
setClusterId(java.lang.String clusterId) |
protected void |
shutdownNodeExecutorService() |
void |
stop()
Stops the monitoring tasks for this monitor and closes all resources.
|
protected void |
updateTopologyCache(@NonNull java.util.List<HostSpec> hosts) |
protected java.util.List<HostSpec> |
waitTillTopologyGetsUpdated(long timeoutMs) |
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 defaultTopologyQueryTimeoutMs
protected static final int closeConnectionNetworkTimeoutMs
protected static final int defaultConnectionTimeoutMs
protected static final int defaultSocketTimeoutMs
protected static final long highRefreshPeriodAfterPanicNano
protected static final long ignoreTopologyRequestNano
protected final long refreshRateNano
protected final long highRefreshRateNano
protected final java.util.Properties properties
protected final java.util.Properties monitoringProperties
protected final HostSpec initialHostSpec
protected final StorageService storageService
protected final ConnectionService connectionService
protected final java.lang.String topologyQuery
protected final java.lang.String nodeIdQuery
protected final java.lang.String writerTopologyQuery
protected final HostListProviderService hostListProviderService
protected final HostSpec clusterInstanceTemplate
protected java.lang.String clusterId
protected final java.util.concurrent.atomic.AtomicReference<HostSpec> writerHostSpec
protected final java.util.concurrent.atomic.AtomicReference<java.sql.Connection> monitoringConnection
protected boolean isVerifiedWriterConnection
protected long highRefreshRateEndTimeNano
protected final java.lang.Object topologyUpdated
protected final java.util.concurrent.atomic.AtomicBoolean requestToUpdateTopology
protected final java.util.concurrent.atomic.AtomicLong ignoreNewTopologyRequestsEndTimeNano
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Boolean> submittedNodes
protected java.util.concurrent.ExecutorService nodeExecutorService
protected final java.util.concurrent.locks.ReentrantLock nodeExecutorLock
protected final java.util.concurrent.atomic.AtomicBoolean nodeThreadsStop
protected final java.util.concurrent.atomic.AtomicReference<java.sql.Connection> nodeThreadsWriterConnection
protected final java.util.concurrent.atomic.AtomicReference<HostSpec> nodeThreadsWriterHostSpec
protected final java.util.concurrent.atomic.AtomicReference<java.sql.Connection> nodeThreadsReaderConnection
protected final java.util.concurrent.atomic.AtomicReference<java.util.List<HostSpec>> nodeThreadsLatestTopology
public ClusterTopologyMonitorImpl(java.lang.String clusterId,
StorageService storageService,
ConnectionService connectionService,
HostSpec initialHostSpec,
java.util.Properties properties,
HostListProviderService hostListProviderService,
HostSpec clusterInstanceTemplate,
long refreshRateNano,
long highRefreshRateNano,
java.lang.String topologyQuery,
java.lang.String writerTopologyQuery,
java.lang.String nodeIdQuery)
public boolean canDispose()
MonitorcanDispose in interface ClusterTopologyMonitorcanDispose in interface MonitorcanDispose in class AbstractMonitorpublic void setClusterId(java.lang.String clusterId)
setClusterId in interface ClusterTopologyMonitorpublic java.util.List<HostSpec> forceRefresh(boolean shouldVerifyWriter, long timeoutMs) throws java.sql.SQLException, java.util.concurrent.TimeoutException
forceRefresh in interface ClusterTopologyMonitorjava.sql.SQLExceptionjava.util.concurrent.TimeoutExceptionpublic java.util.List<HostSpec> forceRefresh(@Nullable java.sql.Connection connection, long timeoutMs) throws java.sql.SQLException, java.util.concurrent.TimeoutException
forceRefresh in interface ClusterTopologyMonitorjava.sql.SQLExceptionjava.util.concurrent.TimeoutExceptionprotected java.util.List<HostSpec> waitTillTopologyGetsUpdated(long timeoutMs) throws java.util.concurrent.TimeoutException
java.util.concurrent.TimeoutExceptionpublic void stop()
Monitorstop in interface Monitorstop in class AbstractMonitorpublic void close()
MonitorMonitor.stop().close in interface Monitorclose in class AbstractMonitorpublic void monitor()
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 shutdownNodeExecutorService()
protected void createNodeExecutorService()
protected boolean isInPanicMode()
protected java.lang.Runnable getNodeMonitoringWorker(HostSpec hostSpec, @Nullable HostSpec writerHostSpec)
protected java.util.List<HostSpec> openAnyConnectionAndUpdateTopology()
protected java.lang.String getNodeId(java.sql.Connection connection)
protected 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 void updateTopologyCache(@NonNull java.util.List<HostSpec> hosts)
protected java.lang.String getWriterNodeId(java.sql.Connection connection)
throws java.sql.SQLException
java.sql.SQLExceptionprotected @Nullable java.util.List<HostSpec> queryForTopology(java.sql.Connection conn) throws java.sql.SQLException
java.sql.SQLExceptionprotected java.lang.String getSuggestedWriterNodeId(java.sql.Connection connection)
throws java.sql.SQLException
java.sql.SQLExceptionprotected @Nullable java.util.List<HostSpec> processQueryResults(java.sql.ResultSet resultSet, java.lang.String suggestedWriterNodeId) throws java.sql.SQLException
java.sql.SQLExceptionprotected HostSpec createHost(java.sql.ResultSet resultSet, java.lang.String suggestedWriterNodeId) throws java.sql.SQLException
java.sql.SQLExceptionprotected HostSpec createHost(java.lang.String nodeName, boolean isWriter, long weight, java.sql.Timestamp lastUpdateTime)
protected java.lang.String getHostEndpoint(java.lang.String nodeName)