Search in sources :

Example 1 with JOBS_VIEW

use of org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW in project ignite by apache.

the class KillCommandsCommandShTest method testCancelConsistencyTask.

/**
 */
@Test
public void testCancelConsistencyTask() throws InterruptedException {
    String consistencyCacheName = "consistencyCache";
    CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>();
    cfg.setName(consistencyCacheName);
    cfg.setBackups(SERVER_NODE_CNT - 1);
    cfg.setAffinity(new RendezvousAffinityFunction().setPartitions(1));
    IgniteCache<Integer, Integer> cache = client.getOrCreateCache(cfg);
    int entries = 10_000;
    for (int i = 0; i < entries; i++) cache.put(i, i);
    AtomicInteger getCnt = new AtomicInteger();
    CountDownLatch thLatch = new CountDownLatch(1);
    Thread th = new Thread(() -> {
        IgnitePredicate<ComputeJobView> repairJobFilter = job -> job.taskClassName().equals(VisorConsistencyRepairTask.class.getName());
        for (IgniteEx node : srvs) {
            SystemView<ComputeJobView> jobs = node.context().systemView().view(JOBS_VIEW);
            // Found.
            assertTrue(F.iterator0(jobs, true, repairJobFilter).hasNext());
        }
        int res = execute("--consistency", "status");
        assertEquals(EXIT_CODE_OK, res);
        assertContains(log, testOut.toString(), "Status: 1024/" + entries);
        assertNotContains(log, testOut.toString(), VisorConsistencyStatusTask.NOTHING_FOUND);
        testOut.reset();
        res = execute("--kill", "consistency");
        assertEquals(EXIT_CODE_OK, res);
        try {
            assertTrue(GridTestUtils.waitForCondition(() -> {
                for (IgniteEx node : srvs) {
                    SystemView<ComputeJobView> jobs = node.context().systemView().view(JOBS_VIEW);
                    if (// Found.
                    F.iterator0(jobs, true, repairJobFilter).hasNext())
                        return false;
                }
                return true;
            }, // Missed.
            5000L));
        } catch (IgniteInterruptedCheckedException e) {
            fail();
        }
        thLatch.countDown();
    });
    // GridNearGetRequest messages count required to pefrom getAll() with readRepair from all nodes twice.
    // First will be finished (which generates status), second will be frozen.
    int twiceGetMsgCnt = SERVER_NODE_CNT * (SERVER_NODE_CNT - 1) * 2;
    for (IgniteEx server : srvs) {
        TestRecordingCommunicationSpi spi = ((TestRecordingCommunicationSpi) server.configuration().getCommunicationSpi());
        AtomicInteger locLimit = new AtomicInteger(SERVER_NODE_CNT - 1);
        spi.blockMessages((node, message) -> {
            if (message instanceof GridNearGetRequest) {
                // Each node should perform get twice.
                if (getCnt.incrementAndGet() == twiceGetMsgCnt)
                    th.start();
                // Cancellation should stop the process.
                assertTrue(getCnt.get() <= twiceGetMsgCnt);
                // Blocking to freeze '--consistency repair' operation (except first get).
                return locLimit.decrementAndGet() < 0;
            }
            return false;
        });
    }
    injectTestSystemOut();
    assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--consistency", "repair", ConsistencyCommand.STRATEGY, ReadRepairStrategy.LWW.toString(), ConsistencyCommand.PARTITION, "0", ConsistencyCommand.CACHE, consistencyCacheName));
    assertContains(log, testOut.toString(), "Operation execution cancelled.");
    assertContains(log, testOut.toString(), VisorConsistencyRepairTask.NOTHING_FOUND);
    assertNotContains(log, testOut.toString(), VisorConsistencyRepairTask.CONSISTENCY_VIOLATIONS_FOUND);
    thLatch.await();
    for (IgniteEx server : srvs) {
        // Restoring messaging for other tests.
        TestRecordingCommunicationSpi spi = ((TestRecordingCommunicationSpi) server.configuration().getCommunicationSpi());
        spi.stopBlock();
    }
    testOut.reset();
    int res = execute("--consistency", "status");
    assertEquals(EXIT_CODE_OK, res);
    assertContains(log, testOut.toString(), VisorConsistencyStatusTask.NOTHING_FOUND);
    assertNotContains(log, testOut.toString(), "Status");
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) KillCommandsTests.doTestScanQueryCancel(org.apache.ignite.util.KillCommandsTests.doTestScanQueryCancel) KillCommandsTests.doTestCancelService(org.apache.ignite.util.KillCommandsTests.doTestCancelService) IgniteEx(org.apache.ignite.internal.IgniteEx) EXIT_CODE_OK(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ArrayList(java.util.ArrayList) KillCommandsTests.doTestCancelSQLQuery(org.apache.ignite.util.KillCommandsTests.doTestCancelSQLQuery) KillCommandsTests.doTestCancelTx(org.apache.ignite.util.KillCommandsTests.doTestCancelTx) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) VisorConsistencyStatusTask(org.apache.ignite.internal.visor.consistency.VisorConsistencyStatusTask) GridTestUtils.assertNotContains(org.apache.ignite.testframework.GridTestUtils.assertNotContains) GridNearGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest) F(org.apache.ignite.internal.util.typedef.F) KillCommandsTests.doTestCancelComputeTask(org.apache.ignite.util.KillCommandsTests.doTestCancelComputeTask) SystemView(org.apache.ignite.spi.systemview.view.SystemView) JOBS_VIEW(org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW) ReadRepairStrategy(org.apache.ignite.cache.ReadRepairStrategy) Test(org.junit.Test) UUID(java.util.UUID) IgniteCache(org.apache.ignite.IgniteCache) ConsistencyCommand(org.apache.ignite.internal.commandline.consistency.ConsistencyCommand) EXIT_CODE_UNEXPECTED_ERROR(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) GridTestUtils.assertContains(org.apache.ignite.testframework.GridTestUtils.assertContains) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PAGES_CNT(org.apache.ignite.util.KillCommandsTests.PAGES_CNT) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest) VisorConsistencyRepairTask(org.apache.ignite.internal.visor.consistency.VisorConsistencyRepairTask) ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) KillCommandsTests.doTestCancelContinuousQuery(org.apache.ignite.util.KillCommandsTests.doTestCancelContinuousQuery) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) PAGE_SZ(org.apache.ignite.util.KillCommandsTests.PAGE_SZ) IgniteUuid(org.apache.ignite.lang.IgniteUuid) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeJobView(org.apache.ignite.spi.systemview.view.ComputeJobView) SystemView(org.apache.ignite.spi.systemview.view.SystemView) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorConsistencyRepairTask(org.apache.ignite.internal.visor.consistency.VisorConsistencyRepairTask) GridNearGetRequest(org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteCache (org.apache.ignite.IgniteCache)1 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)1 ReadRepairStrategy (org.apache.ignite.cache.ReadRepairStrategy)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)1 EXIT_CODE_OK (org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK)1 EXIT_CODE_UNEXPECTED_ERROR (org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR)1 ConsistencyCommand (org.apache.ignite.internal.commandline.consistency.ConsistencyCommand)1 GridNearGetRequest (org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest)1 AbstractSnapshotSelfTest.doSnapshotCancellationTest (org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest)1 JOBS_VIEW (org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW)1 F (org.apache.ignite.internal.util.typedef.F)1