Search in sources :

Example 1 with VisorValidateIndexesJobResult

use of org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult in project ignite by apache.

the class LongDestroyDurableBackgroundTaskTest method validateIndexes.

/**
 * Validates indexes on {@link #RESTARTED_NODE_NUM} and {@link #ALWAYS_ALIVE_NODE_NUM}.
 *
 * @param ignite Ignite instance.
 */
private void validateIndexes(Ignite ignite) {
    Set<UUID> nodeIds = new HashSet<UUID>() {

        {
            add(grid(RESTARTED_NODE_NUM).cluster().localNode().id());
            add(grid(ALWAYS_ALIVE_NODE_NUM).cluster().localNode().id());
        }
    };
    log.info("Doing indexes validation.");
    VisorValidateIndexesTaskArg taskArg = new VisorValidateIndexesTaskArg(Collections.singleton("SQL_PUBLIC_T"), nodeIds, 0, 1, true, true);
    VisorValidateIndexesTaskResult taskRes = ignite.compute().execute(VisorValidateIndexesTask.class.getName(), new VisorTaskArgument<>(nodeIds, taskArg, false));
    if (!taskRes.exceptions().isEmpty()) {
        for (Map.Entry<UUID, Exception> e : taskRes.exceptions().entrySet()) log.error("Exception while validation indexes on node id=" + e.getKey().toString(), e.getValue());
    }
    for (Map.Entry<UUID, VisorValidateIndexesJobResult> nodeEntry : taskRes.results().entrySet()) {
        if (nodeEntry.getValue().hasIssues()) {
            log.error("Validate indexes issues had been found on node id=" + nodeEntry.getKey().toString());
            log.error("Integrity check failures: " + nodeEntry.getValue().integrityCheckFailures().size());
            nodeEntry.getValue().integrityCheckFailures().forEach(f -> log.error(f.toString()));
            logIssuesFromMap("Partition results", nodeEntry.getValue().partitionResult());
            logIssuesFromMap("Index validation issues", nodeEntry.getValue().indexResult());
        }
    }
    assertTrue(taskRes.exceptions().isEmpty());
    for (VisorValidateIndexesJobResult res : taskRes.results().values()) assertFalse(res.hasIssues());
}
Also used : VisorValidateIndexesJobResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult) VisorValidateIndexesTaskResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult) UUID(java.util.UUID) VisorValidateIndexesTaskArg(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskArg) Map(java.util.Map) VisorValidateIndexesTask(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTask) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HashSet(java.util.HashSet)

Example 2 with VisorValidateIndexesJobResult

use of org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult in project ignite by apache.

the class IgnitePdsIndexingDefragmentationTest method validateIndexes.

/**
 * Test that indexes are correct.
 *
 * @param node Node.
 * @throws Exception If failed.
 */
private static void validateIndexes(IgniteEx node) throws Exception {
    ValidateIndexesClosure clo = new ValidateIndexesClosure(() -> false, Collections.singleton(DEFAULT_CACHE_NAME), 0, 0, false, true);
    node.context().resource().injectGeneric(clo);
    VisorValidateIndexesJobResult call = clo.call();
    assertFalse(call.hasIssues());
}
Also used : VisorValidateIndexesJobResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult) ValidateIndexesClosure(org.apache.ignite.internal.visor.verify.ValidateIndexesClosure)

Example 3 with VisorValidateIndexesJobResult

use of org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult in project ignite by apache.

the class IndexingMultithreadedLoadContinuousRestartTest method test.

/**
 * Tests that continuous non-graceful node stop under load doesn't break SQL indexes.
 *
 * @throws Exception If failed.
 */
