Search in sources :

Example 1 with DistributedProcess

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) -> {
    });
}
Also used : ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) IGNITE_INTERNAL_KEY_PREFIX(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage.IGNITE_INTERNAL_KEY_PREFIX) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) PERFORMANCE_STATISTICS_ROTATE(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.PERFORMANCE_STATISTICS_ROTATE) DistributedMetastorageLifecycleListener(org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteFeatures(org.apache.ignite.internal.IgniteFeatures) ArrayList(java.util.ArrayList) GridKernalContext(org.apache.ignite.internal.GridKernalContext) DistributedProcess(org.apache.ignite.internal.util.distributed.DistributedProcess) IgniteFuture(org.apache.ignite.lang.IgniteFuture) GridIntList(org.apache.ignite.internal.util.GridIntList) A(org.apache.ignite.internal.util.typedef.internal.A) IgniteFeatures.allNodesSupports(org.apache.ignite.internal.IgniteFeatures.allNodesSupports) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) UUID(java.util.UUID) Serializable(java.io.Serializable) Consumer(java.util.function.Consumer) EventListener(java.util.EventListener) Nullable(org.jetbrains.annotations.Nullable) GridCacheQueryType(org.apache.ignite.internal.processors.cache.query.GridCacheQueryType) ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) GridProcessorAdapter(org.apache.ignite.internal.processors.GridProcessorAdapter) IgniteUuid(org.apache.ignite.lang.IgniteUuid) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) ReadableDistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) DistributedMetastorageLifecycleListener(org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener)

Example 2 with DistributedProcess

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());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) G(org.apache.ignite.internal.util.typedef.G) DistributedProcess(org.apache.ignite.internal.util.distributed.DistributedProcess) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) TEST_PROCESS(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.TEST_PROCESS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) FailureHandler(org.apache.ignite.failure.FailureHandler) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) FailureContext(org.apache.ignite.failure.FailureContext) Collections(java.util.Collections) DistributedProcess(org.apache.ignite.internal.util.distributed.DistributedProcess) HashMap(java.util.HashMap) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

UUID (java.util.UUID)2 DistributedProcess (org.apache.ignite.internal.util.distributed.DistributedProcess)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 EventListener (java.util.EventListener)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 EVT_NODE_FAILED (org.apache.ignite.events.EventType.EVT_NODE_FAILED)1 EVT_NODE_LEFT (org.apache.ignite.events.EventType.EVT_NODE_LEFT)1 FailureContext (org.apache.ignite.failure.FailureContext)1 FailureHandler (org.apache.ignite.failure.FailureHandler)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1