use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage 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.
*/
private void prepareNodeAddedMessage(TcpDiscoveryAbstractMessage msg, UUID destNodeId, @Nullable Collection<PendingMessage> msgs, @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);
}
}
// No need to send discardMsgId because we already filtered out
// cleaned up messages.
// TODO IGNITE-11271
nodeAddedMsg.messages(msgs0, null, discardCustomMsgId);
Map<Long, Collection<ClusterNode>> hist;
synchronized (mux) {
hist = new TreeMap<>(topHist);
}
nodeAddedMsg.topologyHistory(hist);
}
}
}
use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage in project ignite by apache.
the class ServerImpl method clearNodeAddedMessage.
/**
* @param msg Message to clear.
*/
private void clearNodeAddedMessage(TcpDiscoveryAbstractMessage msg) {
if (msg instanceof TcpDiscoveryNodeAddedMessage) {
// Nullify topology before registration.
TcpDiscoveryNodeAddedMessage nodeAddedMsg = (TcpDiscoveryNodeAddedMessage) msg;
nodeAddedMsg.topology(null);
nodeAddedMsg.topologyHistory(null);
nodeAddedMsg.messages(null, null, null);
nodeAddedMsg.clearUnmarshalledDiscoveryData();
}
}
use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage in project ignite by apache.
the class TcpDiscoverySelfTest method testFailBeforeNodeAddedSent.
/**
* @throws Exception If any error occurs.
*/
@Test
public void testFailBeforeNodeAddedSent() throws Exception {
try {
Ignite g1 = startGrid(1);
final CountDownLatch joinCnt = new CountDownLatch(2);
final CountDownLatch failCnt = new CountDownLatch(1);
g1.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_NODE_JOINED)
joinCnt.countDown();
else if (evt.type() == EVT_NODE_FAILED)
failCnt.countDown();
else
assert false : "Unexpected event type: " + evt;
return true;
}
}, EVT_NODE_JOINED, EVT_NODE_FAILED);
final Ignite g = startGrid("FailBeforeNodeAddedSentSpi");
discoMap.get(g.name()).addSendMessageListener(new IgniteInClosure<TcpDiscoveryAbstractMessage>() {
@Override
public void apply(TcpDiscoveryAbstractMessage msg) {
if (msg instanceof TcpDiscoveryNodeAddedMessage) {
discoMap.get(g.name()).simulateNodeFailure();
throw new RuntimeException("Avoid message sending: " + msg.getClass());
}
}
});
startGrid(3);
assert joinCnt.await(10, SECONDS);
assert failCnt.await(10, SECONDS);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage in project ignite by apache.
the class InvalidServerTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String instanceName, AbstractTestSecurityPluginProvider pluginProv) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(instanceName, pluginProv);
cfg.setDiscoverySpi(new TcpDiscoverySpi() {
@Override
protected void startMessageProcess(TcpDiscoveryAbstractMessage msg) {
if (msg instanceof TcpDiscoveryNodeAddedMessage && msg.verified())
TestSecurityProcessor.PERMS.remove(new SecurityCredentials(TEST_SERVER_NAME, ""));
}
}.setIpFinder(LOCAL_IP_FINDER));
return cfg;
}
use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage in project ignite by apache.
the class TcpDiscoveryNodeJoinAndFailureTest method testConnectingNodesStopIfNoConnectedNodeIsPresented.
/**
* If whole ring fails but two server nodes both in CONNECTING state remain alive they should not hang
* indefinitely sending join requests to each other.
*
* @see <a href="https://issues.apache.org/jira/browse/IGNITE-11621">IGNITE-11621</a>
* with comments provides detailed description of this corner case.
*
* @throws Exception If failed.
*/
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE, value = "false")
public void testConnectingNodesStopIfNoConnectedNodeIsPresented() throws Exception {
/*
Test reproduces the needed behavior (two nodes in CONNECTING state) doing the following:
- it starts two regular nodes, node0 (coordinator) and node1 (just another server) with special
discovery SPIs;
- when node1 receives NodeAddFinished for subsequently started node2, it doesn't send it to the node
but closes disco socket to node2 leaving it in CONNECTING state and generating NodeFailed for it.
Also at this moment node3 is started;
- when node0 receives this NodeFailed it fails (because special SPI throws an exception) and stops;
- when node1 receives another join request from node2 or NodeAdded from node3 reaches it back,
node1's special SPI also throws an exception so it goes down as well;
- as a result, both node2 and node3 get stuck in CONNECTING state and as they use special IpFinders
they see each other and are able to send join requests to each other back and forth.
The whole purpose of the test is to verify that these two nodes won't stuck in CONNECTING state forever
and will eventually stop.
*/
usePortFromNodeName = true;
final AtomicInteger joinReqsCntr = new AtomicInteger(0);
final AtomicReference<IgniteInternalFuture> futureRef = new AtomicReference();
final UUID node2Id = UUID.randomUUID();
final TcpDiscoverySpi node0SpecialSpi = new TcpDiscoverySpi() {
@Override
protected void startMessageProcess(TcpDiscoveryAbstractMessage msg) {
if (msg instanceof TcpDiscoveryNodeFailedMessage) {
TcpDiscoveryNodeFailedMessage failedMsg = (TcpDiscoveryNodeFailedMessage) msg;
UUID failedNodeId = failedMsg.failedNodeId();
if (failedNodeId.equals(node2Id))
throw new RuntimeException("Stop node0 exception");
}
if (msg instanceof TcpDiscoveryJoinRequestMessage) {
TcpDiscoveryJoinRequestMessage joinReq = (TcpDiscoveryJoinRequestMessage) msg;
if (joinReq.node().id().equals(node2Id))
joinReqsCntr.incrementAndGet();
}
}
};
final TcpDiscoverySpi node1SpecialSpi = new TcpDiscoverySpi() {
@Override
protected void startMessageProcess(TcpDiscoveryAbstractMessage msg) {
if (msg instanceof TcpDiscoveryNodeAddFinishedMessage) {
TcpDiscoveryNodeAddFinishedMessage finishedMsg = (TcpDiscoveryNodeAddFinishedMessage) msg;
UUID nodeId = finishedMsg.nodeId();
if (nodeId.equals(node2Id)) {
Object workerObj = GridTestUtils.getFieldValue(impl, "msgWorker");
OutputStream out = GridTestUtils.getFieldValue(workerObj, "out");
try {
out.close();
log.warning("Out to 'sick' node closed");
} catch (Exception ignored) {
// No-op.
}
futureRef.set(GridTestUtils.runAsync(() -> {
try {
startGrid(NODE_WITH_PORT_ID_3);
} catch (Exception ignored) {
// NO-op.
}
}));
}
}
if (msg instanceof TcpDiscoveryJoinRequestMessage) {
TcpDiscoveryJoinRequestMessage joinReq = (TcpDiscoveryJoinRequestMessage) msg;
int joinReqsCount = joinReqsCntr.get();
if (joinReq.node().id().equals(node2Id) && joinReqsCount == 1)
throw new RuntimeException("Stop node1 exception by subsequent join req");
}
if (msg instanceof TcpDiscoveryNodeAddedMessage) {
TcpDiscoveryNodeAddedMessage addedMsg = (TcpDiscoveryNodeAddedMessage) msg;
if (addedMsg.node().discoveryPort() == 47503)
throw new RuntimeException("Stop node1 exception by new node added msg");
}
}
};
specialSpi = node0SpecialSpi;
startGrid(NODE_WITH_PORT_ID_0);
specialSpi = node1SpecialSpi;
startGrid(NODE_WITH_PORT_ID_1);
specialIpFinder0 = new TcpDiscoveryVmIpFinder(false);
((TcpDiscoveryVmIpFinder) specialIpFinder0).setAddresses(Arrays.asList("127.0.0.1:47501", "127.0.0.1:47503"));
specialIpFinder1 = new TcpDiscoveryVmIpFinder(false);
((TcpDiscoveryVmIpFinder) specialIpFinder1).setAddresses(Arrays.asList("127.0.0.1:47502"));
specialSpi = null;
nodeId = node2Id;
boolean expectedExceptionThrown = false;
try {
startGrid(NODE_WITH_PORT_ID_2);
} catch (Exception e) {
Throwable cause0 = e.getCause();
assertNotNull(cause0);
Throwable cause1 = cause0.getCause();
assertNotNull(cause1);
String errorMsg = cause1.getMessage();
assertTrue("Expected error message was not found: " + errorMsg, errorMsg.contains("Failed to connect to any address from IP finder"));
expectedExceptionThrown = true;
}
assertTrue("Expected exception was not thrown.", expectedExceptionThrown);
IgniteInternalFuture startGridFut = futureRef.get();
if (startGridFut != null)
startGridFut.get();
}
Aggregations