use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage in project ignite by apache.
the class ServerImpl method prepareNodeAddedMessage.
/**
* @param msg Message to prepare.
* @param destNodeId Destination node ID.
* @param msgs Messages to include.
* @param discardMsgId Discarded message ID.
*/
private void prepareNodeAddedMessage(TcpDiscoveryAbstractMessage msg, UUID destNodeId, @Nullable Collection<PendingMessage> msgs, @Nullable IgniteUuid discardMsgId, @Nullable IgniteUuid discardCustomMsgId) {
assert destNodeId != null;
if (msg instanceof TcpDiscoveryNodeAddedMessage) {
TcpDiscoveryNodeAddedMessage nodeAddedMsg = (TcpDiscoveryNodeAddedMessage) msg;
TcpDiscoveryNode node = nodeAddedMsg.node();
if (node.id().equals(destNodeId)) {
Collection<TcpDiscoveryNode> allNodes = ring.allNodes();
Collection<TcpDiscoveryNode> topToSnd = new ArrayList<>(allNodes.size());
for (TcpDiscoveryNode n0 : allNodes) {
assert n0.internalOrder() != 0 : n0;
// internal order.
if (n0.internalOrder() < nodeAddedMsg.node().internalOrder())
topToSnd.add(n0);
}
nodeAddedMsg.topology(topToSnd);
Collection<TcpDiscoveryAbstractMessage> msgs0 = null;
if (msgs != null) {
msgs0 = new ArrayList<>(msgs.size());
for (PendingMessage pendingMsg : msgs) {
if (pendingMsg.msg != null)
msgs0.add(pendingMsg.msg);
}
}
nodeAddedMsg.messages(msgs0, discardMsgId, discardCustomMsgId);
Map<Long, Collection<ClusterNode>> hist;
synchronized (mux) {
hist = new TreeMap<>(topHist);
}
nodeAddedMsg.topologyHistory(hist);
}
}
}
use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage in project ignite by apache.
the class TcpClientDiscoverySpiSelfTest method testTimeoutWaitingNodeAddedMessage.
/**
* @throws Exception If any error occurs.
*/
public void testTimeoutWaitingNodeAddedMessage() throws Exception {
longSockTimeouts = true;
startServerNodes(2);
final CountDownLatch cnt = new CountDownLatch(1);
((TcpDiscoverySpi) G.ignite("server-1").configuration().getDiscoverySpi()).addSendMessageListener(new IgniteInClosure<TcpDiscoveryAbstractMessage>() {
@Override
public void apply(TcpDiscoveryAbstractMessage msg) {
try {
cnt.await(10, MINUTES);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteInterruptedException(e);
}
}
});
try {
netTimeout = 500;
startGrid("client-0");
assert false;
} catch (IgniteCheckedException e) {
cnt.countDown();
IgniteSpiException spiEx = e.getCause(IgniteSpiException.class);
assert spiEx != null : e;
assert spiEx.getMessage().contains("Join process timed out") : spiEx.getMessage();
}
}
use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage in project ignite by apache.
the class TcpClientDiscoverySpiSelfTest method missedAddFinishedMessage.
/**
* @param singleSrv If {@code true} starts one server node two otherwise.
* @throws Exception If failed.
*/
private void missedAddFinishedMessage(boolean singleSrv) throws Exception {
int srvs = singleSrv ? 1 : 2;
startServerNodes(srvs);
afterWrite = new CIX2<TcpDiscoveryAbstractMessage, Socket>() {
private boolean first = true;
@Override
public void applyx(TcpDiscoveryAbstractMessage msg, Socket sock) throws IgniteCheckedException {
if (first && (msg instanceof TcpDiscoveryJoinRequestMessage)) {
first = false;
log.info("Close socket after message write [msg=" + msg + "]");
try {
sock.close();
} catch (IOException e) {
throw new IgniteCheckedException(e);
}
log.info("Delay after message write [msg=" + msg + "]");
// Wait when server process join request.
U.sleep(5000);
}
}
};
Ignite srv = singleSrv ? G.ignite("server-0") : G.ignite("server-1");
TcpDiscoveryNode srvNode = (TcpDiscoveryNode) srv.cluster().localNode();
assertEquals(singleSrv ? 1 : 2, srvNode.order());
clientIpFinder = new TcpDiscoveryVmIpFinder();
clientIpFinder.setAddresses(Collections.singleton("localhost:" + srvNode.discoveryPort()));
startClientNodes(1);
TcpDiscoveryNode clientNode = (TcpDiscoveryNode) G.ignite("client-0").cluster().localNode();
assertEquals(srvNode.id(), clientNode.clientRouterNodeId());
checkNodes(srvs, 1);
}
use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage in project ignite by apache.
the class TcpClientDiscoverySpiSelfTest method testClientAndRouterFail.
/**
* @throws Exception If failed.
*/
public void testClientAndRouterFail() throws Exception {
startServerNodes(2);
startClientNodes(2);
checkNodes(2, 2);
srvFailedLatch = new CountDownLatch(2);
clientFailedLatch = new CountDownLatch(2);
attachListeners(1, 1);
((TcpDiscoverySpi) G.ignite("server-1").configuration().getDiscoverySpi()).addSendMessageListener(new IgniteInClosure<TcpDiscoveryAbstractMessage>() {
@Override
public void apply(TcpDiscoveryAbstractMessage msg) {
try {
Thread.sleep(1000000);
} catch (InterruptedException ignored) {
Thread.interrupted();
}
}
});
failClient(1);
failServer(1);
awaitClient(srvFailedLatch);
awaitClient(clientFailedLatch);
checkNodes(1, 1);
}
use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage in project ignite by apache.
the class CacheDiscoveryDataConcurrentJoinTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
TcpDiscoverySpi testSpi = new TcpDiscoverySpi() {
/** */
private boolean delay = true;
@Override
protected void startMessageProcess(TcpDiscoveryAbstractMessage msg) {
if (getTestIgniteInstanceName(0).equals(ignite.name())) {
if (msg instanceof TcpDiscoveryJoinRequestMessage) {
TcpDiscoveryJoinRequestMessage msg0 = (TcpDiscoveryJoinRequestMessage) msg;
if (delay) {
log.info("Delay join processing: " + msg0);
delay = false;
doSleep(5000);
}
}
}
super.startMessageProcess(msg);
}
};
testSpi.setIpFinder(ipFinder);
testSpi.setJoinTimeout(60_000);
cfg.setDiscoverySpi(testSpi);
cfg.setClientMode(client);
Integer caches = staticCaches.get();
if (caches != null) {
cfg.setCacheConfiguration(cacheConfigurations(caches).toArray(new CacheConfiguration[caches]));
staticCaches.remove();
}
return cfg;
}
Aggregations