Search in sources :

Example 31 with SchemaOperationException

use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.

the class DynamicEnableIndexingConcurrentSelfTest method testConcurrentEnableIndexing.

/**
 * Test concurrent enabling indexing. Only one attempt should succeed.
 */
@Test
public void testConcurrentEnableIndexing() throws Exception {
    // Start several nodes.
    IgniteEx srv1 = ignitionStart(serverConfiguration(1));
    ignitionStart(serverConfiguration(2));
    ignitionStart(clientConfiguration(3));
    ignitionStart(clientConfiguration(4));
    srv1.cluster().state(ClusterState.ACTIVE);
    createCache(srv1);
    loadData(srv1, 0, LARGE_NUM_ENTRIES);
    // Start enable indexing from several threads.
    final AtomicBoolean stopped = new AtomicBoolean();
    final AtomicInteger success = new AtomicInteger();
    final CountDownLatch iterations = new CountDownLatch(1000);
    IgniteInternalFuture<?> task = multithreadedAsync(() -> {
        while (!stopped.get()) {
            IgniteEx node = grid(ThreadLocalRandom.current().nextInt(1, 4));
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                break;
            }
            enableIndexing(node).chain((fut) -> {
                try {
                    fut.get();
                    success.incrementAndGet();
                } catch (IgniteCheckedException e) {
                    assertTrue(e.hasCause(SchemaOperationException.class));
                    SchemaOperationException opEx = e.getCause(SchemaOperationException.class);
                    assertEquals(SchemaOperationException.CODE_CACHE_ALREADY_INDEXED, opEx.code());
                    assertEquals("Cache is already indexed: " + POI_CACHE_NAME, opEx.getMessage());
                }
                return null;
            });
            iterations.countDown();
        }
        return null;
    }, 4);
    // Do attempts.
    iterations.await(2, TimeUnit.SECONDS);
    // Start more server nodes..
    ignitionStart(serverConfiguration(5));
    ignitionStart(serverConfiguration(6));
    // Stop task.
    stopped.set(true);
    task.get();
    // Check that only one successful attempt.
    assertEquals(1, success.get());
    awaitPartitionMapExchange();
    for (Ignite g : G.allGrids()) {
        assertEquals(LARGE_NUM_ENTRIES, query(g, SELECT_ALL_QUERY).size());
        performQueryingIntegrityCheck(g);
        checkQueryParallelism((IgniteEx) g, cacheMode);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteClientReconnectAbstractTest(org.apache.ignite.internal.IgniteClientReconnectAbstractTest) Test(org.junit.Test)

Example 32 with SchemaOperationException

use of org.apache.ignite.internal.processors.query.schema.SchemaOperationException in project ignite by apache.

the class DynamicIndexAbstractBasicSelfTest method checkCreateNotCache.

/**
 * Check create when cache doesn't exist.
 *
 * @param mode Mode.
 * @param atomicityMode Atomicity mode.
 * @param near Near flag.
 * @throws Exception If failed.
 */
private void checkCreateNotCache(CacheMode mode, CacheAtomicityMode atomicityMode, boolean near) throws Exception {
    initialize(mode, atomicityMode, near);
    final QueryIndex idx = index(IDX_NAME_1, field(FIELD_NAME_1_ESCAPED));
    try {
        String cacheName = randomString();
        queryProcessor(node()).dynamicIndexCreate(cacheName, cacheName, TBL_NAME, idx, false, 0).get();
    } catch (SchemaOperationException e) {
        assertEquals(SchemaOperationException.CODE_CACHE_NOT_FOUND, e.code());
        assertNoIndex(CACHE_NAME, TBL_NAME, IDX_NAME_1);
        return;
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
    fail(SchemaOperationException.class.getSimpleName() + " is not thrown.");
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) QueryIndex(org.apache.ignite.cache.QueryIndex) CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException)

Aggregations

SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)32 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 QueryIndex (org.apache.ignite.cache.QueryIndex)16 IgniteException (org.apache.ignite.IgniteException)12 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 LinkedHashMap (java.util.LinkedHashMap)8 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)8 Test (org.junit.Test)8 CacheException (javax.cache.CacheException)7 Ignite (org.apache.ignite.Ignite)7 IgniteClientReconnectAbstractTest (org.apache.ignite.internal.IgniteClientReconnectAbstractTest)7 Map (java.util.Map)6 QueryEntity (org.apache.ignite.cache.QueryEntity)6 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)6 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)6 HashMap (java.util.HashMap)5 List (java.util.List)5 GridQueryProperty (org.apache.ignite.internal.processors.query.GridQueryProperty)5 GridQueryTypeDescriptor (org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)5