use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class IgniteSpiAdapter method onContextInitialized.
/** {@inheritDoc} */
@Override
public final void onContextInitialized(final IgniteSpiContext spiCtx) throws IgniteSpiException {
assert spiCtx != null;
this.spiCtx = spiCtx;
if (!Boolean.getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
spiCtx.addLocalEventListener(paramsLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
assert evt instanceof DiscoveryEvent : "Invalid event [expected=" + EVT_NODE_JOINED + ", actual=" + evt.type() + ", evt=" + evt + ']';
ClusterNode node = spiCtx.node(((DiscoveryEvent) evt).eventNode().id());
if (node != null)
try {
checkConfigurationConsistency(spiCtx, node, false);
checkConfigurationConsistency0(spiCtx, node, false);
} catch (IgniteSpiException e) {
U.error(log, "Spi consistency check failed [node=" + node.id() + ", spi=" + getName() + ']', e);
}
}
}, EVT_NODE_JOINED);
final Collection<ClusterNode> remotes = F.concat(false, spiCtx.remoteNodes(), spiCtx.remoteDaemonNodes());
for (ClusterNode node : remotes) {
checkConfigurationConsistency(spiCtx, node, true);
checkConfigurationConsistency0(spiCtx, node, true);
}
}
onContextInitialized0(spiCtx);
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class AbstractAffinityFunctionSelfTest method checkRandomReassignment.
/**
* @param backups Backups.
*/
protected void checkRandomReassignment(int backups) {
AffinityFunction aff = affinityFunction();
Random rnd = new Random();
int maxNodes = 50;
List<ClusterNode> nodes = new ArrayList<>(maxNodes);
List<List<ClusterNode>> prev = null;
int state = 0;
int i = 0;
while (true) {
boolean add;
if (nodes.size() < 2) {
// Returned back to one node?
if (state == 1)
return;
add = true;
} else if (nodes.size() == maxNodes) {
if (state == 0)
state = 1;
add = false;
} else {
// Nodes size in [2, maxNodes - 1].
if (state == 0)
// 66% to add, 33% to remove.
add = rnd.nextInt(3) != 0;
else
// 33% to add, 66% to remove.
add = rnd.nextInt(3) == 0;
}
DiscoveryEvent discoEvt;
if (add) {
ClusterNode addedNode = new GridTestNode(UUID.randomUUID());
nodes.add(addedNode);
discoEvt = new DiscoveryEvent(addedNode, "", EventType.EVT_NODE_JOINED, addedNode);
} else {
ClusterNode rmvNode = nodes.remove(rnd.nextInt(nodes.size()));
discoEvt = new DiscoveryEvent(rmvNode, "", EventType.EVT_NODE_LEFT, rmvNode);
}
info("======================================");
info("Assigning partitions [iter=" + i + ", discoEvt=" + discoEvt + ", nodesSize=" + nodes.size() + ']');
info("======================================");
List<List<ClusterNode>> assignment = aff.assignPartitions(new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups));
verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
prev = assignment;
i++;
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class RendezvousAffinityFunctionSimpleBenchmark method addNode.
/**
* @param nodes Topology.
* @param iter Iteration count.
* @return Discovery event.
*/
@NotNull
private DiscoveryEvent addNode(List<ClusterNode> nodes, int iter) {
GridTestNode node = new GridTestNode(UUID.randomUUID());
// two neighbours nodes
node.setAttribute(IgniteNodeAttributes.ATTR_MACS, MAC_PREF + "_add_" + iter / 4);
nodes.add(node);
return new DiscoveryEvent(nodes.get(0), "", EventType.EVT_NODE_JOINED, node);
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class RendezvousAffinityFunctionSimpleBenchmark method nodesModificationChangeLast.
/**
* Modify the topology by remove the last / add new node.
*
* @param nodes Topology.
* @param prevAssignment Previous afinity.
* @param iter Number of iteration.
* @param backups Backups count.
* @return Affinity context.
*/
private GridAffinityFunctionContextImpl nodesModificationChangeLast(List<ClusterNode> nodes, List<List<ClusterNode>> prevAssignment, int iter, int backups) {
DiscoveryEvent discoEvt;
discoEvt = iter % 2 == 0 ? addNode(nodes, iter) : removeNode(nodes, nodes.size() - 1);
return new GridAffinityFunctionContextImpl(nodes, prevAssignment, discoEvt, new AffinityTopologyVersion(nodes.size()), backups);
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class IgniteClientReconnectCacheTest method testReconnectInitialExchangeInProgress.
/**
* @throws Exception If failed.
*/
public void testReconnectInitialExchangeInProgress() throws Exception {
final UUID clientId = UUID.randomUUID();
Ignite srv = grid(0);
final CountDownLatch joinLatch = new CountDownLatch(1);
srv.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_NODE_JOINED && ((DiscoveryEvent) evt).eventNode().id().equals(clientId)) {
info("Client joined: " + evt);
joinLatch.countDown();
}
return true;
}
}, EVT_NODE_JOINED);
TestCommunicationSpi srvCommSpi = (TestCommunicationSpi) srv.configuration().getCommunicationSpi();
srvCommSpi.blockMessages(GridDhtPartitionsFullMessage.class, clientId);
clientMode = true;
nodeId = clientId;
IgniteInternalFuture<Boolean> fut = GridTestUtils.runAsync(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
Ignition.start(optimize(getConfiguration(getTestIgniteInstanceName(SRV_CNT))));
return true;
} catch (IgniteClientDisconnectedException e) {
log.info("Expected start error: " + e);
try {
e.reconnectFuture().get();
fail();
} catch (IgniteException e0) {
log.info("Expected future error: " + e0);
}
return true;
} catch (Throwable e) {
log.error("Unexpected error: " + e, e);
throw e;
}
}
});
TestTcpDiscoverySpi srvSpi = spi(srv);
try {
if (!joinLatch.await(10_000, MILLISECONDS)) {
log.error("Failed to wait for join event, will dump threads.");
U.dumpThreads(log);
fail("Failed to wait for join event.");
}
U.sleep(1000);
assertNotDone(fut);
srvSpi.failNode(clientId, null);
} finally {
srvCommSpi.stopBlock(false);
}
assertTrue(fut.get());
}
Aggregations