Search in sources :

Example 1 with VisorValidateIndexesTaskResult

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

the class GridCommandHandlerIndexingCheckSizeTest method validateCheckSizes.

/**
 * Checking whether cache and index size check is correct.
 *
 * @param node Node.
 * @param cacheName Cache name.
 * @param rmvByTbl Number of deleted items per table.
 * @param cacheSizeExp Function for getting expected cache size.
 * @param idxSizeExp Function for getting expected index size.
 */
private void validateCheckSizes(IgniteEx node, String cacheName, Map<String, AtomicInteger> rmvByTbl, Function<AtomicInteger, Integer> cacheSizeExp, Function<AtomicInteger, Integer> idxSizeExp) {
    requireNonNull(node);
    requireNonNull(cacheName);
    requireNonNull(rmvByTbl);
    requireNonNull(cacheSizeExp);
    requireNonNull(idxSizeExp);
    injectTestSystemOut();
    assertEquals(EXIT_CODE_OK, execute(CACHE.text(), VALIDATE_INDEXES.text(), cacheName, CHECK_SIZES.argName()));
    String out = testOut.toString();
    assertContains(log, out, "issues found (listed above)");
    assertContains(log, out, "Size check");
    Map<String, ValidateIndexesCheckSizeResult> valIdxCheckSizeResults = ((VisorValidateIndexesTaskResult) lastOperationResult).results().get(node.localNode().id()).checkSizeResult();
    assertEquals(rmvByTbl.size(), valIdxCheckSizeResults.size());
    for (Map.Entry<String, AtomicInteger> rmvByTblEntry : rmvByTbl.entrySet()) {
        ValidateIndexesCheckSizeResult checkSizeRes = valIdxCheckSizeResults.entrySet().stream().filter(e -> e.getKey().contains(rmvByTblEntry.getKey())).map(Map.Entry::getValue).findAny().orElse(null);
        assertNotNull(checkSizeRes);
        assertEquals((int) cacheSizeExp.apply(rmvByTblEntry.getValue()), checkSizeRes.cacheSize());
        Collection<ValidateIndexesCheckSizeIssue> issues = checkSizeRes.issues();
        assertFalse(issues.isEmpty());
        issues.forEach(issue -> {
            assertEquals((int) idxSizeExp.apply(rmvByTblEntry.getValue()), issue.indexSize());
            Throwable err = issue.error();
            assertNotNull(err);
            assertEquals("Cache and index size not same.", err.getMessage());
        });
    }
}
Also used : Person(org.apache.ignite.util.GridCommandHandlerIndexingUtils.Person) CHECK_SIZES(org.apache.ignite.internal.commandline.cache.argument.ValidateIndexesCommandArg.CHECK_SIZES) GridCommandHandlerIndexingUtils.organizationEntity(org.apache.ignite.util.GridCommandHandlerIndexingUtils.organizationEntity) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) HashMap(java.util.HashMap) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) GridCommandHandlerIndexingUtils.createAndFillCache(org.apache.ignite.util.GridCommandHandlerIndexingUtils.createAndFillCache) Function(java.util.function.Function) EXIT_CODE_OK(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK) ArrayList(java.util.ArrayList) CACHE_NAME(org.apache.ignite.util.GridCommandHandlerIndexingUtils.CACHE_NAME) GridCommandHandlerIndexingUtils.personEntity(org.apache.ignite.util.GridCommandHandlerIndexingUtils.personEntity) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Objects.requireNonNull(java.util.Objects.requireNonNull) Cache(javax.cache.Cache) GridCommandHandlerIndexingUtils.breakCacheDataTree(org.apache.ignite.util.GridCommandHandlerIndexingUtils.breakCacheDataTree) QueryEntity(org.apache.ignite.cache.QueryEntity) ValidateIndexesCommandArg(org.apache.ignite.internal.commandline.cache.argument.ValidateIndexesCommandArg) ValidateIndexesCheckSizeIssue(org.apache.ignite.internal.visor.verify.ValidateIndexesCheckSizeIssue) GridTestUtils.assertNotContains(org.apache.ignite.testframework.GridTestUtils.assertNotContains) VisorValidateIndexesTaskResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult) Collections.emptyMap(java.util.Collections.emptyMap) VALIDATE_INDEXES(org.apache.ignite.internal.commandline.cache.CacheSubcommands.VALIDATE_INDEXES) GridCommandHandlerIndexingUtils.breakSqlIndex(org.apache.ignite.util.GridCommandHandlerIndexingUtils.breakSqlIndex) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Test(org.junit.Test) CacheSubcommands(org.apache.ignite.internal.commandline.cache.CacheSubcommands) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils.assertContains(org.apache.ignite.testframework.GridTestUtils.assertContains) CACHE(org.apache.ignite.internal.commandline.CommandList.CACHE) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) String.valueOf(java.lang.String.valueOf) Organization(org.apache.ignite.util.GridCommandHandlerIndexingUtils.Organization) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) GROUP_NAME(org.apache.ignite.util.GridCommandHandlerIndexingUtils.GROUP_NAME) ValidateIndexesCheckSizeResult(org.apache.ignite.internal.visor.verify.ValidateIndexesCheckSizeResult) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ValidateIndexesCheckSizeIssue(org.apache.ignite.internal.visor.verify.ValidateIndexesCheckSizeIssue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VisorValidateIndexesTaskResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult) ValidateIndexesCheckSizeResult(org.apache.ignite.internal.visor.verify.ValidateIndexesCheckSizeResult) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 2 with VisorValidateIndexesTaskResult

