Search in sources :

Example 1 with ValidateIndexesClosure

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

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

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

the class IgniteClusterSnapshotWithIndexesTest method testClusterSnapshotWithIndexes.

/**
 * @throws Exception If fails.
 */
@Test
public void testClusterSnapshotWithIndexes() throws Exception {
    String tblName = "Person";
    IgniteEx ignite = startGridsWithCache(3, CACHE_KEYS_RANGE, key -> new Account(key, key), indexedCcfg);
    executeSql(ignite, "CREATE TABLE " + tblName + " (id int, name varchar, age int, city varchar, " + "primary key (id, name)) WITH \"cache_name=" + tblName + "\"");
    executeSql(ignite, "CREATE INDEX ON " + tblName + "(city, age)");
    forceCheckpoint();
    for (int i = 0; i < CACHE_KEYS_RANGE; i++) executeSql(ignite, "INSERT INTO " + tblName + " (id, name, age, city) VALUES(?, 'name', 3, 'city')", i);
    assertEquals(CACHE_KEYS_RANGE, rowsCount(executeSql(ignite, selectStartSQLStatement(tblName))));
    assertEquals(CACHE_KEYS_RANGE, rowsCount(executeSql(ignite.context().cache().jcache(indexedCcfg.getName()), selectStartSQLStatement(Account.class.getSimpleName()))));
    ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
    stopAllGrids();
    IgniteEx snp = startGridsFromSnapshot(3, SNAPSHOT_NAME);
    assertTrue(snp.cache(indexedCcfg.getName()).indexReadyFuture().isDone());
    assertTrue(snp.cache(tblName).indexReadyFuture().isDone());
    List<List<?>> results = executeSql(snp, explainSQLStatement(tblName) + "id > 10");
    // Primary key exists.
    String explainPlan = (String) results.get(0).get(0);
    assertTrue(explainPlan.toUpperCase().contains("\"_KEY_PK"));
    assertFalse(explainPlan.toUpperCase().contains("_SCAN_"));
    results = executeSql(snp, explainSQLStatement(tblName) + "city='city' and age=2");
    assertUsingSecondaryIndex(results);
    results = executeSql(snp.context().cache().jcache(indexedCcfg.getName()), explainSQLStatement(Account.class.getSimpleName()) + "id=0");
    assertUsingSecondaryIndex(results);
    assertEquals(CACHE_KEYS_RANGE, rowsCount(executeSql(snp, selectStartSQLStatement(tblName))));
    assertEquals(CACHE_KEYS_RANGE, rowsCount(executeSql(snp.context().cache().jcache(indexedCcfg.getName()), selectStartSQLStatement(Account.class.getSimpleName()))));
    forceCheckpoint();
    // Validate indexes on start.
    ValidateIndexesClosure clo = new ValidateIndexesClosure(() -> false, new HashSet<>(Arrays.asList(indexedCcfg.getName(), tblName)), 0, 0, false, true);
    for (Ignite node : G.allGrids()) {
        ((IgniteEx) node).context().resource().injectGeneric(clo);
        assertFalse(clo.call().hasIssues());
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) List(java.util.List) Ignite(org.apache.ignite.Ignite) ValidateIndexesClosure(org.apache.ignite.internal.visor.verify.ValidateIndexesClosure) Test(org.junit.Test)

Example 4 with ValidateIndexesClosure

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

the class RebuildIndexTest method check.

/**
 * @throws Exception if failed.
 */
private void check(boolean msgFound) throws Exception {
    srvLog = new ListeningTestLogger(false, log);
    LogListener idxRebuildLsnr = LogListener.matches(idxRebuildPattert).build();
    srvLog.registerListener(idxRebuildLsnr);
    IgniteEx node = startGrids(2);
    node.cluster().active(true);
    IgniteCache<UserKey, UserValue> cache = node.getOrCreateCache(CACHE_NAME);
    cache.put(new UserKey(1), new UserValue(333));
    cache.put(new UserKey(2), new UserValue(555));
    stopGrid(0);
    removeIndexBin(0);
    node = startGrid(0);
    awaitPartitionMapExchange();
    forceCheckpoint();
    enableCheckpoints(G.allGrids(), false);
    // Validate indexes on start.
    ValidateIndexesClosure clo = new ValidateIndexesClosure(() -> false, Collections.singleton(CACHE_NAME), 0, 0, false, true);
    node.context().resource().injectGeneric(clo);
    assertFalse(clo.call().hasIssues());
    assertEquals(msgFound, idxRebuildLsnr.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) ValidateIndexesClosure(org.apache.ignite.internal.visor.verify.ValidateIndexesClosure)

Example 5 with ValidateIndexesClosure

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

the class GridCommandHandlerInterruptCommandTest method testCancelValidateIndexesClosure.

/**
 * Test invokes index validation closure and canceling it after started.
 *
 * @throws Exception If failed.
 */
@Test
public void testCancelValidateIndexesClosure() throws Exception {
    IgniteEx ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    preloadeData(ignite0);
    AtomicBoolean cancelled = new AtomicBoolean(false);
    ValidateIndexesClosure clo = new ValidateIndexesClosure(cancelled::get, Collections.singleton(DEFAULT_CACHE_NAME), 0, 0, false, true);
    ListeningTestLogger listeningLogger = new ListeningTestLogger(false, log);
    GridTestUtils.setFieldValue(clo, "ignite", ignite0);
    GridTestUtils.setFieldValue(clo, "log", listeningLogger);
    LogListener lnsrValidationStarted = LogListener.matches("Current progress of ValidateIndexesClosure").build();
    listeningLogger.registerListener(lnsrValidationStarted);
    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> GridTestUtils.assertThrows(log, clo::call, IgniteException.class, ValidateIndexesClosure.CANCELLED_MSG));
    assertTrue(GridTestUtils.waitForCondition(lnsrValidationStarted::check, 10_000));
    assertFalse(fut.isDone());
    cancelled.set(true);
    fut.get(10_000);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogListener(org.apache.ignite.testframework.LogListener) IgniteException(org.apache.ignite.IgniteException) IgniteEx(org.apache.ignite.internal.IgniteEx) ValidateIndexesClosure(org.apache.ignite.internal.visor.verify.ValidateIndexesClosure) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Test(org.junit.Test)

Aggregations

ValidateIndexesClosure (org.apache.ignite.internal.visor.verify.ValidateIndexesClosure)6 IgniteEx (org.apache.ignite.internal.IgniteEx)5 Test (org.junit.Test)4 VisorValidateIndexesJobResult (org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult)3 LogListener (org.apache.ignite.testframework.LogListener)3 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)1