use of org.apache.ignite.internal.managers.communication.GridMessageListener in project ignite by apache.
the class KillQueryTest method testCancelQueryIfPartitionsCantBeReservedOnMapNodes.
/**
* Check if query hangs (due to reducer spins retrying to reserve partitions but they can't be reserved), we still
* able to cancel it. Used mocked indexing simulates 100% unability.
*/
@Test
public void testCancelQueryIfPartitionsCantBeReservedOnMapNodes() throws Exception {
// Releases thread that kills query when map nodes receive query request. At least one map node received is ok.
GridMessageListener qryStarted = (node, msg, plc) -> {
if (msg instanceof GridH2QueryRequest)
TestSQLFunctions.cancelLatch.countDown();
};
for (int i = 0; i < NODES_COUNT; i++) grid(i).context().io().addMessageListener(GridTopic.TOPIC_QUERY, qryStarted);
// Suspends distributed queries on the map nodes.
MockedIndexing.failReservations = true;
try {
IgniteInternalFuture cancelFut = cancel(1, asyncCancel);
GridTestUtils.assertThrows(log, () -> {
ignite.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("select * from Integer where _val <> 42")).getAll();
return null;
}, CacheException.class, "The query was cancelled while executing.");
cancelFut.get(CHECK_RESULT_TIMEOUT);
} finally {
for (int i = 0; i < NODES_COUNT; i++) grid(i).context().io().removeMessageListener(GridTopic.TOPIC_QUERY, qryStarted);
}
}
use of org.apache.ignite.internal.managers.communication.GridMessageListener in project ignite by apache.
the class IgniteClusterSnapshotCheckTest method testClusterSnapshotCheckOtherCluster.
/**
* @throws Exception If fails.
*/
@Test
public void testClusterSnapshotCheckOtherCluster() throws Exception {
IgniteEx ig0 = startGridsWithCache(3, dfltCacheCfg.setAffinity(new RendezvousAffinityFunction(false, 1)), CACHE_KEYS_RANGE);
ig0.snapshot().createSnapshot(SNAPSHOT_NAME).get();
stopAllGrids();
// Cleanup persistence directory except created snapshots.
Arrays.stream(new File(U.defaultWorkDirectory()).listFiles()).filter(f -> !f.getName().equals(DFLT_SNAPSHOT_DIRECTORY)).forEach(U::delete);
Set<UUID> assigns = Collections.newSetFromMap(new ConcurrentHashMap<>());
for (int i = 4; i < 7; i++) {
startGrid(optimize(getConfiguration(getTestIgniteInstanceName(i)).setCacheConfiguration()));
UUID locNodeId = grid(i).localNode().id();
grid(i).context().io().addMessageListener(GridTopic.TOPIC_JOB, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
if (msg instanceof GridJobExecuteRequest) {
GridJobExecuteRequest msg0 = (GridJobExecuteRequest) msg;
if (msg0.getTaskName().contains(SnapshotPartitionsVerifyTask.class.getName()))
assigns.add(locNodeId);
}
}
});
}
IgniteEx ignite = grid(4);
ignite.cluster().baselineAutoAdjustEnabled(false);
ignite.cluster().state(ACTIVE);
IdleVerifyResultV2 res = snp(ignite).checkSnapshot(SNAPSHOT_NAME).get();
StringBuilder b = new StringBuilder();
res.print(b::append, true);
// GridJobExecuteRequest is not send to the local node.
assertTrue("Number of jobs must be equal to the cluster size (except local node): " + assigns + ", count: " + assigns.size(), waitForCondition(() -> assigns.size() == 2, 5_000L));
assertTrue(F.isEmpty(res.exceptions()));
assertPartitionsSame(res);
assertContains(log, b.toString(), "The check procedure has finished, no conflicts have been found");
}
use of org.apache.ignite.internal.managers.communication.GridMessageListener in project ignite by apache.
the class GridIoManagerBenchmark0 method testLatency.
/**
* @throws Exception If failed.
*/
@Test
public void testLatency() throws Exception {
final IgniteKernal sndKernal = (IgniteKernal) grid(0);
final IgniteKernal rcvKernal = (IgniteKernal) grid(1);
final ClusterNode sndNode = sndKernal.localNode();
final ClusterNode rcvNode = rcvKernal.localNode();
final GridIoManager snd = sndKernal.context().io();
final GridIoManager rcv = rcvKernal.context().io();
final LongAdder msgCntr = new LongAdder();
final Integer topic = 1;
final Map<IgniteUuid, CountDownLatch> map = new ConcurrentHashMap<>();
rcv.addMessageListener(topic, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
try {
rcv.sendToCustomTopic(sndNode, topic, (Message) msg, PUBLIC_POOL);
} catch (IgniteCheckedException e) {
error("Failed to send message.", e);
}
}
});
snd.addMessageListener(topic, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
map.get(((GridTestMessage) msg).id()).countDown();
}
});
Timer t = new Timer("results-reporter");
t.schedule(new TimerTask() {
private long ts = System.currentTimeMillis();
@Override
public void run() {
long newTs = System.currentTimeMillis();
long qrys = msgCntr.sumThenReset();
long time = newTs - ts;
X.println("Communication benchmark [qps=" + qrys * 1000 / time + ", executed=" + qrys + ", time=" + time + ']');
ts = newTs;
}
}, 10000, 10000);
final AtomicBoolean finish = new AtomicBoolean();
IgniteInternalFuture<?> f = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
IgniteUuid msgId = IgniteUuid.randomUuid();
while (!finish.get()) {
CountDownLatch latch = new CountDownLatch(1);
map.put(msgId, latch);
snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
latch.await();
msgCntr.increment();
}
} catch (IgniteCheckedException e) {
X.println("Message send failed", e);
} catch (InterruptedException ignored) {
// No-op.
}
return null;
}
}, 1, "send-thread");
Thread.sleep(TEST_TIMEOUT);
finish.set(true);
t.cancel();
f.get();
}
use of org.apache.ignite.internal.managers.communication.GridMessageListener in project ignite by apache.
the class GridIoManagerBenchmark method receiveMessages.
/**
* @param g Kernal.
*/
private static void receiveMessages(final IgniteKernal g) {
X.println(">>> Receiving messages.");
final GridIoManager io = g.context().io();
GridMessageListener lsnr = new GridMessageListener() {
private ClusterNode node;
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
if (node == null)
node = g.context().discovery().node(nodeId);
GridTestMessage testMsg = ((GridTestMessage) msg);
testMsg.bytes(null);
try {
io.sendToCustomTopic(node, TEST_TOPIC, testMsg, PUBLIC_POOL);
} catch (IgniteCheckedException e) {
e.printStackTrace();
}
}
};
io.addMessageListener(TEST_TOPIC, lsnr);
}
use of org.apache.ignite.internal.managers.communication.GridMessageListener in project ignite by apache.
the class GridContinuousProcessor method start.
/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
if (ctx.config().isDaemon())
return;
retryDelay = ctx.config().getNetworkSendRetryDelay();
retryCnt = ctx.config().getNetworkSendRetryCount();
marsh = ctx.config().getMarshaller();
ctx.event().addLocalEventListener(new GridLocalEventListener() {
@SuppressWarnings({ "fallthrough", "TooBroadScope" })
@Override
public void onEvent(Event evt) {
assert evt instanceof DiscoveryEvent;
assert evt.type() == EVT_NODE_LEFT || evt.type() == EVT_NODE_FAILED;
UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
clientInfos.remove(nodeId);
// Unregister handlers created by left node.
for (Map.Entry<UUID, RemoteRoutineInfo> e : rmtInfos.entrySet()) {
UUID routineId = e.getKey();
RemoteRoutineInfo info = e.getValue();
if (nodeId.equals(info.nodeId)) {
if (info.autoUnsubscribe)
unregisterRemote(routineId);
if (info.hnd.isQuery())
info.hnd.onNodeLeft();
}
}
for (Map.Entry<IgniteUuid, SyncMessageAckFuture> e : syncMsgFuts.entrySet()) {
SyncMessageAckFuture fut = e.getValue();
if (fut.nodeId().equals(nodeId)) {
SyncMessageAckFuture fut0 = syncMsgFuts.remove(e.getKey());
if (fut0 != null) {
ClusterTopologyCheckedException err = new ClusterTopologyCheckedException("Node left grid while sending message to: " + nodeId);
fut0.onDone(err);
}
}
}
}
}, EVT_NODE_LEFT, EVT_NODE_FAILED);
ctx.event().addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
cancelFutures(new IgniteCheckedException("Topology segmented"));
}
}, EVT_NODE_SEGMENTED);
ctx.discovery().setCustomEventListener(StartRoutineDiscoveryMessage.class, new CustomEventListener<StartRoutineDiscoveryMessage>() {
@Override
public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineDiscoveryMessage msg) {
if (!snd.id().equals(ctx.localNodeId()) && !ctx.isStopping())
processStartRequest(snd, msg);
}
});
ctx.discovery().setCustomEventListener(StartRoutineAckDiscoveryMessage.class, new CustomEventListener<StartRoutineAckDiscoveryMessage>() {
@Override
public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StartRoutineAckDiscoveryMessage msg) {
StartFuture fut = startFuts.remove(msg.routineId());
if (fut != null) {
if (msg.errs().isEmpty()) {
LocalRoutineInfo routine = locInfos.get(msg.routineId());
// Update partition counters.
if (routine != null && routine.handler().isQuery()) {
Map<UUID, Map<Integer, T2<Long, Long>>> cntrsPerNode = msg.updateCountersPerNode();
Map<Integer, T2<Long, Long>> cntrs = msg.updateCounters();
GridCacheAdapter<Object, Object> interCache = ctx.cache().internalCache(routine.handler().cacheName());
GridCacheContext cctx = interCache != null ? interCache.context() : null;
if (cctx != null && cntrsPerNode != null && !cctx.isLocal() && cctx.affinityNode())
cntrsPerNode.put(ctx.localNodeId(), cctx.topology().updateCounters(false));
routine.handler().updateCounters(topVer, cntrsPerNode, cntrs);
}
fut.onRemoteRegistered();
} else {
IgniteCheckedException firstEx = F.first(msg.errs().values());
fut.onDone(firstEx);
stopRoutine(msg.routineId());
}
}
}
});
ctx.discovery().setCustomEventListener(StopRoutineDiscoveryMessage.class, new CustomEventListener<StopRoutineDiscoveryMessage>() {
@Override
public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StopRoutineDiscoveryMessage msg) {
if (!snd.id().equals(ctx.localNodeId())) {
UUID routineId = msg.routineId();
unregisterRemote(routineId);
}
for (Map<UUID, LocalRoutineInfo> clientInfo : clientInfos.values()) {
if (clientInfo.remove(msg.routineId()) != null)
break;
}
}
});
ctx.discovery().setCustomEventListener(StopRoutineAckDiscoveryMessage.class, new CustomEventListener<StopRoutineAckDiscoveryMessage>() {
@Override
public void onCustomEvent(AffinityTopologyVersion topVer, ClusterNode snd, StopRoutineAckDiscoveryMessage msg) {
StopFuture fut = stopFuts.remove(msg.routineId());
if (fut != null)
fut.onDone();
}
});
ctx.io().addMessageListener(TOPIC_CONTINUOUS, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object obj) {
GridContinuousMessage msg = (GridContinuousMessage) obj;
if (msg.data() == null && msg.dataBytes() != null) {
try {
msg.data(U.unmarshal(marsh, msg.dataBytes(), U.resolveClassLoader(ctx.config())));
} catch (IgniteCheckedException e) {
U.error(log, "Failed to process message (ignoring): " + msg, e);
return;
}
}
switch(msg.type()) {
case MSG_EVT_NOTIFICATION:
processNotification(nodeId, msg);
break;
case MSG_EVT_ACK:
processMessageAck(msg);
break;
default:
assert false : "Unexpected message received: " + msg.type();
}
}
});
ctx.cacheObjects().onContinuousProcessorStarted(ctx);
ctx.service().onContinuousProcessorStarted(ctx);
if (log.isDebugEnabled())
log.debug("Continuous processor started.");
}
Aggregations