@Test
public void test() throws Exception {
    for (int i = 0; i < RESTARTS; i++) {
        IgniteEx ignite = startGrid(0);
        ignite.cluster().active(true);
        // Ensure that checkpoint isn't running - otherwise validate indexes task may fail.
        forceCheckpoint();
        // Validate indexes on start.
        ValidateIndexesClosure clo = new ValidateIndexesClosure(() -> false, Collections.singleton(CACHE_NAME), 0, 0, false, true);
        ignite.context().resource().injectGeneric(clo);
        VisorValidateIndexesJobResult res = clo.call();
        assertFalse(res.hasIssues());
        IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {

            @Override
            public void run() {
                IgniteCache<UserKey, UserValue> cache = ignite.cache(CACHE_NAME);
                int i = 0;
                try {
                    for (; i < LOAD_LOOP; i++) {
                        ThreadLocalRandom r = ThreadLocalRandom.current();
                        Integer keySeed = r.nextInt(KEY_BOUND);
                        UserKey key = new UserKey(keySeed);
                        if (r.nextBoolean())
                            cache.put(key, new UserValue(r.nextLong()));
                        else
                            cache.remove(key);
                    }
                    // Intentionally stop grid while another loaders are still in progress.
                    ignite.close();
                } catch (Exception e) {
                    log.warning("Failed to update cache after " + i + " loop cycles", e);
                }
            }
        }, THREADS, "loader");
        fut.get();
        ignite.close();
    }
}
Also used : IgniteCache(org.apache.ignite.IgniteCache) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorValidateIndexesJobResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ValidateIndexesClosure(org.apache.ignite.internal.visor.verify.ValidateIndexesClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with VisorValidateIndexesJobResult

use of org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult in project ignite by apache.

the class GridIndexRebuildTest method testFullIndexRebuild.

/**
 * We start several nodes, populate caches, then start replacing values. After that one node is killed, their
 * index.bin files would be removed. Finally, we restart the node, index rebuild starting after recovery. And we
 * checke indexes by "validate indexes" task.
 */
@Test
public void testFullIndexRebuild() throws Exception {
    long start = System.currentTimeMillis();
    IgniteEx grid1 = startGrids(4);
    grid1.cluster().active(true);
    final int accountCnt = 2048;
    try (IgniteDataStreamer streamer = grid1.dataStreamer(FIRST_CACHE)) {
        for (long i = 0; i < accountCnt; i++) {
            streamer.addData(i, new Account(i));
        }
        streamer.flush();
    }
    try (IgniteDataStreamer streamer = grid1.dataStreamer(SECOND_CACHE)) {
        for (long i = 0; i < accountCnt; i++) {
            streamer.addData(i, new Account(i));
        }
        streamer.flush();
    }
    AtomicBoolean stop = new AtomicBoolean();
    IgniteCache<Object, Object> cache1 = grid1.cache(FIRST_CACHE);
    IgniteCache<Object, Object> cache2 = grid1.cache(SECOND_CACHE);
    new Thread(new Runnable() {

        @Override
        public void run() {
            long i = 0;
            while (!stop.get()) {
                try {
                    cache1.put(i, new Account(i));
                    if (i % 13 == 7)
                        cache2.put(i, new Account2(i));
                    else
                        cache2.put(i, new Account(i));
                    i++;
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();
    File workDir = U.resolveWorkDirectory(U.defaultWorkDirectory(), DFLT_STORE_DIR, false);
    long diff = System.currentTimeMillis() - start;
    U.sleep(7500 - (diff % 5000));
    stopGrid(3);
    stop.set(true);
    for (File grp : new File(workDir, U.maskForFileName(getTestIgniteInstanceName(3))).listFiles()) {
        new File(grp, "index.bin").delete();
    }
    startGrid(3);
    awaitPartitionMapExchange();
    U.sleep(3_000);
    ImmutableSet<UUID> nodes = ImmutableSet.of(grid(2).localNode().id(), grid(3).localNode().id());
    VisorValidateIndexesTaskArg arg = new VisorValidateIndexesTaskArg(null, null, 10000, 1, true, true);
    VisorTaskArgument<VisorValidateIndexesTaskArg> visorTaskArg = new VisorTaskArgument<>(nodes, arg, true);
    ComputeTaskInternalFuture<VisorValidateIndexesTaskResult> exec = grid1.context().task().execute(new VisorValidateIndexesTask(), visorTaskArg);
    VisorValidateIndexesTaskResult res = exec.get();
    Map<UUID, VisorValidateIndexesJobResult> results = res.results();
    boolean hasIssue = false;
    for (VisorValidateIndexesJobResult jobResult : results.values()) {
        System.err.println(jobResult);
        hasIssue |= jobResult.hasIssues();
    }
    assertFalse(hasIssue);
}
Also used : VisorValidateIndexesTask(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTask) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) VisorValidateIndexesJobResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult) VisorValidateIndexesTaskResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult) UUID(java.util.UUID) File(java.io.File) VisorValidateIndexesTaskArg(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskArg) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with VisorValidateIndexesJobResult

use of org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult in project ignite by apache.

the class GridIndexRebuildTest method testPartialIndexRebuild.

/**
 * We start several nodes, populate caches, then start replacing values. After that one node is killed, new index
 * created. Finally, we restart the node, index rebuild starting after recovery. And we checke indexes by "validate
 * indexes" task.
 */
@SuppressWarnings("unchecked")
@Test
public void testPartialIndexRebuild() throws Exception {
    LogListener lsnr = LogListener.matches("B+Tree is corrupted").build();
    listeningLog.registerListener(lsnr);
    long start = System.currentTimeMillis();
    IgniteEx grid1 = startGrids(4);
    grid1.cluster().active(true);
    final int accountCnt = 2048;
    try (IgniteDataStreamer streamer = grid1.dataStreamer(SECOND_CACHE)) {
        for (long i = 0; i < accountCnt; i++) streamer.addData(i, new Account(i));
        streamer.flush();
    }
    AtomicBoolean stop = new AtomicBoolean();
    IgniteCache<Object, Object> cache2 = grid1.cache(SECOND_CACHE);
    new Thread(new Runnable() {

        @Override
        public void run() {
            long i = 0;
            while (!stop.get()) {
                try {
                    if (i % 13 == 7)
                        cache2.put(i, new Account2(i));
                    else
                        cache2.put(i, new Account(i));
                    i++;
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();
    long diff = System.currentTimeMillis() - start;
    U.sleep(7500 - (diff % 5000));
    stopGrid(3);
    stop.set(true);
    cache2.query(new SqlFieldsQuery("CREATE INDEX idx" + UUID.randomUUID().toString().replaceAll("-", "_") + " on Account (amount)")).getAll();
    startGrid(3);
    awaitPartitionMapExchange();
    U.sleep(3_000);
    ImmutableSet<UUID> nodes = ImmutableSet.of(grid(2).localNode().id(), grid(3).localNode().id());
    VisorValidateIndexesTaskArg arg = new VisorValidateIndexesTaskArg(null, null, 10000, 1, true, true);
    VisorTaskArgument<VisorValidateIndexesTaskArg> visorTaskArg = new VisorTaskArgument<>(nodes, arg, true);
    ComputeTaskInternalFuture<VisorValidateIndexesTaskResult> execute = grid1.context().task().execute(new VisorValidateIndexesTask(), visorTaskArg);
    VisorValidateIndexesTaskResult res = execute.get();
    Map<UUID, VisorValidateIndexesJobResult> results = res.results();
    boolean hasIssue = false;
    for (VisorValidateIndexesJobResult jobResult : results.values()) {
        System.err.println(jobResult);
        hasIssue |= jobResult.hasIssues();
    }
    assertFalse(hasIssue);
    assertFalse("B+Tree is corrupted.", lsnr.check());
}
Also used : VisorValidateIndexesJobResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult) UUID(java.util.UUID) VisorValidateIndexesTaskArg(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskArg) LogListener(org.apache.ignite.testframework.LogListener) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) VisorValidateIndexesTask(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTask) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) VisorValidateIndexesTaskResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

VisorValidateIndexesJobResult (org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult)7 UUID (java.util.UUID)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 VisorValidateIndexesTaskArg (org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskArg)4 VisorValidateIndexesTaskResult (org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult)4 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)4 Test (org.junit.Test)4 ValidateIndexesClosure (org.apache.ignite.internal.visor.verify.ValidateIndexesClosure)3 VisorValidateIndexesTask (org.apache.ignite.internal.visor.verify.VisorValidateIndexesTask)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IgniteDataStreamer (org.apache.ignite.IgniteDataStreamer)2 VisorTaskArgument (org.apache.ignite.internal.visor.VisorTaskArgument)2 LogListener (org.apache.ignite.testframework.LogListener)2 File (java.io.File)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1