use of org.apache.ignite.internal.util.distributed.DistributedProcess in project ignite by apache.
the class PerformanceStatisticsProcessor method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws IgniteCheckedException {
super.start();
ctx.internalSubscriptionProcessor().registerDistributedMetastorageListener(new DistributedMetastorageLifecycleListener() {
@Override
public void onReadyForRead(ReadableDistributedMetaStorage metastorage) {
metastorage.listen(PERF_STAT_KEY::equals, (key, oldVal, newVal) -> {
// Skip history on local join.
if (!ctx.discovery().localJoinFuture().isDone())
return;
onMetastorageUpdate((boolean) newVal);
});
}
@Override
public void onReadyForWrite(DistributedMetaStorage metastorage) {
PerformanceStatisticsProcessor.this.metastorage = metastorage;
try {
Boolean performanceStatsEnabled = metastorage.read(PERF_STAT_KEY);
if (performanceStatsEnabled == null)
return;
onMetastorageUpdate(performanceStatsEnabled);
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}
});
rotateProc = new DistributedProcess<>(ctx, PERFORMANCE_STATISTICS_ROTATE, req -> ctx.closure().callLocalSafe(() -> {
rotateWriter();
return null;
}), (id, res, err) -> {
});
}
use of org.apache.ignite.internal.util.distributed.DistributedProcess in project ignite by apache.
the class DistributedProcessCoordinatorLeftTest method testCoordinatorFailed.
/**
* Tests that coordinator failing during sending single result not cause node failure and the process finishes.
*
* <ol>
* <li>Start new process of {@link DistributedProcess}.</li>
* <li>The coordinator fails.</li>
* <li>Nodes try to send a single message to the not-alive coordinator.</li>
* <li>{@link DistributedProcess} process a node left event and reinitialize a new coordinator.</li>
* <li>Process finishes.</li>
* </ol>
*
* @throws Exception If failed.
*/
@Test
public void testCoordinatorFailed() throws Exception {
startGrids(NODES_CNT);
CountDownLatch startLatch = new CountDownLatch(NODES_CNT);
CountDownLatch finishLatch = new CountDownLatch(NODES_CNT - 1);
HashMap<String, DistributedProcess<Integer, Integer>> processes = new HashMap<>();
int processRes = 1;
for (Ignite grid : G.allGrids()) {
DistributedProcess<Integer, Integer> dp = new DistributedProcess<>(((IgniteEx) grid).context(), TEST_PROCESS, req -> {
IgniteInternalFuture<Integer> fut = runAsync(() -> {
try {
nodeLeftLatch.await();
} catch (InterruptedException ignored) {
fail("Unexpected interrupt.");
}
return req;
});
// It is guaranteed by the LIFO order of future listeners notifying.
if (!grid.name().equals(getTestIgniteInstanceName(STOP_NODE_IDX)))
fut.listen(f -> msgSendLatch.countDown());
startLatch.countDown();
return fut;
}, (uuid, res, err) -> {
if (res.values().size() == NODES_CNT - 1 && res.values().stream().allMatch(i -> i == processRes))
finishLatch.countDown();
else
fail("Unexpected process result [res=" + res + ", err=" + err + ']');
});
processes.put(grid.name(), dp);
}
processes.get(grid(STOP_NODE_IDX).name()).start(UUID.randomUUID(), processRes);
assertTrue(startLatch.await(TIMEOUT, MILLISECONDS));
stopGrid(STOP_NODE_IDX);
assertTrue(finishLatch.await(TIMEOUT, MILLISECONDS));
assertFalse(failure.get());
}
Aggregations