use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridSpiTestContext method resetNodes.
/**
* @param nodes Nodes to reset.
* @param rmv Whether nodes that were not passed in should be removed or not.
*/
public void resetNodes(Collection<ClusterNode> nodes, boolean rmv) {
for (ClusterNode node : nodes) {
assert !node.equals(locNode);
if (!rmtNodes.contains(node))
addNode(node);
}
if (rmv) {
for (Iterator<ClusterNode> iter = rmtNodes.iterator(); iter.hasNext(); ) {
ClusterNode node = iter.next();
if (!nodes.contains(node)) {
iter.remove();
notifyListener(new DiscoveryEvent(locNode, "Node left", EVT_NODE_LEFT, node));
}
}
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridSpiTestContext method addNode.
/**
* @param node Node to add.
*/
public void addNode(ClusterNode node) {
rmtNodes.add(node);
notifyListener(new DiscoveryEvent(locNode, "Node joined", EVT_NODE_JOINED, node));
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class TcpClientDiscoverySpiFailureTimeoutSelfTest method testFailureTimeout3Server.
/**
* Test failure detection time between servers with failure detection.
*
* @throws Exception in case of error.
*/
public void testFailureTimeout3Server() throws Exception {
failureThreshold = 1000;
clientFailureDetectionTimeout = 10000;
useTestSpi = true;
try {
startServerNodes(3);
checkNodes(3, 0);
Ignite srv0 = G.ignite("server-0");
final TestTcpDiscoverySpi2 spi0 = (TestTcpDiscoverySpi2) srv0.configuration().getDiscoverySpi();
final Ignite srv1 = G.ignite("server-1");
final TestTcpDiscoverySpi2 spi1 = (TestTcpDiscoverySpi2) srv1.configuration().getDiscoverySpi();
Ignite srv2 = G.ignite("server-2");
final TestTcpDiscoverySpi2 spi2 = (TestTcpDiscoverySpi2) srv2.configuration().getDiscoverySpi();
long failureTime = U.currentTimeMillis();
final AtomicLong failureDetectTime = new AtomicLong();
final CountDownLatch latch = new CountDownLatch(2);
spi1.writeToSocketDelay = 2000;
for (Ignite srv : new Ignite[] { srv0, srv2 }) {
srv.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
DiscoveryEvent evt0 = (DiscoveryEvent) evt;
assertEquals(srv1.cluster().localNode().id(), evt0.eventNode().id());
failureDetectTime.compareAndSet(0, U.currentTimeMillis());
latch.countDown();
return true;
}
}, EVT_NODE_FAILED);
}
assertTrue("Can't get node failure event", latch.await(15000, TimeUnit.MILLISECONDS));
long detectTime = failureDetectTime.get() - failureTime;
assertTrue("Server node failure detected too fast: " + detectTime + "ms", detectTime > failureThreshold - 100);
assertTrue("Server node failure detected too slow: " + detectTime + "ms", detectTime < clientFailureDetectionTimeout);
} finally {
failureThreshold = FAILURE_THRESHOLD;
useTestSpi = false;
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class TcpClientDiscoverySpiFailureTimeoutSelfTest method clientReconnectOnCoordinatorRouterFail.
/**
* Test tries to provoke scenario when client sends reconnect message before router failure detected.
*
* @param srvNodes Number of additional server nodes.
* @throws Exception If failed.
*/
public void clientReconnectOnCoordinatorRouterFail(int srvNodes) throws Exception {
startServerNodes(1);
Ignite srv = G.ignite("server-0");
final TcpDiscoveryNode srvNode = (TcpDiscoveryNode) srv.cluster().localNode();
final UUID srvNodeId = srvNode.id();
clientIpFinder = new TcpDiscoveryVmIpFinder();
clientIpFinder.setAddresses(Collections.singleton("localhost:" + srvNode.discoveryPort() + ".." + (srvNode.discoveryPort() + 1)));
failureThreshold = 1000L;
netTimeout = 1000L;
// Client should connect to coordinator.
startClientNodes(1);
failureThreshold = 10_000L;
netTimeout = 5000L;
List<String> nodes = new ArrayList<>();
for (int i = 0; i < srvNodes; i++) {
Ignite g = startGrid("server-" + srvIdx.getAndIncrement());
nodes.add(g.name());
srvNodeIds.add(g.cluster().localNode().id());
}
checkNodes(1 + srvNodes, 1);
nodes.add("client-0");
final CountDownLatch latch = new CountDownLatch(nodes.size());
final AtomicBoolean err = new AtomicBoolean();
for (String node : nodes) {
G.ignite(node).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
DiscoveryEvent disoEvt = (DiscoveryEvent) evt;
if (disoEvt.eventNode().id().equals(srvNodeId)) {
info("Expected node failed event: " + ((DiscoveryEvent) evt).eventNode());
latch.countDown();
} else {
log.info("Unexpected node failed event: " + evt);
err.set(true);
}
return true;
}
}, EVT_NODE_FAILED);
}
Thread.sleep(5000);
Ignite client = G.ignite("client-0");
UUID nodeId = client.cluster().localNode().id();
log.info("Fail coordinator: " + srvNodeId);
TestTcpDiscoverySpi srvSpi = (TestTcpDiscoverySpi) srv.configuration().getDiscoverySpi();
srvSpi.pauseAll(false);
try {
Thread.sleep(2000);
} finally {
srvSpi.simulateNodeFailure();
srvSpi.resumeAll();
}
try {
assertTrue(latch.await(failureThreshold + 3000, TimeUnit.MILLISECONDS));
assertFalse("Unexpected event, see log for details.", err.get());
assertEquals(nodeId, client.cluster().localNode().id());
} finally {
srvSpi.resumeAll();
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridReduceQueryExecutor method start.
/**
* @param ctx Context.
* @param h2 H2 Indexing.
* @throws IgniteCheckedException If failed.
*/
public void start(final GridKernalContext ctx, final IgniteH2Indexing h2) throws IgniteCheckedException {
this.ctx = ctx;
this.h2 = h2;
log = ctx.log(GridReduceQueryExecutor.class);
ctx.io().addMessageListener(GridTopic.TOPIC_QUERY, new GridMessageListener() {
@SuppressWarnings("deprecation")
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
if (!busyLock.enterBusy())
return;
try {
if (msg instanceof GridCacheQueryMarshallable)
((GridCacheQueryMarshallable) msg).unmarshall(ctx.config().getMarshaller(), ctx);
GridReduceQueryExecutor.this.onMessage(nodeId, msg);
} finally {
busyLock.leaveBusy();
}
}
});
ctx.event().addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(final Event evt) {
UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
for (ReduceQueryRun r : runs.values()) {
for (GridMergeIndex idx : r.indexes()) {
if (idx.hasSource(nodeId)) {
handleNodeLeft(r, nodeId);
break;
}
}
}
for (DistributedUpdateRun r : updRuns.values()) r.handleNodeLeft(nodeId);
}
}, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
}
Aggregations