use of org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult 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 3 with VisorValidateIndexesTaskResult

use of org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult 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 4 with VisorValidateIndexesTaskResult

use of org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult 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)

Example 5 with VisorValidateIndexesTaskResult

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

the class CacheValidateIndexes method execute.

/**
 * {@inheritDoc}
 */
@Override
public Object execute(GridClientConfiguration clientCfg, Logger logger) throws Exception {
    VisorValidateIndexesTaskArg taskArg = new VisorValidateIndexesTaskArg(args.caches(), args.nodeId() != null ? Collections.singleton(args.nodeId()) : null, args.checkFirst(), args.checkThrough(), args.checkCrc(), args.checkSizes());
    try (GridClient client = Command.startClient(clientCfg)) {
        VisorValidateIndexesTaskResult taskRes = executeTaskByNameOnNode(client, "org.apache.ignite.internal.visor.verify.VisorValidateIndexesTask", taskArg, null, clientCfg);
        boolean errors = CommandLogger.printErrors(taskRes.exceptions(), "Index validation failed on nodes:", logger);
        for (Entry<UUID, VisorValidateIndexesJobResult> nodeEntry : taskRes.results().entrySet()) {
            VisorValidateIndexesJobResult jobRes = nodeEntry.getValue();
            if (!jobRes.hasIssues())
                continue;
            errors = true;
            logger.info("Index issues found on node " + nodeEntry.getKey() + ":");
            for (IndexIntegrityCheckIssue is : jobRes.integrityCheckFailures()) logger.info(INDENT + is);
            for (Entry<PartitionKey, ValidateIndexesPartitionResult> e : jobRes.partitionResult().entrySet()) {
                ValidateIndexesPartitionResult res = e.getValue();
                if (!res.issues().isEmpty()) {
                    logger.info(INDENT + join(" ", e.getKey(), e.getValue()));
                    for (IndexValidationIssue is : res.issues()) logger.info(DOUBLE_INDENT + is);
                }
            }
            for (Entry<String, ValidateIndexesPartitionResult> e : jobRes.indexResult().entrySet()) {
                ValidateIndexesPartitionResult res = e.getValue();
                if (!res.issues().isEmpty()) {
                    logger.info(INDENT + join(" ", "SQL Index", e.getKey(), e.getValue()));
                    for (IndexValidationIssue is : res.issues()) logger.info(DOUBLE_INDENT + is);
                }
            }
            for (Entry<String, ValidateIndexesCheckSizeResult> e : jobRes.checkSizeResult().entrySet()) {
                ValidateIndexesCheckSizeResult res = e.getValue();
                Collection<ValidateIndexesCheckSizeIssue> issues = res.issues();
                if (issues.isEmpty())
                    continue;
                logger.info(INDENT + join(" ", "Size check", e.getKey(), res));
                for (ValidateIndexesCheckSizeIssue issue : issues) logger.info(DOUBLE_INDENT + issue);
            }
        }
        if (!errors)
            logger.info("no issues found.");
        else
            logger.severe("issues found (listed above).");
        logger.info("");
        return taskRes;
    }
}
Also used : IndexValidationIssue(org.apache.ignite.internal.visor.verify.IndexValidationIssue) GridClient(org.apache.ignite.internal.client.GridClient) ValidateIndexesCheckSizeIssue(org.apache.ignite.internal.visor.verify.ValidateIndexesCheckSizeIssue) VisorValidateIndexesJobResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult) IndexIntegrityCheckIssue(org.apache.ignite.internal.visor.verify.IndexIntegrityCheckIssue) PartitionKey(org.apache.ignite.internal.processors.cache.verify.PartitionKey) VisorValidateIndexesTaskResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult) UUID(java.util.UUID) VisorValidateIndexesTaskArg(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskArg) ValidateIndexesCheckSizeResult(org.apache.ignite.internal.visor.verify.ValidateIndexesCheckSizeResult) ValidateIndexesPartitionResult(org.apache.ignite.internal.visor.verify.ValidateIndexesPartitionResult)

Aggregations

VisorValidateIndexesTaskResult (org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult)5 UUID (java.util.UUID)4 VisorValidateIndexesJobResult (org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult)4 VisorValidateIndexesTaskArg (org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskArg)4 IgniteDataStreamer (org.apache.ignite.IgniteDataStreamer)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 VisorValidateIndexesTask (org.apache.ignite.internal.visor.verify.VisorValidateIndexesTask)3 Test (org.junit.Test)3 Map (java.util.Map)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)2 VisorTaskArgument (org.apache.ignite.internal.visor.VisorTaskArgument)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 File (java.io.File)1 String.valueOf (java.lang.String.valueOf)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.emptyMap (java.util.Collections.emptyMap)1