P - the concrete priority type (e.g., MonitoringConnectionPriority or
GdbMonitoringConnectionPriority). The type's toString() should return a stable
human-readable label for snapshot logging.public abstract class AbstractMonitoringConnectionHandler<P> extends java.lang.Object implements MonitoringConnectionHandler
MonitoringConnectionHandler that handles the connection-priority lifecycle
(accept, batch-accept, async upgrade, close). Concrete subclasses provide the priority-evaluation hooks
specific to their priority model (Aurora vs. Global Aurora).| Modifier and Type | Field and Description |
|---|---|
protected int |
currentPriorityIndex |
protected AtomicConnection |
monitoringConnection |
protected java.util.Properties |
monitoringProperties |
protected PluginService |
pluginService |
protected java.util.List<P> |
priorities |
protected TopologyUtils |
topologyUtils |
protected @Nullable HostSpec |
upgradeConnectedHost |
protected AtomicConnection |
upgradeConnection |
protected @Nullable java.util.concurrent.ExecutorService |
upgradeExecutor |
protected @Nullable java.util.concurrent.Future<?> |
upgradeFuture |
protected @Nullable java.lang.Runnable |
upgradeReadyNotifier |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractMonitoringConnectionHandler(AtomicConnection monitoringConnection,
PluginService pluginService,
TopologyUtils topologyUtils,
java.util.Properties monitoringProperties,
java.util.List<P> priorities,
@Nullable java.lang.Runnable upgradeReadyNotifier) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptConnection(java.sql.Connection conn,
boolean isWriter,
HostSpec hostSpec)
Called when a connection is offered to the handler (e.g., a writer connection found during panic mode).
|
@Nullable HostSpec |
acceptConnections(java.util.Map<HostSpec,AtomicConnection> connections,
@Nullable HostSpec writerHostSpec,
@Nullable java.util.List<HostSpec> topology)
Offers a batch of harvested connections (e.g., from node monitoring threads after panic mode resolves)
to the handler.
|
void |
attemptConnectionUpgrade(java.util.List<HostSpec> currentTopology)
Non-blocking attempt to upgrade the monitoring connection to a higher-priority node.
|
void |
close()
Cleans up resources: cancels pending upgrade attempts and closes any connections held by the handler.
|
protected static int |
effectiveIndex(int priorityIndex) |
protected abstract java.util.List<HostSpec> |
findHostsForPriority(int priorityIndex,
java.util.List<HostSpec> hosts)
|
protected java.util.List<java.util.List<HostSpec>> |
findUpgradeCandidates(java.util.List<HostSpec> hosts)
Returns candidates grouped by priority, with the highest priority bucket first.
|
protected static java.lang.String |
formatPriorityIndex(int index)
Formats a priority index for logging.
|
protected @Nullable java.util.List<Pair<java.lang.String,java.lang.Object>> |
getAdditionalSnapshotState()
Hook for subclasses to publish additional snapshot state (e.g., GDB primary region).
|
protected abstract int |
getPriorityIndex(HostSpec host,
boolean isWriter)
Returns the index into
priorities that the given host satisfies, or -1 if no priority
matches. |
java.util.List<Pair<java.lang.String,java.lang.Object>> |
getSnapshotState() |
protected abstract java.lang.String |
getUpgradeThreadName()
Returns the thread-name prefix used for the async upgrade executor (e.g.,
"atmu" or "gatmu"). |
protected final AtomicConnection monitoringConnection
protected final AtomicConnection upgradeConnection
protected final PluginService pluginService
protected final TopologyUtils topologyUtils
protected final java.util.Properties monitoringProperties
protected final java.util.List<P> priorities
protected final @Nullable java.lang.Runnable upgradeReadyNotifier
protected int currentPriorityIndex
protected volatile @Nullable java.util.concurrent.Future<?> upgradeFuture
protected volatile @Nullable HostSpec upgradeConnectedHost
protected @Nullable java.util.concurrent.ExecutorService upgradeExecutor
protected AbstractMonitoringConnectionHandler(AtomicConnection monitoringConnection, PluginService pluginService, TopologyUtils topologyUtils, java.util.Properties monitoringProperties, java.util.List<P> priorities, @Nullable java.lang.Runnable upgradeReadyNotifier)
protected abstract int getPriorityIndex(HostSpec host, boolean isWriter)
priorities that the given host satisfies, or -1 if no priority
matches. The lowest-index match wins.host - the host being consideredisWriter - whether the connection is to a writerprotected abstract java.util.List<HostSpec> findHostsForPriority(int priorityIndex, java.util.List<HostSpec> hosts)
protected abstract java.lang.String getUpgradeThreadName()
"atmu" or "gatmu").protected @Nullable java.util.List<Pair<java.lang.String,java.lang.Object>> getAdditionalSnapshotState()
protected static java.lang.String formatPriorityIndex(int index)
Integer.MAX_VALUE is shown as <none>
to avoid confusing users with a 10-digit number.protected static int effectiveIndex(int priorityIndex)
public boolean acceptConnection(java.sql.Connection conn,
boolean isWriter,
HostSpec hostSpec)
MonitoringConnectionHandleracceptConnection in interface MonitoringConnectionHandlerconn - the offered connectionisWriter - true if the connection is to a writer instancehostSpec - the host spec of the connectionpublic @Nullable HostSpec acceptConnections(java.util.Map<HostSpec,AtomicConnection> connections, @Nullable HostSpec writerHostSpec, @Nullable java.util.List<HostSpec> topology)
MonitoringConnectionHandlerThe handler determines each connection's role from the topology (the writer host is known) — readers are everything else. The handler may also use the host's region for region-aware priorities.
acceptConnections in interface MonitoringConnectionHandlerconnections - a map of host -> connection harvested from node threadswriterHostSpec - the host spec of the writer (if known)topology - the current topology, used for region/role contextpublic void attemptConnectionUpgrade(java.util.List<HostSpec> currentTopology)
MonitoringConnectionHandlerattemptConnectionUpgrade in interface MonitoringConnectionHandlercurrentTopology - the current cluster topologypublic void close()
MonitoringConnectionHandlerclose in interface MonitoringConnectionHandlerprotected java.util.List<java.util.List<HostSpec>> findUpgradeCandidates(java.util.List<HostSpec> hosts)
public java.util.List<Pair<java.lang.String,java.lang.Object>> getSnapshotState()
getSnapshotState in interface StateSnapshotProvider