Class TcpDiscoverySpi
- java.lang.Object
-
- org.apache.ignite.spi.IgniteSpiAdapter
-
- org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi
-
- All Implemented Interfaces:
org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi
,DiscoverySpi
,IgniteSpi
@IgniteSpiMultipleInstancesSupport(true) @DiscoverySpiOrderSupport(true) @DiscoverySpiHistorySupport(true) @DiscoverySpiMutableCustomMessageSupport(true) public class TcpDiscoverySpi extends IgniteSpiAdapter implements org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi
Discovery SPI implementation that uses TCP/IP for node discovery.Nodes are organized in ring. So almost all network exchange (except few cases) is done across it.
If node is configured as client node (see
IgniteConfiguration.clientMode
) TcpDiscoverySpi starts in client mode as well. In this case node does not take its place in the ring, but it connects to random node in the ring (IP taken from IP finder configured) and use it as a router for discovery traffic. Therefore slow client node or its shutdown will not affect whole cluster. If TcpDiscoverySpi needs to be started in server mode regardless ofIgniteConfiguration.clientMode
,forceSrvMode
should be set to true.At startup SPI tries to send messages to random IP taken from
TcpDiscoveryIpFinder
about self start (stops when send succeeds) and then this info goes to coordinator. When coordinator processes join request and issues node added messages and all other nodes then receive info about new node.Failure Detection
Configuration defaults (see Configuration section below andIgniteConfiguration.getFailureDetectionTimeout()
) for details) are chosen to make possible for discovery SPI work reliably on most of hardware and virtual deployments, but this has made failure detection time worse.If it's needed to tune failure detection then it's highly recommended to do this using
IgniteConfiguration.setFailureDetectionTimeout(long)
. This failure timeout automatically controls the following parameters:getSocketTimeout()
,getAckTimeout()
,getMaxAckTimeout()
,getReconnectCount()
. If any of those parameters is set explicitly, then the failure timeout setting will be ignored. As an example, for stable low-latency networks the failure detection timeout may be set to ~120 ms.If it's required to perform advanced settings of failure detection and
IgniteConfiguration.getFailureDetectionTimeout()
is unsuitable then variousTcpDiscoverySpi
configuration parameters may be used. As an example, for stable low-latency networks the following more aggressive settings are recommended (which allows failure detection time ~200ms):- Socket timeout (see
setSocketTimeout(long)
) - 200ms - Message acknowledgement timeout (see
setAckTimeout(long)
) - 50ms
Configuration
Mandatory
There are no mandatory configuration parameters.Optional
The following configuration parameters are optional:- IP finder to share info about nodes IP addresses
(see
setIpFinder(TcpDiscoveryIpFinder)
). See the following IP finder implementations for details on configuration:
- Local address (see
setLocalAddress(String)
) - Local port to bind to (see
setLocalPort(int)
) - Local port range to try binding to if previous ports are in use
(see
setLocalPortRange(int)
) - Number of times node tries to (re)establish connection to another node
(see
setReconnectCount(int)
) - Network timeout (see
setNetworkTimeout(long)
) - Socket timeout (see
setSocketTimeout(long)
) - Message acknowledgement timeout (see
setAckTimeout(long)
) - Maximum message acknowledgement timeout (see
setMaxAckTimeout(long)
) - Join timeout (see
setJoinTimeout(long)
) - Thread priority for threads started by SPI (see
setThreadPriority(int)
) - IP finder clean frequency (see
setIpFinderCleanFrequency(long)
) - Statistics print frequency (see
setStatisticsPrintFrequency(long)
- Force server mode (see
setForceServerMode(boolean)
Java Example
TcpDiscoverySpi spi = new TcpDiscoverySpi(); TcpDiscoveryVmIpFinder finder = new GridTcpDiscoveryVmIpFinder(); spi.setIpFinder(finder); IgniteConfiguration cfg = new IgniteConfiguration(); // Override default discovery SPI. cfg.setDiscoverySpi(spi); // Start grid. Ignition.start(cfg);
Spring Example
TcpDiscoverySpi can be configured from Spring XML configuration file:<bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true"> ... <property name="discoverySpi"> <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> <property name="ipFinder"> <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder" /> </property> </bean> </property> ... </bean>
For information about Spring framework visit www.springframework.org- See Also:
DiscoverySpi
-
-
Field Summary
Fields Modifier and Type Field Description static String
ATTR_EXT_ADDRS
Node attribute that is mapped to node's external addresses (value is disc.tcp.ext-addrs).protected UUID
cfgNodeId
protected long
connRecoveryTimeout
Default connection recovery timeout in ms.static long
DFLT_ACK_TIMEOUT
Default timeout for receiving message acknowledgement in milliseconds (value is 5000ms).static long
DFLT_ACK_TIMEOUT_CLIENT
Default timeout for receiving message acknowledgement in milliseconds (value is 5000ms).static long
DFLT_CONNECTION_RECOVERY_TIMEOUT
Default connection recovery timeout in ms.static int
DFLT_DISCO_FAILED_CLIENT_RECONNECT_DELAY
static int
DFLT_DISCOVERY_CLIENT_RECONNECT_HISTORY_SIZE
static int
DFLT_DISCOVERY_METRICS_QNT_WARN
static long
DFLT_IP_FINDER_CLEAN_FREQ
Default IP finder clean frequency in milliseconds (value is 60,000ms).static long
DFLT_JOIN_TIMEOUT
Default timeout for joining topology (value is 0).static long
DFLT_MAX_ACK_TIMEOUT
Maximum ack timeout value for receiving message acknowledgement in milliseconds (value is 600,000ms).static long
DFLT_NETWORK_TIMEOUT
Default network timeout in milliseconds (value is 5000ms).static int
DFLT_NODE_IDS_HISTORY_SIZE
static int
DFLT_PORT
Default port to listen (value is 47500).static int
DFLT_PORT_RANGE
Default local port range (value is 100).static int
DFLT_RECONNECT_CNT
Default reconnect attempts count (value is 10).static long
DFLT_RECONNECT_DELAY
Default delay between attempts to connect to the cluster in milliseconds (value is 2000).static int
DFLT_SO_LINGER
Default SO_LINGER to set for socket, 0 means enabled with 0 timeout.static long
DFLT_SOCK_TIMEOUT
Default socket operations timeout in milliseconds (value is 5000ms).static long
DFLT_SOCK_TIMEOUT_CLIENT
Default socket operations timeout in milliseconds (value is 5000ms).static long
DFLT_STATS_PRINT_FREQ
Default statistics print frequency in milliseconds (value is 0ms).static int
DFLT_THREAD_PRI
Default value for thread priority (value is 10).static int
DFLT_THROTTLE_RECONNECT_RESET_TIMEOUT_INTERVAL
static int
DFLT_TOP_HISTORY_SIZE
Default size of topology snapshots history.protected DiscoverySpiDataExchange
exchange
Data exchange.protected long
gridStartTime
Start time of the very first grid node.protected org.apache.ignite.spi.discovery.tcp.TcpDiscoveryImpl
impl
protected CopyOnWriteArrayList<IgniteInClosure<Socket>>
incomeConnLsnrs
protected TcpDiscoveryIpFinder
ipFinder
IP finder.protected long
ipFinderCleanFreq
The frequency with which coordinator cleans IP finder and keeps it in the correct state, which means that coordinator unregisters addresses of the nodes that have left the topology and re-registries missing addresses.protected long
joinTimeout
Join timeout, in milliseconds.protected String
locAddr
Local address.protected InetAddress
locHost
Local host.protected org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode
locNode
Local node.protected Collection<InetSocketAddress>
locNodeAddrs
Internal and external addresses of local node.protected Map<String,Object>
locNodeAttrs
Local node attributes.protected IgniteProductVersion
locNodeVer
Local node version.protected int
locPort
Local port which node uses.protected int
locPortRange
Local port range.protected IgniteLogger
log
Logger.protected DiscoverySpiListener
lsnr
Grid discovery listener.protected DiscoveryMetricsProvider
metricsProvider
Metrics provider.protected long
metricsUpdateFreq
Metrics update messages issuing frequency.protected long
netTimeout
Network timeout.protected DiscoverySpiNodeAuthenticator
nodeAuth
Node authenticator.protected CopyOnWriteArrayList<IgniteInClosure<org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage>>
sndMsgLsnrs
protected IgniteSpiContext
spiCtx
protected boolean
sslEnable
SSL enable/disable flag.protected SSLSocketFactory
sslSockFactory
SSL socket factory.protected SSLServerSocketFactory
sslSrvSockFactory
SSL server socket factory.protected org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryStatistics
stats
Statistics.protected long
statsPrintFreq
Statistics print frequency.protected int
threadPri
Thread priority for all threads started by SPI.protected int
topHistSize
Size of topology snapshots history.-
Fields inherited from class org.apache.ignite.spi.IgniteSpiAdapter
ignite, igniteInstanceName
-
-
Constructor Summary
Constructors Constructor Description TcpDiscoverySpi()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addIncomeConnectionListener(IgniteInClosure<Socket> lsnr)
FOR TEST ONLY!!!void
addSendMessageListener(IgniteInClosure<org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage> lsnr)
FOR TEST ONLY!!!boolean
allNodesSupport(org.apache.ignite.internal.IgniteFeatures feature)
protected IgniteSpiException
authenticationFailedError(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAuthFailedMessage msg)
void
brakeConnection()
FOR TEST PURPOSE ONLY!protected IgniteSpiException
checkFailedError(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCheckFailedMessage msg)
void
clientReconnect()
boolean
clientReconnectSupported()
int
clientWorkerCount()
FOR TEST ONLY!!!@Nullable Serializable
consistentId()
Gets consistent ID.void
disconnect()
Tells discovery SPI to disconnect from topology.void
dumpDebugInfo()
Dumps debug info using configured logger.protected IgniteSpiException
duplicateIdError(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryDuplicateIdMessage msg)
protected boolean
ensured(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg)
void
failNode(UUID nodeId, @Nullable String warning)
Initiates failure of provided node.long
getAckTimeout()
Gets message acknowledgement timeout.AddressResolver
getAddressResolver()
Gets address resolver.long
getAvgMessageProcessingTime()
Gets avg message processing time.long
getConnectionRecoveryTimeout()
Gets timeout that defines how long server node would try to recovery connection.
SeesetConnectionRecoveryTimeout(long)
for details.UUID
getCoordinator()
Gets current coordinator.long
getCoordinatorSinceTimestamp()
Gets time local node has been coordinator since.long
getEffectiveSocketTimeout(boolean srvrOperation)
Gets effective or resulting socket timeout with considering failure detection timeoutlong
getGridStartTime()
Gets start time of the very first node in the grid.TcpDiscoveryIpFinder
getIpFinder()
Gets IP finder for IP addresses sharing and storing.long
getIpFinderCleanFrequency()
Gets frequency with which coordinator cleans IP finder and keeps it in the correct state, unregistering addresses of the nodes that have left the topology.String
getIpFinderFormatted()
GetsTcpDiscoveryIpFinder
(string representation).long
getJoinTimeout()
Get join timeout, in milliseconds.String
getLocalAddress()
Gets local address that was set to SPI withsetLocalAddress(String)
method.ClusterNode
getLocalNode()
Gets local node.UUID
getLocalNodeId()
Gets ID of the local node.int
getLocalPort()
Gets local TCP port SPI listens to.int
getLocalPortRange()
Gets local TCP port range.long
getMaxAckTimeout()
Gets maximum message acknowledgement timeout.long
getMaxMessageProcessingTime()
Gets max message processing time.int
getMessageWorkerQueueSize()
Gets message worker queue current size.long
getNetworkTimeout()
Gets network timeout.@Nullable ClusterNode
getNode(UUID nodeId)
Gets node by ID.ClusterNode
getNode0(UUID id)
long
getNodesFailed()
Gets failed nodes count.long
getNodesJoined()
Gets joined nodes count.long
getNodesLeft()
Gets left nodes count.long
getPendingMessagesDiscarded()
Gets pending messages discarded count.long
getPendingMessagesRegistered()
Gets pending messages registered count.Map<String,Integer>
getProcessedMessages()
Gets processed messages counts (grouped by type).Map<String,Integer>
getReceivedMessages()
Gets received messages counts (grouped by type).int
getReconnectCount()
Gets number of connection attempts.long
getReconnectDelay()
Gets the amount of time in milliseconds that node waits before retrying to (re)connect to the cluster.Collection<ClusterNode>
getRemoteNodes()
Gets collection of remote nodes in grid or empty collection if no remote nodes found.long
getSocketTimeout()
Gets socket timeout.int
getSoLinger()
Gets SO_LINGER timeout for socket.IgniteSpiContext
getSpiContext()
Gets SPI context.String
getSpiState()
Gets current SPI state.long
getStatisticsPrintFrequency()
Gets statistics print frequency.int
getThreadPriority()
Gets thread priority.long
getTopHistorySize()
int
getTotalProcessedMessages()
Gets total processed messages count.int
getTotalReceivedMessages()
Gets total received messages count.protected void
initializeImpl()
protected void
initLocalNode(int srvPort, boolean addExtAddrAttr)
Collection<Object>
injectables()
This method returns SPI internal instances that need to be injected as well.protected void
injectResources(Ignite ignite)
Inject resourcesboolean
isClientMode()
Whether or not discovery is started in client mode.boolean
isClientReconnectDisabled()
Iftrue
client does not try to reconnect after server detected client node failure.boolean
isForceServerMode()
Deprecated.Will be removed at 3.0.boolean
isLocalNodeCoordinator()
Checks whether local node is coordinator.boolean
knownNode(UUID nodeId)
protected Marshaller
marshaller()
protected void
onContextDestroyed0()
Method to be called in the beginning of onContextDestroyed() method.protected void
onContextInitialized0(IgniteSpiContext spiCtx)
Method to be called in the end of onContextInitialized method.protected void
onExchange(org.apache.ignite.spi.discovery.tcp.internal.DiscoveryDataPacket dataPacket, ClassLoader clsLdr)
protected Socket
openSocket(InetSocketAddress sockAddr, IgniteSpiOperationTimeoutHelper timeoutHelper)
protected Socket
openSocket(Socket sock, InetSocketAddress remAddr, IgniteSpiOperationTimeoutHelper timeoutHelper)
Connects to remote address sendingU.IGNITE_HEADER
when connection is established.boolean
pingNode(UUID nodeId)
Pings the remote node to see if it's alive.protected <T> T
readMessage(Socket sock, @Nullable InputStream in, long timeout)
Reads message from the socket limiting read time.protected int
readReceipt(Socket sock, long timeout)
Reads message delivery receipt from the socket.protected Collection<InetSocketAddress>
registeredAddresses()
Gets addresses registered in the IP finder, initializes addresses having no port (or 0 port) withDFLT_PORT
.void
removeIncomeConnectionListener(IgniteInClosure<Socket> lsnr)
FOR TEST ONLY!!!void
removeSendMessageListener(IgniteInClosure<org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage> lsnr)
FOR TEST ONLY!!!void
resolveCommunicationFailure(ClusterNode node, Exception err)
protected Collection<InetSocketAddress>
resolvedAddresses()
Resolves addresses registered in the IP finder, removes duplicates and local host address and returns the collection of.void
sendCustomEvent(DiscoverySpiCustomMessage msg)
Sends custom message across the ring.TcpDiscoverySpi
setAckTimeout(long ackTimeout)
Sets timeout for receiving acknowledgement for sent message.TcpDiscoverySpi
setAddressFilter(IgnitePredicate<InetSocketAddress> addressFilter)
Sets filter for IP addresses.void
setAddressResolver(AddressResolver addrRslvr)
Sets address resolver.void
setAuthenticator(DiscoverySpiNodeAuthenticator auth)
Sets discovery SPI node authenticator.void
setClientReconnectDisabled(boolean clientReconnectDisabled)
Sets client reconnect disabled flag.void
setConnectionRecoveryTimeout(long connRecoveryTimeout)
Sets timeout that defines how long server node would try to recovery connection.void
setDataExchange(DiscoverySpiDataExchange exchange)
Sets a handler for initial data exchange between Ignite nodes.TcpDiscoverySpi
setForceServerMode(boolean forceSrvMode)
Deprecated.Will be removed at 3.0.void
setInternalListener(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpiInternalListener lsnr)
For TESTING only.TcpDiscoverySpi
setIpFinder(TcpDiscoveryIpFinder ipFinder)
Sets IP finder for IP addresses sharing and storing.TcpDiscoverySpi
setIpFinderCleanFrequency(long ipFinderCleanFreq)
Sets IP finder clean frequency in milliseconds.TcpDiscoverySpi
setJoinTimeout(long joinTimeout)
Sets join timeout.void
setListener(@Nullable DiscoverySpiListener lsnr)
Sets a listener for discovery events.TcpDiscoverySpi
setLocalAddress(String locAddr)
Sets network addresses for the Discovery SPI.TcpDiscoverySpi
setLocalPort(int locPort)
Sets local port to listen to.TcpDiscoverySpi
setLocalPortRange(int locPortRange)
Range for local ports.TcpDiscoverySpi
setMaxAckTimeout(long maxAckTimeout)
Sets maximum timeout for receiving acknowledgement for sent message.void
setMetricsProvider(DiscoveryMetricsProvider metricsProvider)
Sets discovery metrics provider.TcpDiscoverySpi
setName(String name)
Sets SPI name.TcpDiscoverySpi
setNetworkTimeout(long netTimeout)
Sets maximum network timeout to use for network operations.void
setNodeAttributes(Map<String,Object> attrs, IgniteProductVersion ver)
Sets node attributes and node version which will be distributed in grid during join process.TcpDiscoverySpi
setReconnectCount(int reconCnt)
Number of times node tries to (re)establish connection to another node.TcpDiscoverySpi
setReconnectDelay(int reconDelay)
Sets the amount of time in milliseconds that node waits before retrying to (re)connect to the cluster.TcpDiscoverySpi
setSocketTimeout(long sockTimeout)
Sets socket operations timeout.void
setSoLinger(int soLinger)
Sets SO_LINGER to use for all created sockets.TcpDiscoverySpi
setStatisticsPrintFrequency(long statsPrintFreq)
Sets statistics print frequency.TcpDiscoverySpi
setThreadPriority(int threadPri)
Sets thread priority.TcpDiscoverySpi
setTopHistorySize(int topHistSize)
Sets size of topology snapshots history.void
simulateNodeFailure()
FOR TEST ONLY!!!void
spiStart(@Nullable String igniteInstanceName)
This method is called to start SPI.void
spiStop()
This method is called to stop SPI.protected void
startMessageProcess(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg)
boolean
supportsCommunicationFailureResolve()
String
toString()
void
waitForClientMessagePrecessed()
FOR TEST PURPOSE ONLY!protected void
writeToSocket(Socket sock, OutputStream out, org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg, long timeout)
Writes message to the socket.protected void
writeToSocket(Socket sock, org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg, byte[] data, long timeout)
Writes message to the socket.protected void
writeToSocket(Socket sock, org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg, long timeout)
Writes message to the socket.protected void
writeToSocket(ClusterNode node, Socket sock, OutputStream out, org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg, long timeout)
protected void
writeToSocket(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg, Socket sock, int res, long timeout)
Writes response to the socket.-
Methods inherited from class org.apache.ignite.spi.IgniteSpiAdapter
addTimeoutObject, assertParameter, checkConfigurationConsistency0, clientFailureDetectionTimeout, configInfo, createSpiAttributeName, failureDetectionTimeout, failureDetectionTimeoutEnabled, failureDetectionTimeoutEnabled, getConsistentAttributeNames, getExceptionRegistry, getName, getNodeAttributes, ignite, initFailureDetectionTimeout, isNodeStopping, onBeforeStart, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextInitialized, registerMBean, removeTimeoutObject, started, startInfo, startStopwatch, stopInfo, unregisterMBean
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.ignite.spi.IgniteSpi
getName, getNodeAttributes, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextInitialized
-
-
-
-
Field Detail
-
ATTR_EXT_ADDRS
public static final String ATTR_EXT_ADDRS
Node attribute that is mapped to node's external addresses (value is disc.tcp.ext-addrs).- See Also:
- Constant Field Values
-
DFLT_PORT_RANGE
public static final int DFLT_PORT_RANGE
Default local port range (value is 100).- See Also:
- Constant Field Values
-
DFLT_PORT
public static final int DFLT_PORT
Default port to listen (value is 47500).- See Also:
- Constant Field Values
-
DFLT_JOIN_TIMEOUT
public static final long DFLT_JOIN_TIMEOUT
Default timeout for joining topology (value is 0).- See Also:
- Constant Field Values
-
DFLT_NETWORK_TIMEOUT
public static final long DFLT_NETWORK_TIMEOUT
Default network timeout in milliseconds (value is 5000ms).- See Also:
- Constant Field Values
-
DFLT_THREAD_PRI
public static final int DFLT_THREAD_PRI
Default value for thread priority (value is 10).- See Also:
- Constant Field Values
-
DFLT_TOP_HISTORY_SIZE
public static final int DFLT_TOP_HISTORY_SIZE
Default size of topology snapshots history.- See Also:
- Constant Field Values
-
DFLT_SOCK_TIMEOUT
public static final long DFLT_SOCK_TIMEOUT
Default socket operations timeout in milliseconds (value is 5000ms).- See Also:
- Constant Field Values
-
DFLT_ACK_TIMEOUT
public static final long DFLT_ACK_TIMEOUT
Default timeout for receiving message acknowledgement in milliseconds (value is 5000ms).- See Also:
- Constant Field Values
-
DFLT_SOCK_TIMEOUT_CLIENT
public static final long DFLT_SOCK_TIMEOUT_CLIENT
Default socket operations timeout in milliseconds (value is 5000ms).- See Also:
- Constant Field Values
-
DFLT_ACK_TIMEOUT_CLIENT
public static final long DFLT_ACK_TIMEOUT_CLIENT
Default timeout for receiving message acknowledgement in milliseconds (value is 5000ms).- See Also:
- Constant Field Values
-
DFLT_RECONNECT_CNT
public static final int DFLT_RECONNECT_CNT
Default reconnect attempts count (value is 10).- See Also:
- Constant Field Values
-
DFLT_RECONNECT_DELAY
public static final long DFLT_RECONNECT_DELAY
Default delay between attempts to connect to the cluster in milliseconds (value is 2000).- See Also:
- Constant Field Values
-
DFLT_IP_FINDER_CLEAN_FREQ
public static final long DFLT_IP_FINDER_CLEAN_FREQ
Default IP finder clean frequency in milliseconds (value is 60,000ms).- See Also:
- Constant Field Values
-
DFLT_STATS_PRINT_FREQ
public static final long DFLT_STATS_PRINT_FREQ
Default statistics print frequency in milliseconds (value is 0ms).- See Also:
- Constant Field Values
-
DFLT_MAX_ACK_TIMEOUT
public static final long DFLT_MAX_ACK_TIMEOUT
Maximum ack timeout value for receiving message acknowledgement in milliseconds (value is 600,000ms).- See Also:
- Constant Field Values
-
DFLT_SO_LINGER
public static final int DFLT_SO_LINGER
Default SO_LINGER to set for socket, 0 means enabled with 0 timeout.- See Also:
- Constant Field Values
-
DFLT_CONNECTION_RECOVERY_TIMEOUT
public static final long DFLT_CONNECTION_RECOVERY_TIMEOUT
Default connection recovery timeout in ms.
-
DFLT_DISCOVERY_CLIENT_RECONNECT_HISTORY_SIZE
public static final int DFLT_DISCOVERY_CLIENT_RECONNECT_HISTORY_SIZE
-
DFLT_NODE_IDS_HISTORY_SIZE
public static final int DFLT_NODE_IDS_HISTORY_SIZE
-
DFLT_DISCO_FAILED_CLIENT_RECONNECT_DELAY
public static final int DFLT_DISCO_FAILED_CLIENT_RECONNECT_DELAY
-
DFLT_THROTTLE_RECONNECT_RESET_TIMEOUT_INTERVAL
public static final int DFLT_THROTTLE_RECONNECT_RESET_TIMEOUT_INTERVAL
-
DFLT_DISCOVERY_METRICS_QNT_WARN
public static final int DFLT_DISCOVERY_METRICS_QNT_WARN
-
locAddr
protected String locAddr
Local address.
-
ipFinder
protected TcpDiscoveryIpFinder ipFinder
IP finder.
-
netTimeout
protected long netTimeout
Network timeout.
-
joinTimeout
protected long joinTimeout
Join timeout, in milliseconds. Time to wait for joining. If node cannot connect to any address from the IP finder, the node continues to try to join during this timeout. If all addresses still do not respond, an exception will occur and the node will fail to start. If 0 is specified, it means wait forever.
-
threadPri
protected int threadPri
Thread priority for all threads started by SPI.
-
metricsUpdateFreq
protected long metricsUpdateFreq
Metrics update messages issuing frequency.
-
topHistSize
protected int topHistSize
Size of topology snapshots history.
-
connRecoveryTimeout
protected long connRecoveryTimeout
Default connection recovery timeout in ms.
-
lsnr
protected volatile DiscoverySpiListener lsnr
Grid discovery listener.
-
exchange
protected DiscoverySpiDataExchange exchange
Data exchange.
-
metricsProvider
protected DiscoveryMetricsProvider metricsProvider
Metrics provider.
-
locNodeVer
protected IgniteProductVersion locNodeVer
Local node version.
-
locNode
protected org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode locNode
Local node.
-
cfgNodeId
protected UUID cfgNodeId
-
locHost
protected InetAddress locHost
Local host.
-
locNodeAddrs
protected Collection<InetSocketAddress> locNodeAddrs
Internal and external addresses of local node.
-
gridStartTime
protected volatile long gridStartTime
Start time of the very first grid node.
-
stats
protected final org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryStatistics stats
Statistics.
-
locPort
protected int locPort
Local port which node uses.
-
locPortRange
protected int locPortRange
Local port range.
-
statsPrintFreq
protected long statsPrintFreq
Statistics print frequency.
-
ipFinderCleanFreq
protected long ipFinderCleanFreq
The frequency with which coordinator cleans IP finder and keeps it in the correct state, which means that coordinator unregisters addresses of the nodes that have left the topology and re-registries missing addresses.- See Also:
ServerImpl.IpFinderCleaner
-
nodeAuth
protected DiscoverySpiNodeAuthenticator nodeAuth
Node authenticator.
-
sslSrvSockFactory
protected SSLServerSocketFactory sslSrvSockFactory
SSL server socket factory.
-
sslSockFactory
protected SSLSocketFactory sslSockFactory
SSL socket factory.
-
sslEnable
protected boolean sslEnable
SSL enable/disable flag.
-
sndMsgLsnrs
protected final CopyOnWriteArrayList<IgniteInClosure<org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage>> sndMsgLsnrs
-
incomeConnLsnrs
protected final CopyOnWriteArrayList<IgniteInClosure<Socket>> incomeConnLsnrs
-
log
@LoggerResource protected IgniteLogger log
Logger.
-
impl
protected org.apache.ignite.spi.discovery.tcp.TcpDiscoveryImpl impl
-
spiCtx
protected IgniteSpiContext spiCtx
-
-
Method Detail
-
getSpiState
public String getSpiState()
Gets current SPI state.- Returns:
- Current SPI state.
-
getMessageWorkerQueueSize
public int getMessageWorkerQueueSize()
Gets message worker queue current size.- Returns:
- Message worker queue current size.
-
getCoordinator
public UUID getCoordinator()
Gets current coordinator.- Returns:
- Gets current coordinator.
-
getRemoteNodes
public Collection<ClusterNode> getRemoteNodes()
Gets collection of remote nodes in grid or empty collection if no remote nodes found.- Specified by:
getRemoteNodes
in interfaceDiscoverySpi
- Returns:
- Collection of remote nodes.
-
getNode
@Nullable public @Nullable ClusterNode getNode(UUID nodeId)
Gets node by ID.- Specified by:
getNode
in interfaceDiscoverySpi
- Parameters:
nodeId
- Node ID.- Returns:
- Node with given ID or
null
if node is not found.
-
getNode0
public ClusterNode getNode0(UUID id)
- Parameters:
id
- Id.- Returns:
- Cluster node instance with specified ID.
-
pingNode
public boolean pingNode(UUID nodeId)
Pings the remote node to see if it's alive.- Specified by:
pingNode
in interfaceDiscoverySpi
- Parameters:
nodeId
- Node Id.- Returns:
true
if node alive,false
otherwise.
-
disconnect
public void disconnect() throws IgniteSpiException
Tells discovery SPI to disconnect from topology. This is very close to callingIgniteSpi.spiStop()
with accounting that it is not a full stop, but disconnect due to segmentation.- Specified by:
disconnect
in interfaceDiscoverySpi
- Throws:
IgniteSpiException
- If any error occurs.
-
setAuthenticator
public void setAuthenticator(DiscoverySpiNodeAuthenticator auth)
Sets discovery SPI node authenticator. This method is called before SPI start() method.- Specified by:
setAuthenticator
in interfaceDiscoverySpi
- Parameters:
auth
- Discovery SPI authenticator.
-
sendCustomEvent
public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException
Sends custom message across the ring.- Specified by:
sendCustomEvent
in interfaceDiscoverySpi
- Parameters:
msg
- Custom message.- Throws:
IgniteException
- if failed to sent the event message.
-
failNode
public void failNode(UUID nodeId, @Nullable @Nullable String warning)
Initiates failure of provided node.- Specified by:
failNode
in interfaceDiscoverySpi
- Parameters:
nodeId
- Node ID.warning
- Warning to be shown on all cluster nodes.
-
dumpDebugInfo
public void dumpDebugInfo()
Dumps debug info using configured logger.
-
isClientMode
public boolean isClientMode()
Whether or not discovery is started in client mode.- Specified by:
isClientMode
in interfaceDiscoverySpi
- Returns:
true
if node is in client mode.
-
isForceServerMode
@Deprecated public boolean isForceServerMode()
Deprecated.Will be removed at 3.0.Iftrue
TcpDiscoverySpi will started in server mode regardless ofIgniteConfiguration.isClientMode()
- Returns:
- forceServerMode flag.
-
setForceServerMode
@IgniteSpiConfiguration(optional=true) @Deprecated public TcpDiscoverySpi setForceServerMode(boolean forceSrvMode)
Deprecated.Will be removed at 3.0.Sets force server mode flag.If
true
TcpDiscoverySpi is started in server mode regardless ofIgniteConfiguration.isClientMode()
.- Parameters:
forceSrvMode
- forceServerMode flag.- Returns:
this
for chaining.
-
isClientReconnectDisabled
public boolean isClientReconnectDisabled()
Iftrue
client does not try to reconnect after server detected client node failure.- Returns:
- Client reconnect disabled flag.
-
setClientReconnectDisabled
@IgniteSpiConfiguration(optional=true) public void setClientReconnectDisabled(boolean clientReconnectDisabled)
Sets client reconnect disabled flag.If
true
client does not try to reconnect after server detected client node failure.- Parameters:
clientReconnectDisabled
- Client reconnect disabled flag.
-
injectResources
@IgniteInstanceResource protected void injectResources(Ignite ignite)
Inject resources- Overrides:
injectResources
in classIgniteSpiAdapter
- Parameters:
ignite
- Ignite.
-
setLocalAddress
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setLocalAddress(String locAddr)
Sets network addresses for the Discovery SPI.If not provided, the value is resolved from
IgniteConfiguration.getLocalHost()
. If the latter is not set as well, the the node binds to all available IP addresses of an environment it's running on. If there is no a non-loopback address, thenInetAddress.getLocalHost()
is used.NOTE: You should initialize the
IgniteConfiguration.getLocalHost()
orgetLocalAddress()
parameter with the network interface that will be used for inter-node communication. Otherwise, the node can listen on multiple network addresses available in the environment and this can prolong node failures detection if some of the addresses are not reachable from other cluster nodes. For instance, if the node is bound to 3 network interfaces, it can take up to 'IgniteConfiguration.getFailureDetectionTimeout()
* 3 +getConnectionRecoveryTimeout()
' milliseconds for another node to detect a disconnect of the give node.- Parameters:
locAddr
- IP address.- Returns:
this
for chaining.
-
getLocalAddress
public String getLocalAddress()
Gets local address that was set to SPI withsetLocalAddress(String)
method.- Returns:
- local address.
-
setAddressResolver
@IgniteSpiConfiguration(optional=true) public void setAddressResolver(AddressResolver addrRslvr)
Sets address resolver.- Parameters:
addrRslvr
- Address resolver.
-
getAddressResolver
public AddressResolver getAddressResolver()
Gets address resolver.- Returns:
- Address resolver.
-
getReconnectCount
public int getReconnectCount()
Gets number of connection attempts.- Returns:
- Number of connection attempts.
-
setReconnectCount
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setReconnectCount(int reconCnt)
Number of times node tries to (re)establish connection to another node.Note that SPI implementation will increase
ackTimeout
by factor 2 on every retry.If not specified, default is
DFLT_RECONNECT_CNT
.When this property is explicitly set
IgniteConfiguration.getFailureDetectionTimeout()
is ignored.- Parameters:
reconCnt
- Number of retries during message sending.- Returns:
this
for chaining.- See Also:
setAckTimeout(long)
-
getReconnectDelay
public long getReconnectDelay()
Gets the amount of time in milliseconds that node waits before retrying to (re)connect to the cluster.- Returns:
- Delay between attempts to connect to the cluster in milliseconds.
-
setReconnectDelay
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setReconnectDelay(int reconDelay)
Sets the amount of time in milliseconds that node waits before retrying to (re)connect to the cluster.If not specified, default is
DFLT_RECONNECT_DELAY
.- Parameters:
reconDelay
- Delay between attempts to connect to the cluster in milliseconds.- Returns:
this
for chaining.
-
getMaxAckTimeout
public long getMaxAckTimeout()
Gets maximum message acknowledgement timeout.- Returns:
- Maximum message acknowledgement timeout.
-
setMaxAckTimeout
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setMaxAckTimeout(long maxAckTimeout)
Sets maximum timeout for receiving acknowledgement for sent message.If acknowledgement is not received within this timeout, sending is considered as failed and SPI tries to repeat message sending. Every time SPI retries messing sending, ack timeout will be increased. If no acknowledgement is received and
maxAckTimeout
is reached, then the process of message sending is considered as failed.If not specified, default is
DFLT_MAX_ACK_TIMEOUT
.Affected server nodes only.
When this property is explicitly set
IgniteConfiguration.getFailureDetectionTimeout()
is ignored.- Parameters:
maxAckTimeout
- Maximum acknowledgement timeout.- Returns:
this
for chaining.
-
getLocalPort
public int getLocalPort()
Gets local TCP port SPI listens to.- Returns:
- Local port range.
-
setLocalPort
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setLocalPort(int locPort)
Sets local port to listen to.If not specified, default is
DFLT_PORT
.Affected server nodes only.
- Parameters:
locPort
- Local port to bind.- Returns:
this
for chaining.
-
getLocalPortRange
public int getLocalPortRange()
Gets local TCP port range.- Returns:
- Local port range.
-
setLocalPortRange
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setLocalPortRange(int locPortRange)
Range for local ports. Local node will try to bind on first available port starting fromgetLocalPort()
up untilgetLocalPort()
+ locPortRange
. If port range value is 0, then implementation will try bind only to the port provided bysetLocalPort(int)
method and fail if binding to this port did not succeed.If not specified, default is
DFLT_PORT_RANGE
.Affected server nodes only.
- Parameters:
locPortRange
- Local port range to bind.- Returns:
this
for chaining.
-
getStatisticsPrintFrequency
public long getStatisticsPrintFrequency()
Gets statistics print frequency.- Returns:
- Statistics print frequency in milliseconds.
-
setStatisticsPrintFrequency
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setStatisticsPrintFrequency(long statsPrintFreq)
Sets statistics print frequency.If not set default value is
DFLT_STATS_PRINT_FREQ
. 0 indicates that no print is required. If value is greater than 0 and log is not quiet then statistics are printed out with INFO level.This may be very helpful for tracing topology problems.
- Parameters:
statsPrintFreq
- Statistics print frequency in milliseconds.- Returns:
this
for chaining.
-
getIpFinderCleanFrequency
public long getIpFinderCleanFrequency()
Gets frequency with which coordinator cleans IP finder and keeps it in the correct state, unregistering addresses of the nodes that have left the topology.- Returns:
- IP finder clean frequency.
-
setIpFinderCleanFrequency
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setIpFinderCleanFrequency(long ipFinderCleanFreq)
Sets IP finder clean frequency in milliseconds.If not provided, default value is
DFLT_IP_FINDER_CLEAN_FREQ
Affected server nodes only.
- Parameters:
ipFinderCleanFreq
- IP finder clean frequency.- Returns:
this
for chaining.
-
getIpFinder
public TcpDiscoveryIpFinder getIpFinder()
Gets IP finder for IP addresses sharing and storing.- Returns:
- IP finder for IP addresses sharing and storing.
-
setIpFinder
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setIpFinder(TcpDiscoveryIpFinder ipFinder)
Sets IP finder for IP addresses sharing and storing.If not provided
TcpDiscoveryMulticastIpFinder
will be used by default.- Parameters:
ipFinder
- IP finder.- Returns:
this
for chaining.
-
setAddressFilter
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setAddressFilter(IgnitePredicate<InetSocketAddress> addressFilter)
Sets filter for IP addresses. Each address found byTcpDiscoveryIpFinder
will be checked against this filter and only passing addresses will be used for discovery.If not specified or null, all found addresses are used.
- Parameters:
addressFilter
- Address filter to use- Returns:
this
for chaining.
-
setSocketTimeout
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setSocketTimeout(long sockTimeout)
Sets socket operations timeout. This timeout is used to limit connection time and write-to-socket time.Note that when running Ignite on Amazon EC2, socket timeout must be set to a value significantly greater than the default (e.g. to
30000
).If not specified, default is
DFLT_SOCK_TIMEOUT
orDFLT_SOCK_TIMEOUT_CLIENT
.When this property is explicitly set
IgniteConfiguration.getFailureDetectionTimeout()
is ignored.- Parameters:
sockTimeout
- Socket connection timeout.- Returns:
this
for chaining.
-
setAckTimeout
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setAckTimeout(long ackTimeout)
Sets timeout for receiving acknowledgement for sent message.If acknowledgement is not received within this timeout, sending is considered as failed and SPI tries to repeat message sending.
If not specified, default is
DFLT_ACK_TIMEOUT
orDFLT_ACK_TIMEOUT_CLIENT
.When this property is explicitly set
IgniteConfiguration.getFailureDetectionTimeout()
is ignored.- Parameters:
ackTimeout
- Acknowledgement timeout.- Returns:
this
for chaining.
-
setSoLinger
@IgniteSpiConfiguration(optional=true) public void setSoLinger(int soLinger)
Sets SO_LINGER to use for all created sockets.If not specified, default is
DFLT_SO_LINGER
- Parameters:
soLinger
- SO_LINGER value.
-
setNetworkTimeout
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setNetworkTimeout(long netTimeout)
Sets maximum network timeout to use for network operations.If not specified, default is
DFLT_NETWORK_TIMEOUT
.- Parameters:
netTimeout
- Network timeout.- Returns:
this
for chaining.
-
getJoinTimeout
public long getJoinTimeout()
Get join timeout, in milliseconds. Time to wait for joining. If node cannot connect to any address from the IP finder, the node continues to try to join during this timeout. If all addresses still do not respond, an exception will occur and the node will fail to start. If 0 is specified, it means wait forever.- Returns:
- Join timeout.
-
setJoinTimeout
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setJoinTimeout(long joinTimeout)
Sets join timeout.If non-shared IP finder is used and node fails to connect to any address from IP finder, node keeps trying to join within this timeout. If all addresses are still unresponsive, exception is thrown and node startup fails.
If not specified, default is
DFLT_JOIN_TIMEOUT
.- Parameters:
joinTimeout
- Join timeout (0
means wait forever).- Returns:
this
for chaining.- See Also:
TcpDiscoveryIpFinder.isShared()
-
setThreadPriority
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setThreadPriority(int threadPri)
Sets thread priority. All threads within SPI will be started with it.If not provided, default value is
DFLT_THREAD_PRI
- Parameters:
threadPri
- Thread priority.- Returns:
this
for chaining.
-
getTopHistorySize
public long getTopHistorySize()
- Returns:
- Size of topology snapshots history.
-
setTopHistorySize
@IgniteSpiConfiguration(optional=true) public TcpDiscoverySpi setTopHistorySize(int topHistSize)
Sets size of topology snapshots history. Specified size should be greater than or equal to default sizeDFLT_TOP_HISTORY_SIZE
.- Parameters:
topHistSize
- Size of topology snapshots history.- Returns:
this
for chaining.
-
getConnectionRecoveryTimeout
public long getConnectionRecoveryTimeout()
Gets timeout that defines how long server node would try to recovery connection.
SeesetConnectionRecoveryTimeout(long)
for details.- Returns:
- Timeout that defines how long server node would try to recovery connection.
-
setConnectionRecoveryTimeout
public void setConnectionRecoveryTimeout(long connRecoveryTimeout)
Sets timeout that defines how long server node would try to recovery connection.In case local node has temporary connectivity issues with part of the cluster, it may sequentially fail nodes one-by-one till successfully connect to one that has a fine connection with. This leads to fail of big number of nodes.
To overcome that issue, local node will do a sequential connection tries to next nodes. But if new next node has connection to previous it forces local node to retry connect to previous. These tries will last till timeout will not finished. When timeout is over, but no success in connecting to nodes it will segment itself.
Cannot be greater than
IgniteSpiAdapter.failureDetectionTimeout()
.Default is
DFLT_CONNECTION_RECOVERY_TIMEOUT
.- Parameters:
connRecoveryTimeout
- Timeout that defines how long server node would try to recovery connection.0
means node will not recheck failed nodes.
-
setNodeAttributes
public void setNodeAttributes(Map<String,Object> attrs, IgniteProductVersion ver)
Sets node attributes and node version which will be distributed in grid during join process. Note that these attributes cannot be changed and set only once. set- Specified by:
setNodeAttributes
in interfaceDiscoverySpi
- Parameters:
attrs
- Map of node attributes.ver
- Product version.
-
getLocalNodeId
public UUID getLocalNodeId()
Gets ID of the local node.- Returns:
- ID of the local node.
-
consistentId
@Nullable public @Nullable Serializable consistentId() throws IgniteSpiException
Gets consistent ID.- Specified by:
consistentId
in interfaceDiscoverySpi
- Returns:
- Consistent ID of this Ignite instance or
null
if not applicable. - Throws:
IgniteSpiException
- If failed.
-
initLocalNode
protected void initLocalNode(int srvPort, boolean addExtAddrAttr)
- Parameters:
srvPort
- Server port.addExtAddrAttr
- Iftrue
addsATTR_EXT_ADDRS
attribute.
-
injectables
public Collection<Object> injectables()
This method returns SPI internal instances that need to be injected as well. Usually these will be instances provided to SPI externally by user, e.g. during SPI configuration.- Overrides:
injectables
in classIgniteSpiAdapter
- Returns:
- Internal SPI objects that also need to be injected.
-
getSocketTimeout
public long getSocketTimeout()
Gets socket timeout.- Returns:
- Socket timeout.
-
getEffectiveSocketTimeout
public long getEffectiveSocketTimeout(boolean srvrOperation)
Gets effective or resulting socket timeout with considering failure detection timeout- Parameters:
srvrOperation
-True
if socket connect to server node,False
if socket connect to client node.- Returns:
- Resulting socket timeout.
-
getAckTimeout
public long getAckTimeout()
Gets message acknowledgement timeout.- Returns:
- Message acknowledgement timeout.
-
getSoLinger
public int getSoLinger()
Gets SO_LINGER timeout for socket.- Returns:
- SO_LINGER timeout for socket.
-
getNetworkTimeout
public long getNetworkTimeout()
Gets network timeout.- Returns:
- Network timeout.
-
getThreadPriority
public int getThreadPriority()
Gets thread priority. All threads within SPI will be started with it.- Returns:
- Thread priority.
-
getIpFinderFormatted
public String getIpFinderFormatted()
GetsTcpDiscoveryIpFinder
(string representation).- Returns:
- IPFinder (string representation).
-
getNodesJoined
public long getNodesJoined()
Gets joined nodes count.- Returns:
- Nodes joined count.
-
getNodesLeft
public long getNodesLeft()
Gets left nodes count.- Returns:
- Left nodes count.
-
getNodesFailed
public long getNodesFailed()
Gets failed nodes count.- Returns:
- Failed nodes count.
-
getPendingMessagesRegistered
public long getPendingMessagesRegistered()
Gets pending messages registered count.- Returns:
- Pending messages registered count.
-
getPendingMessagesDiscarded
public long getPendingMessagesDiscarded()
Gets pending messages discarded count.- Returns:
- Pending messages registered count.
-
getAvgMessageProcessingTime
public long getAvgMessageProcessingTime()
Gets avg message processing time.- Returns:
- Avg message processing time.
-
getMaxMessageProcessingTime
public long getMaxMessageProcessingTime()
Gets max message processing time.- Returns:
- Max message processing time.
-
getTotalReceivedMessages
public int getTotalReceivedMessages()
Gets total received messages count.- Returns:
- Total received messages count.
-
getReceivedMessages
public Map<String,Integer> getReceivedMessages()
Gets received messages counts (grouped by type).- Returns:
- Map containing message types and respective counts.
-
getTotalProcessedMessages
public int getTotalProcessedMessages()
Gets total processed messages count.- Returns:
- Total processed messages count.
-
getProcessedMessages
public Map<String,Integer> getProcessedMessages()
Gets processed messages counts (grouped by type).- Returns:
- Map containing message types and respective counts.
-
getCoordinatorSinceTimestamp
public long getCoordinatorSinceTimestamp()
Gets time local node has been coordinator since.- Returns:
- Time local node is coordinator since.
-
onContextInitialized0
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException
Method to be called in the end of onContextInitialized method.- Overrides:
onContextInitialized0
in classIgniteSpiAdapter
- Parameters:
spiCtx
- SPI context.- Throws:
IgniteSpiException
- In case of errors.
-
onContextDestroyed0
protected void onContextDestroyed0()
Method to be called in the beginning of onContextDestroyed() method.- Overrides:
onContextDestroyed0
in classIgniteSpiAdapter
-
getSpiContext
public IgniteSpiContext getSpiContext()
Gets SPI context.- Overrides:
getSpiContext
in classIgniteSpiAdapter
- Returns:
- SPI context.
-
getLocalNode
public ClusterNode getLocalNode()
Gets local node.- Specified by:
getLocalNode
in interfaceDiscoverySpi
- Overrides:
getLocalNode
in classIgniteSpiAdapter
- Returns:
- Local node.
-
setListener
public void setListener(@Nullable @Nullable DiscoverySpiListener lsnr)
Sets a listener for discovery events. Refer toDiscoveryEvent
for a set of all possible discovery events.TODO: This method should be removed from public API in Apache Ignite 3.0
- Specified by:
setListener
in interfaceDiscoverySpi
- Parameters:
lsnr
- Listener to discovery events ornull
to unset the listener.
-
setDataExchange
public void setDataExchange(DiscoverySpiDataExchange exchange)
Sets a handler for initial data exchange between Ignite nodes.- Specified by:
setDataExchange
in interfaceDiscoverySpi
- Parameters:
exchange
- Discovery data exchange handler.
-
setMetricsProvider
public void setMetricsProvider(DiscoveryMetricsProvider metricsProvider)
Sets discovery metrics provider. Use metrics provided byDiscoveryMetricsProvider.metrics()
method to exchange dynamic metrics between nodes.- Specified by:
setMetricsProvider
in interfaceDiscoverySpi
- Parameters:
metricsProvider
- Provider of metrics data.
-
getGridStartTime
public long getGridStartTime()
Gets start time of the very first node in the grid. This value should be the same on all nodes in the grid and it should not change even if very first node fails of leaves grid.- Specified by:
getGridStartTime
in interfaceDiscoverySpi
- Returns:
- Start time of the first node in grid or
0
if SPI implementation does not support this method.
-
openSocket
protected Socket openSocket(InetSocketAddress sockAddr, IgniteSpiOperationTimeoutHelper timeoutHelper) throws IOException, IgniteSpiOperationTimeoutException
- Parameters:
sockAddr
- Remote address.timeoutHelper
- Timeout helper.- Returns:
- Opened socket.
- Throws:
IOException
- If failed.IgniteSpiOperationTimeoutException
- In case of timeout.
-
openSocket
protected Socket openSocket(Socket sock, InetSocketAddress remAddr, IgniteSpiOperationTimeoutHelper timeoutHelper) throws IOException, IgniteSpiOperationTimeoutException
Connects to remote address sendingU.IGNITE_HEADER
when connection is established.- Parameters:
sock
- Socket bound to a local host address.remAddr
- Remote address.timeoutHelper
- Timeout helper.- Returns:
- Connected socket.
- Throws:
IOException
- If failed.IgniteSpiOperationTimeoutException
- In case of timeout.
-
writeToSocket
protected void writeToSocket(Socket sock, org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg, byte[] data, long timeout) throws IOException
Writes message to the socket.- Parameters:
sock
- Socket.msg
- Message.data
- Raw data to write.timeout
- Socket write timeout.- Throws:
IOException
- If IO failed or write timed out.
-
writeToSocket
protected void writeToSocket(Socket sock, org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg, long timeout) throws IOException, IgniteCheckedException
Writes message to the socket.- Parameters:
sock
- Socket.msg
- Message.timeout
- Socket write timeout.- Throws:
IOException
- If IO failed or write timed out.IgniteCheckedException
- If marshalling failed.
-
startMessageProcess
@TestOnly protected void startMessageProcess(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg)
- Parameters:
msg
- Message.
-
writeToSocket
protected void writeToSocket(ClusterNode node, Socket sock, OutputStream out, org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg, long timeout) throws IOException, IgniteCheckedException
- Parameters:
node
- Target node.sock
- Socket.out
- Stream to write to.msg
- Message.timeout
- Timeout.- Throws:
IOException
- If IO failed or write timed out.IgniteCheckedException
- If marshalling failed.
-
writeToSocket
protected void writeToSocket(Socket sock, OutputStream out, org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg, long timeout) throws IOException, IgniteCheckedException
Writes message to the socket.- Parameters:
sock
- Socket.out
- Stream to write to.msg
- Message.timeout
- Timeout.- Throws:
IOException
- If IO failed or write timed out.IgniteCheckedException
- If marshalling failed.
-
writeToSocket
protected void writeToSocket(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg, Socket sock, int res, long timeout) throws IOException
Writes response to the socket.- Parameters:
msg
- Received message.sock
- Socket.res
- Integer response.timeout
- Socket timeout.- Throws:
IOException
- If IO failed or write timed out.
-
readMessage
protected <T> T readMessage(Socket sock, @Nullable @Nullable InputStream in, long timeout) throws IOException, IgniteCheckedException
Reads message from the socket limiting read time.- Parameters:
sock
- Socket.in
- Input stream (in case socket stream was wrapped).timeout
- Socket timeout for this operation.- Returns:
- Message.
- Throws:
IOException
- If IO failed or read timed out.IgniteCheckedException
- If unmarshalling failed.
-
readReceipt
protected int readReceipt(Socket sock, long timeout) throws IOException
Reads message delivery receipt from the socket.- Parameters:
sock
- Socket.timeout
- Socket timeout for this operation.- Returns:
- Receipt.
- Throws:
IOException
- If IO failed or read timed out.
-
resolvedAddresses
protected Collection<InetSocketAddress> resolvedAddresses() throws IgniteSpiException
Resolves addresses registered in the IP finder, removes duplicates and local host address and returns the collection of.- Returns:
- Resolved addresses without duplicates and local address (potentially empty but never null).
- Throws:
IgniteSpiException
- If an error occurs.
-
registeredAddresses
protected Collection<InetSocketAddress> registeredAddresses() throws IgniteSpiException
Gets addresses registered in the IP finder, initializes addresses having no port (or 0 port) withDFLT_PORT
.- Returns:
- Registered addresses.
- Throws:
IgniteSpiException
- If an error occurs.
-
duplicateIdError
protected IgniteSpiException duplicateIdError(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryDuplicateIdMessage msg)
- Parameters:
msg
- Message.- Returns:
- Error.
-
authenticationFailedError
protected IgniteSpiException authenticationFailedError(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAuthFailedMessage msg)
- Parameters:
msg
- Message.- Returns:
- Error.
-
checkFailedError
protected IgniteSpiException checkFailedError(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCheckFailedMessage msg)
- Parameters:
msg
- Message.- Returns:
- Error.
-
ensured
protected boolean ensured(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage msg)
- Parameters:
msg
- Message.- Returns:
- Whether delivery of the message is ensured.
-
onExchange
protected void onExchange(org.apache.ignite.spi.discovery.tcp.internal.DiscoveryDataPacket dataPacket, ClassLoader clsLdr)
- Parameters:
dataPacket
- object holding discovery data collected during discovery process.clsLdr
- Class loader.
-
spiStart
public void spiStart(@Nullable @Nullable String igniteInstanceName) throws IgniteSpiException
This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.- Specified by:
spiStart
in interfaceIgniteSpi
- Parameters:
igniteInstanceName
- Name of Ignite instance this SPI is being started for (null
for default Ignite instance).- Throws:
IgniteSpiException
- Throws in case of any error during SPI start.
-
initializeImpl
protected void initializeImpl()
-
spiStop
public void spiStop() throws IgniteSpiException
This method is called to stop SPI. After this method returns kernel assumes that this SPI is finished and all resources acquired by it are released.Note that this method can be called at any point including during recovery of failed start. It should make no assumptions on what state SPI will be in when this method is called.
- Specified by:
spiStop
in interfaceIgniteSpi
- Throws:
IgniteSpiException
- Thrown in case of any error during SPI stop.
-
clientReconnect
public void clientReconnect() throws IgniteSpiException
- Specified by:
clientReconnect
in interfaceorg.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi
- Throws:
IgniteSpiException
-
allNodesSupport
public boolean allNodesSupport(org.apache.ignite.internal.IgniteFeatures feature)
- Specified by:
allNodesSupport
in interfaceorg.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi
- Parameters:
feature
- Feature to check.- Returns:
true
if all nodes support the given feature.
-
knownNode
public boolean knownNode(UUID nodeId)
- Specified by:
knownNode
in interfaceorg.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi
- Parameters:
nodeId
- Node ID.- Returns:
True
if node joining or already joined topology.
-
clientReconnectSupported
public boolean clientReconnectSupported()
- Specified by:
clientReconnectSupported
in interfaceorg.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi
- Returns:
True
if SPI supports client reconnect.
-
supportsCommunicationFailureResolve
public boolean supportsCommunicationFailureResolve()
- Specified by:
supportsCommunicationFailureResolve
in interfaceorg.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi
- Returns:
True
if supports communication error resolve.
-
resolveCommunicationFailure
public void resolveCommunicationFailure(ClusterNode node, Exception err)
- Specified by:
resolveCommunicationFailure
in interfaceorg.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi
- Parameters:
node
- Problem node.err
- Connection error.
-
clientWorkerCount
public int clientWorkerCount()
FOR TEST ONLY!!!- Returns:
- Client workers count.
-
addSendMessageListener
public void addSendMessageListener(IgniteInClosure<org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage> lsnr)
FOR TEST ONLY!!!- Parameters:
lsnr
- Listener of sent messages.
-
setInternalListener
public void setInternalListener(org.apache.ignite.internal.managers.discovery.IgniteDiscoverySpiInternalListener lsnr)
For TESTING only.- Specified by:
setInternalListener
in interfaceorg.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi
- Parameters:
lsnr
- Listener.
-
removeSendMessageListener
public void removeSendMessageListener(IgniteInClosure<org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage> lsnr)
FOR TEST ONLY!!!- Parameters:
lsnr
- Instance of the listener for sent messages.
-
addIncomeConnectionListener
public void addIncomeConnectionListener(IgniteInClosure<Socket> lsnr)
FOR TEST ONLY!!!- Parameters:
lsnr
- Instance of the listener for incoming messages.
-
removeIncomeConnectionListener
public void removeIncomeConnectionListener(IgniteInClosure<Socket> lsnr)
FOR TEST ONLY!!!- Parameters:
lsnr
- Instance of the listener for incoming messages.
-
waitForClientMessagePrecessed
public void waitForClientMessagePrecessed()
FOR TEST PURPOSE ONLY!
-
simulateNodeFailure
public void simulateNodeFailure()
FOR TEST ONLY!!!Simulates this node failure by stopping service threads. So, node will become unresponsive.
This method is intended for test purposes only.
- Specified by:
simulateNodeFailure
in interfaceorg.apache.ignite.internal.managers.discovery.IgniteDiscoverySpi
-
brakeConnection
public void brakeConnection()
FOR TEST PURPOSE ONLY!
-
isLocalNodeCoordinator
public boolean isLocalNodeCoordinator()
Checks whether local node is coordinator. Nodes that are leaving or failed (but are still in topology) are removed from search.- Returns:
true
if local node is coordinator.
-
marshaller
protected Marshaller marshaller()
- Returns:
- Marshaller.
-
setName
public TcpDiscoverySpi setName(String name)
Sets SPI name.- Overrides:
setName
in classIgniteSpiAdapter
- Parameters:
name
- SPI name.- Returns:
this
for chaining.
-
-